-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
32 lines (26 loc) · 870 Bytes
/
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
new WOW().init();
const toggleIcon = document.querySelector(".toggle");
const userTheme = localStorage.getItem("theme");
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)").matches;
const themeCheck = () => {
if (userTheme === "dark" || (!userTheme && systemTheme)) {
document.documentElement.classList.add("dark");
return;
}
};
const themeSwitch = () => {
if (document.documentElement.classList.contains("dark")) {
document.documentElement.classList.remove("remove");
localStorage.setItem("theme", "light")
return;
}
document.documentElement.classList.add("dark");
localStorage.setItem("theme", "dark");
};
var el = document.querySelector('.toggle');
if (el) {
el.addEventListener("click", () => {
themeSwitch();
});
}
themeCheck();