Skip to content

Commit af38a1e

Browse files
refactor: simplify dark mode toggle logic for improved readability
1 parent ef79650 commit af38a1e

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

website/script.js

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -475,25 +475,16 @@ function switchDarkMode () {
475475
const body = document.getElementsByTagName("body")[0];
476476
const root = document.querySelector(":root");
477477
const sortButton = document.getElementById("sort-dropdown");
478-
if (darkMode.checked) {
479-
header.style.backgroundColor = "#222";
480-
header.style.color = "#e9e9e9";
481-
body.style.backgroundColor = "#222";
482-
sortButton.style.color = "#ddd";
483-
sortButton.style.backgroundColor = "#555";
484-
resetButton.style.color = "#ddd";
485-
resetButton.style.backgroundColor = "#555";
486-
root.style.setProperty("--color-card-background", "#ddd");
487-
} else {
488-
header.style.backgroundColor = "#e9e9e9";
489-
header.style.color = "#222";
490-
body.style.backgroundColor = "#e9e9e9";
491-
sortButton.style.color = "#555";
492-
sortButton.style.backgroundColor = "#ddd";
493-
resetButton.style.color = "#555";
494-
resetButton.style.backgroundColor = "#ddd";
495-
root.style.setProperty("--color-card-background", "#fff");
496-
}
478+
const isDark = darkMode.checked;
479+
480+
header.style.backgroundColor = isDark ? "#222" : "#e9e9e9";
481+
header.style.color = isDark ? "#e9e9e9" : "#222";
482+
body.style.backgroundColor = isDark ? "#222" : "#e9e9e9";
483+
sortButton.style.color = isDark ? "#ddd" : "#555";
484+
sortButton.style.backgroundColor = isDark ? "#555" : "#ddd";
485+
resetButton.style.color = isDark ? "#ddd" : "#555";
486+
resetButton.style.backgroundColor = isDark ? "#555" : "#ddd";
487+
root.style.setProperty("--color-card-background", isDark ? "#ddd" : "#fff");
497488

498489
const navMenu = document.getElementById("nav-menu");
499490
if (navMenu.classList.contains("visible")) {

0 commit comments

Comments
 (0)