revamp

This commit is contained in:
piharpi
2020-03-09 22:37:39 +07:00
parent 7067f11243
commit 1fabbf8ea7
122 changed files with 4524 additions and 1482 deletions

35
assets/js/main.js Normal file
View File

@@ -0,0 +1,35 @@
(() => {
// Theme switch
const root = document.body;
const themeSwitch = document.getElementById("mood");
const themeData = root.getAttribute("data-theme");
if (themeSwitch) {
initTheme(localStorage.getItem("theme"));
themeSwitch.addEventListener("click", () =>
toggleTheme(localStorage.getItem("theme"))
);
function toggleTheme(state) {
if (state === "dark") {
localStorage.setItem("theme", "light");
root.removeAttribute("data-theme");
} else if (state === "light") {
localStorage.setItem("theme", "dark");
document.body.setAttribute("data-theme", "dark");
} else {
initTheme(state);
}
}
function initTheme(state) {
if (state === "dark") {
document.body.setAttribute("data-theme", "dark");
} else if (state === "light") {
root.removeAttribute("data-theme");
} else {
localStorage.setItem("theme", themeData);
}
}
}
})();