-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
32 lines (29 loc) · 1.06 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
document.addEventListener("DOMContentLoaded", () => {
const savedTheme = localStorage.getItem("theme");
applyTheme(savedTheme || "dark");
});
function toggleMode() {
const currentTheme = document.documentElement.classList.contains("light")
? "dark"
: "light";
applyTheme(currentTheme);
localStorage.setItem("theme", currentTheme);
}
function applyTheme(theme) {
const html = document.documentElement;
const root = document.querySelector(":root");
const img = document.querySelector("#user img");
if (theme === "light") {
html.classList.add("light");
html.classList.remove("dark");
img.setAttribute("src", "./assets/avatar-light.png");
img.setAttribute("alt", "Light theme user image");
root.style.setProperty("--bg-color", "rgb(239, 235, 239)");
} else {
html.classList.add("dark");
html.classList.remove("light");
img.setAttribute("src", "./assets/avatar-dark.png");
img.setAttribute("alt", "Dark theme user image");
root.style.setProperty("--bg-color", "rgb(22, 22, 24)");
}
}