-
Notifications
You must be signed in to change notification settings - Fork 6
/
script.js
40 lines (39 loc) · 1.35 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
const themeToggle = document.getElementById("darkBtn");
themeToggle.addEventListener("click", () => {
themeToggle.classList.toggle("fa-moon");
themeToggle.classList.toggle("fa-sun");
if (localStorage.getItem("theme")) {
let currentTheme = localStorage.getItem("theme");
if (currentTheme == 1) {
localStorage.setItem("theme", 0);
document.getElementsByTagName("body")[0].classList.remove("dark");
themeToggle.classList.add("fa-moon");
themeToggle.classList.remove("fa-sun");
}
else {
localStorage.setItem("theme", 1);
document.getElementsByTagName("body")[0].classList.add("dark");
themeToggle.classList.add("fa-sun");
themeToggle.classList.remove("fa-moon");
}
}
else {
document.getElementsByTagName("body")[0].classList.add("dark");
localStorage.setItem("theme", 1);
themeToggle.classList.add("fa-sun");
}
});
// 1 - For darkmode 2- For NormalMode
if (localStorage.getItem("theme")) {
let currentTheme = localStorage.getItem("theme");
if (currentTheme == 1) {
document.getElementsByTagName("body")[0].classList.add("dark");
themeToggle.classList.add("fa-sun");
themeToggle.classList.remove("fa-moon");
}
else {
document.getElementsByTagName("body")[0].classList.remove("dark");
themeToggle.classList.remove("fa-sun");
themeToggle.classList.add("fa-moon");
}
}