adds dark mode

This commit is contained in:
Drew
2025-04-26 14:45:42 -06:00
parent e0546c0e2e
commit bd702f8f51
11 changed files with 87 additions and 24 deletions

19
assets/js/darkmode.js Normal file
View File

@ -0,0 +1,19 @@
// Set initial theme on page load
(function() {
const isDark = localStorage.theme === "dark" ||
(!("theme" in localStorage) && window.matchMedia("(prefers-color-scheme: dark)").matches);
document.documentElement.classList.toggle("dark", isDark);
// Update label on load
const label = document.getElementById("darkmode-label");
if (label) label.textContent = !isDark ? "Dark" : "Light";
})();
// Toggle dark mode and update label/localStorage
function toggleDarkMode() {
const html = document.documentElement;
const isDark = html.classList.toggle("dark");
localStorage.theme = isDark ? "dark" : "light";
const label = document.getElementById("darkmode-label");
if (label) label.textContent = !isDark ? "Dark" : "Light";
}