mirror of
https://github.com/ShaYmez/FreeSTAR-Status-Engine.git
synced 2026-06-02 14:14:47 -04:00
add darkmode switch
This commit is contained in:
+26
@@ -27,3 +27,29 @@ function timeago() {
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
var darkSwitch = document.getElementById("darkSwitch");
|
||||
window.addEventListener("load", function () {
|
||||
if (darkSwitch) {
|
||||
initTheme();
|
||||
darkSwitch.addEventListener("change", function () {
|
||||
resetTheme();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
function initTheme() {
|
||||
var darkThemeSelected = localStorage.getItem("darkSwitch") !== null && localStorage.getItem("darkSwitch") === "dark";
|
||||
darkSwitch.checked = darkThemeSelected;
|
||||
darkThemeSelected ? document.body.setAttribute("data-theme", "dark") : document.body.removeAttribute("data-theme");
|
||||
}
|
||||
|
||||
function resetTheme() {
|
||||
if (darkSwitch.checked) {
|
||||
document.body.setAttribute("data-theme", "dark");
|
||||
localStorage.setItem("darkSwitch", "dark");
|
||||
} else {
|
||||
document.body.removeAttribute("data-theme");
|
||||
localStorage.removeItem("darkSwitch");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user