-
Notifications
You must be signed in to change notification settings - Fork 1
/
anki_front.coffee
28 lines (24 loc) · 1 KB
/
anki_front.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
shuffle = (xs) ->
for i in [(xs.length-1)...0]
j = Math.floor(Math.random() * xs.length)
[xs[i], xs[j]] = [xs[j], xs[i]]
return xs
if document.getElementById('answer') == null
candidates = window.words
type = document.getElementById('word-type')
if type != null && type.innerHTML != ''
candidates = (w for w in candidates when w.type().indexOf(type.innerHTML) == 0)
for word in shuffle(candidates)
try
for elem in document.getElementsByClassName('required-conjugation')
# Test all required conjugations - if one of them throws (e.g. because it's not supported
# by this word) we move to the next word.
word.conjugate(elem.innerHTML)
globalSet('word', word)
break
catch error
document.getElementById('error').innerHTML = error
elem = document.getElementById('replace-front')
elem.innerHTML = getByPlain(globalGet('word')).conjugate(elem.innerHTML)
# Clear previous errors, since this word worked.
document.getElementById('error').innerHTML = ''