-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
119 lines (117 loc) · 3.1 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const html = document.documentElement.classList;
const svg = document.getElementById("svg");
let selctedTheme = document.cookie;
window.onload = function () {
selctedTheme = document.cookie;
if (document.cookie == "theme=dark") {
html.remove("light");
html.remove("system");
html.add("dark");
svg.src = "./img/moon.svg";
document.cookie = "theme = dark";
} else if (document.cookie == "theme=light") {
html.remove("system");
html.remove("dark");
html.add("light");
svg.src = "./img/sun.svg";
document.cookie = "theme = light";
} else {
html.remove("light");
html.remove("dark");
html.add("system");
svg.src = "./img/system.svg";
document.cookie = "theme = system";
if (
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
) {
html.add("dark");
} else {
html.remove("dark");
}
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", (event) => {
if (event.matches) {
html.add("dark");
} else {
html.remove("dark");
}
});
}
setInterval(() => {
selctedTheme = document.cookie;
if (document.cookie == "theme=dark") {
html.remove("light");
html.remove("system");
html.add("dark");
svg.src = "./img/moon.svg";
document.cookie = "theme = dark";
} else if (document.cookie == "theme=light") {
html.remove("system");
html.remove("dark");
html.add("light");
svg.src = "./img/sun.svg";
document.cookie = "theme = light";
} else {
html.add("system");
svg.src = "./img/system.svg";
document.cookie = "theme = system";
if (
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
) {
html.add("dark");
} else {
html.remove("dark");
}
window
.matchMedia("(prefers-color-scheme: dark)")
.addEventListener("change", (event) => {
if (event.matches) {
html.add("dark");
} else {
html.remove("dark");
}
});
}
}, 1000);
};
const changeTheme = {
lightTheme() {
selctedTheme = document.cookie;
html.remove("system");
html.remove("dark");
html.add("light");
svg.src = "./img/sun.svg";
document.cookie = "theme = light";
},
darkTheme() {
selctedTheme = document.cookie;
html.remove("system");
html.remove("light");
html.add("dark");
svg.src = "./img/moon.svg";
document.cookie = "theme = dark";
},
systemTheme() {
selctedTheme = document.cookie;
html.remove("light");
html.remove("dark");
html.add("system");
svg.src = "./img/system.svg";
document.cookie = "theme = system";
},
};
const numberInput = {
add(clickedID) {
let id = "numinput" + clickedID;
let num = document.getElementById(id).value;
document.getElementById(id).value = ++num;
},
removeN(clickedID) {
let id = "numinput" + clickedID;
let num = document.getElementById(id).value;
document.getElementById(id).value = --num;
},
};