blob: 4ef8b86d785e97079665dd3dda2ce0fcde094dd0 (
plain) (
blame)
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
|
<i id="dark-mode-toggle"></i>
<script>
var toggle = document.getElementById("dark-mode-toggle");
var darkTheme = document.getElementById("dark-mode-theme");
var savedTheme = localStorage.getItem("dark-mode-storage") || "light";
setTheme(savedTheme);
toggle.addEventListener("click", () => {
if (toggle.className === "fas fa-moon") {
setTheme("dark");
} else if (toggle.className === "fas fa-sun") {
setTheme("light");
}
});
function setTheme(mode) {
localStorage.setItem("dark-mode-storage", mode);
if (mode === "dark") {
darkTheme.disabled = false;
toggle.className = "fas fa-sun";
} else if (mode === "light") {
darkTheme.disabled = true;
toggle.className = "fas fa-moon";
}
}
</script>
|