adds dark mode
This commit is contained in:
19
assets/js/darkmode.js
Normal file
19
assets/js/darkmode.js
Normal 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";
|
||||
}
|
Reference in New Issue
Block a user