-
Notifications
You must be signed in to change notification settings - Fork 0
/
vocabTrainer.js
70 lines (55 loc) · 1.39 KB
/
vocabTrainer.js
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
'use strict';
const vocabTrainerScript = () => {
'use strict';
console.log("=> VocabTrainer module loaded.")
const hotkeyFnsKeyUp = {
"KeyI": focusAnswerfield,
"KeyP": pronounce, // SHIFT+P reads out the answer
"KeyU": undo,
"Escape": focusPage,
"Enter": answer(true, 1),
"Backspace": answer(true, 3),
"Space": answer(true, 2)
};
const hotkeyFnsKeyDown = {
"Enter": answer(false, 1),
"Backspace": answer(false, 3),
"Space": answer(false, 2)
};
initialize(hotkeyFnsKeyUp, hotkeyFnsKeyDown);
function focusAnswerfield() {
document.getElementById("afid").focus();
}
function pronounce(evt) {
let column = vt.question_colnum;
let text = vt.current_question;
if (evt.shiftKey) {
column = vt.answer_colnum;
text = vt.current_answer;
}
fs_play_audio({
colnum: column,
text_term: text,
id: -1,
change_buttons: false
});
}
function undo() {
ft_undo_last_answer()
}
function focusPage() {
document.activeElement.blur();
}
function answer(up, buttonNmbr) {
return (evt) => {
if (up) {
ft_bb_mouseup(null, buttonNmbr);
return;
}
ft_bb_mousedown(null, buttonNmbr);
// Prevent pressing "Space" from scrolling the page and
// "Backspace" from leaving it etc.. Only necessary with keyDown
evt.preventDefault();
};
}
};