-
Notifications
You must be signed in to change notification settings - Fork 0
/
util.js
38 lines (36 loc) · 1.07 KB
/
util.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
const output_attr = "data-output";
const selected_attr = "data-selected";
const button_class = "sc-output-button";
const output_class = "sc-output";
const update_target = (target) => {
for (let l2 of document.getElementsByClassName(button_class)) {
l2.setAttribute(
selected_attr,
l2.getAttribute(output_attr) == target ? "true" : ""
);
}
for (let t of document.getElementsByClassName(output_class)) {
if (t.getAttribute(output_attr) == target) {
t.style.display = "";
} else {
t.style.display = "none";
}
}
};
window.addEventListener("DOMContentLoaded", (e_) => {
{
let target = decodeURI((document.location.hash || "#").substr(1));
if (target.length == 0)
for (let t of document.getElementsByClassName(output_class)) {
target = t.getAttribute(output_attr);
break;
}
update_target(target);
}
for (let l of document.getElementsByClassName(button_class)) {
const target = l.getAttribute(output_attr);
l.addEventListener("click", (e_) => {
update_target(target);
});
}
});