-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathscript.js
56 lines (49 loc) · 1.56 KB
/
script.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
function getGroupRows(term) {
const rows = [];
for (let row = term.parentNode.parentNode;
row != null;
row = row.previousElementSibling) {
rows.push(row);
if (row.classList.contains('group-head')) break;
}
for (let row = term.parentNode.parentNode.nextElementSibling;
row != null && !row.classList.contains('group-head');
row = row.nextElementSibling) {
rows.push(row);
}
return rows;
}
function getHoverClasses(term) {
return Array.from(term.classList)
.filter(c => c.startsWith('correspond-'))
.map(c => 'hover-' + c);
}
function onCorrespond() {
const classes = getHoverClasses(this);
for (const row of getGroupRows(this)) {
row.className = Array.from(row.classList)
.filter(c => !c.startsWith('hover-correspond-'))
.concat(classes)
.join(' ');
}
}
function offCorrespond() {
for (const row of getGroupRows(this)) {
row.className = Array.from(row.classList)
.filter(c => !c.startsWith('hover-correspond-'))
.join(' ');
}
}
Array.from(document.querySelectorAll('*[class*="correspond-"]'))
.filter(e => e.className.match(/\bcorrespond-\d+\b/))
.forEach(e => {
e.addEventListener('mouseover', onCorrespond);
e.addEventListener('mouseout', offCorrespond);
});
const tocTitle = document.querySelector('#toc > div > h2').innerText.trim();
Array.from(document.querySelectorAll(':not(#toc > div) > h2, h3'))
.forEach(h => {
h.innerHTML +=
` <a class="toc" href="${location.pathname}#toc">${tocTitle}</a>`;
});
// vim: set et sw=2 ts=2 sts=2 ft=javascript: