-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy paththemeswitch.js
45 lines (39 loc) · 1.2 KB
/
themeswitch.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
var switches = document.getElementsByClassName("switch");
var style = localStorage.getItem("style");
if (style == null) {
setTheme("default");
} else {
setTheme(style);
}
for (var i = 0; i < Object.keys(switches).length; i++) {
var switchElement = switches[i];
switchElement.addEventListener("click", function () {
var theme = this.dataset.theme;
setTheme(theme);
});
}
function setTheme(theme) {
switch (theme) {
case "default":
document.getElementById("theme-switch").href = "./themes/default.css";
break;
case "dark":
document.getElementById("theme-switch").href = "./themes/dark.css";
break;
case "deepblue":
document.getElementById("theme-switch").href = "./themes/deepblue.css";
break;
case "owlpurple":
document.getElementById("theme-switch").href = "./themes/owlpurple.css";
break;
case "mint":
document.getElementById("theme-switch").href = "./themes/mint.css";
break;
case "lemon":
document.getElementById("theme-switch").href = "./themes/lemon.css";
break;
default:
document.getElementById("theme-switch").href = "./themes/default.css";
}
localStorage.setItem("style", theme);
}