-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
50 lines (41 loc) · 1.49 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
(function () {
const htmlElement = document.documentElement;
const previewFrame = document.getElementsByClassName("preview-frame")[0];
const sidetabActions = document.getElementsByClassName("side-tab-action");
const spinnerElement =
document.getElementsByClassName("spinner-container")[0];
let lastActiveTab = sidetabActions[0];
function showSpinner() {
previewFrame.classList.remove("show");
previewFrame.classList.add("hide");
spinnerElement.classList.remove("hide");
spinnerElement.classList.add("show");
}
function hideSpinner() {
spinnerElement.classList.remove("show");
spinnerElement.classList.add("hide");
previewFrame.classList.remove("hide");
previewFrame.classList.add("show");
}
[...sidetabActions].forEach((sidetabAction) => {
function handleAnchorClick(event) {
lastActiveTab.classList.remove("active-tab");
lastActiveTab = event.target;
lastActiveTab.classList.add("active-tab");
showSpinner();
function handleFrameLoad() {
hideSpinner();
previewFrame.removeEventListener("load", handleFrameLoad);
}
const href = sidetabAction.dataset.href;
previewFrame.src = href;
previewFrame.addEventListener("load", handleFrameLoad);
}
sidetabAction.addEventListener("click", handleAnchorClick);
});
// theme initially as system
const theme = matchMedia("(prefers-color-scheme: dark)");
if (theme.matches) {
htmlElement.setAttribute("data-theme", "dark");
}
})();