-
Notifications
You must be signed in to change notification settings - Fork 0
/
resultList.js
executable file
·109 lines (88 loc) · 2.79 KB
/
resultList.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict';
const resultListScript = () => {
'use strict';
console.log("=> ResultList module loaded.")
// Wrap the callback triggered when vocabularies
// have successfully been added on the serverside
const add2myvocab_serverside_callback_orig = add2myvocab_serverside_callback;
add2myvocab_serverside_callback = (txt) => {
if (txt.startsWith("Err")) {
console.log(`Seems something went wrong trying to save vocabs to list '${my_vocab_lists["x" + current_trainerlist_id]}'.`);
} else {
console.log(`Successfully saved vocabs to list '${my_vocab_lists["x" + current_trainerlist_id]}'. It now contains ${txt} vocabs.`);
}
add2myvocab_serverside_callback_orig(txt);
};
let currentRowIdx = 0;
const hotkeyFnsKeyUp = {
"ArrowUp": moveUp,
"ArrowDown": moveDown,
"KeyS": selectVocab,
"KeyA": addVocab,
"KeyI": focusSearchBox,
"KeyP": pronounce,
"Escape": focusPage
};
initialize(hotkeyFnsKeyUp, []);
function focusSearchBox() {
focus_searchbox();
}
function pronounce() {
const term_lang=lpp2_lc;
const id = idArr[currentRowIdx];
speak_nopop(id, term_lang+"_rec_ip");
}
function focusPage() {
document.activeElement.blur();
}
function moveUp() {
if (currentRowIdx === 1) {
// If we are already in the top most row jump into the search box
focusSearchBox();
return;
}
hlrow(currentRowIdx, 2);
currentRowIdx--;
hlrow(currentRowIdx, 1);
}
function moveDown() {
if (currentRowIdx === nres) {
return;
}
hlrow(currentRowIdx, 2);
currentRowIdx++;
hlrow(currentRowIdx, 1);
}
function selectVocab() {
// Adapted from original page source, does the same but does not
// open the menu (hlrow())
if (markedrows["tr" + currentRowIdx ] != 1) {
setrowcolor(currentRowIdx, "#ffcc99");
markedrows["tr" + currentRowIdx] = 1;
}
else {
if (currentRowIdx % 2) {
// There is actually code in the page checking whether this
// value has been set - and if that's the case,
// a different color gets set (the same in both cases ) ^^.
// So I dont really understand this differentiation.
// But perhaps there is a setting somewhere to have alternating row colors.
setrowcolor(currentRowIdx, "#eeeeee");
}
else {
setrowcolor(currentRowIdx, "#dddddd");
}
markedrows["tr" + currentRowIdx] = 0;
// TODO: combine with this
hlrow(currentRowIdx, 1);
}
}
function addVocab() {
// This should not remove the current row from the selection, therefore only trigger a "click"
// in case it isn't already marked as selected.
if (currentRowIdx > 0 && markedrows["tr" + currentRowIdx] !== 1) {
selectVocab();
}
add2myvocab();
}
};