-
Notifications
You must be signed in to change notification settings - Fork 0
/
dark.js
31 lines (27 loc) · 907 Bytes
/
dark.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
let darkMode = localStorage.getItem("darkMode");
const darkModeToggle = document.querySelector("#dark-mode-toggle");
const icon = document.querySelector("#dark-mode-toggle i");
const navbar = document.querySelector(".navbar");
const enableDarkMode = () => {
document.body.classList.add("darkmode");
localStorage.setItem("darkMode", "enabled");
icon.className = "fas fa-sun";
navbar.className = "navbar navbar-expand-lg navbar-dark";
};
const disableDarkMode = () => {
document.body.classList.remove("darkmode");
localStorage.removeItem("darkMode");
icon.className = "fas fa-moon";
navbar.className = "navbar navbar-expand-lg navbar-light";
};
if (darkMode === "enabled") {
enableDarkMode();
}
darkModeToggle.addEventListener("click", () => {
darkMode = localStorage.getItem("darkMode");
if (darkMode !== "enabled") {
enableDarkMode();
} else {
disableDarkMode();
}
});