-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdarkMode.js
29 lines (25 loc) · 933 Bytes
/
darkMode.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
const body = document.getElementById("workstation-root");
const icon = document.getElementById("workstation-icon");
function toggleDarkMode() {
const currentClass = body.className;
body.className =
currentClass == "workstation-dark-mode"
? "workstation-light-mode"
: "workstation-dark-mode";
// Update icon after class change
setTimeout(function () {
icon.innerHTML =
body.className == "workstation-dark-mode"
? `<i class="fa-regular fa-sun"></i>`
: `<i class="fa-regular fa-moon"></i>`;
}, 0);
const mode = body.className == "workstation-dark-mode" ? "dark" : "light";
localStorage.setItem("mode", mode);
}
document.addEventListener("DOMContentLoaded", () => {
const mode = localStorage.getItem("mode");
if (mode === "dark") {
body.className = "workstation-dark-mode";
icon.innerHTML = `<i class="fa-regular fa-sun"></i>`;
}
});