-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaddition.js
50 lines (48 loc) · 1.37 KB
/
addition.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
/*The underline of navigation*/
B.nav({
activeclass: 'current',
navclass: 'nvbtn'
});
B.navcheck();
/*The function for toggling the lazyload*/
var onlazy = true;
function togglelazy(element) {
if (onlazy) {
onlazy = false;
element.innerHTML = "我要加载图片!";
B.lazy(false);
} else {
onlazy = true;
element.innerHTML = "不要加载图片";
B.lazy(true);
}
}
/*The listener of 'backtotop' button*/
window.addEventListener("scroll", () => {
if (document.body.scrollTop <= 700) {
SC("backtop").style.opacity = 0;
} else {
SC("backtop").style.opacity = 1;
}
}, false);
/*Darkmode Support 20241105*/
let themeMode = localStorage.getItem("o_simple_darkmode");
if (themeMode == null) {
// 尚未定义,检测浏览器目前的主题
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
themeMode = "dark";
} else {
themeMode = "light";
}
localStorage.setItem("o_simple_darkmode", themeMode);
}
document.body.setAttribute("data-theme", themeMode);
SC("darkmode-switch").addEventListener("click", () => {
if (themeMode == "dark") {
themeMode = "light";
} else {
themeMode = "dark";
}
localStorage.setItem("o_simple_darkmode", themeMode);
document.body.setAttribute("data-theme", themeMode);
});