-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisplay.js
66 lines (56 loc) · 2.04 KB
/
display.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
function paramVal(name, def) {
return url.searchParams.has(name) ? url.searchParams.get(name) : def;
}
function paramNumVal(name, def) {
return url.searchParams.has(name) ? Number.parseInt(url.searchParams.get(name)) : def;
}
var url = new URL(location.href);
var start = paramNumVal("start", 1);
var end = paramNumVal("end", 40);
if (end < start)
end = start;
var typeopt = paramVal("type", "0").split(/ /);
function wordFilter(word) {
if (word.chapter < start || word.chapter > end) return false;
if (typeopt[0] == "0") return true;
if (!word.type.split(/, /).includes(typeopt[0])) return false;
if (!typeopt[1]) return true;
if (typeopt[0] == 'verb') {
return word.conjugation == typeopt[1];
} else if (typeopt[0] == 'noun') {
return word.declension == typeopt[1];
}
return true;
}
function buildTable() {
var displaytable = document.getElementById("displaytable");
vocab.filter(wordFilter).forEach((word) => {
var tr = document.createElement("tr");
var td = document.createElement("td");
td.align = "center";
td.innerText = word.chapter;
tr.appendChild(td);
td = document.createElement("td");
td.align = "center";
td.innerText = word.type;
var types = word.type.split(/, /);
if (types.includes('verb')) {
td.innerText += ` (${word.conjugation ? word.conjugation : 'irregular'})`;
} else if (types.includes('noun')) {
td.innerText += ` (${word.declension ? word.declension : 'indeclinable'})`;
}
tr.appendChild(td);
td = document.createElement("td");
td.innerText = word.latin;
if (word.gender)
td.innerText += `, ${word.gender}.`;
tr.appendChild(td);
td = document.createElement("td");
td.innerText = word.english;
if (word.notes)
td.innerText += ` (${word.notes})`;
tr.appendChild(td);
displaytable.appendChild(tr);
});
}
addEventListener("load", () => GetVocab(buildTable));