-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautogen.js
45 lines (37 loc) · 1.25 KB
/
autogen.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
/** Copyright 2022 Cameron Foale / Federation University Australia */
(function () {
// pull out a mapping from number to value
const table = document.querySelector(".qtext tbody");
if (!table) return;
// Cells must contain something like 1 = y
const re = /^\s*(\d+)\s*=\s*?(.*?)\s*$/;
for (let row of table.querySelectorAll("tr")) {
const cells = Array.prototype.slice.apply(row.querySelectorAll("td"), [0]);
const firstCell = cells[0];
const span = firstCell.querySelector("span");
if (!span) continue;
const searchValue = span.textContent.trim();
const spanPre = firstCell.childNodes[0];
for (let cell of cells.slice(1)) {
const match = re.exec(cell.textContent);
if (match && match[1] === searchValue) {
span.textContent = match[2];
// fix a -> an
if (spanPre.textContent.match(/\s*a\s*$/)) {
if (match[2].match(/^\s*[aeiouAEIOU].*$/)) {
spanPre.textContent += "n";
}
}
break;
}
}
}
// hide the options
const style = ".qtext td { display: none; }\n" +
".qtext td:first-child { display: table-cell; }\n" +
".d-print-none { display: none; }\n" +
".info { display: none; }";
const css = document.createElement("style");
css.textContent = style;
document.head.append(css);
})();