1
0
mirror of https://github.com/Damillora/Yuika synced 2024-11-22 17:27:32 +00:00
Yuika/assets/js/lib/dark-mode.js

27 lines
1.0 KiB
JavaScript
Raw Permalink Normal View History

2021-04-14 15:19:52 +00:00
function setDarkMode() {
2021-04-22 10:03:54 +00:00
if (window.document.body.getAttribute("data-theme")) {
2021-04-14 15:19:52 +00:00
window.localStorage.setItem('theme', window.document.body.getAttribute("data-theme"));
}
if (window.document.body.getAttribute("data-theme") == "dark") {
window.document.querySelector("#darkMode i").innerHTML = "brightness_high";
window.document.querySelector("#darkMode p").innerHTML = "Light Mode";
2021-04-14 15:19:52 +00:00
} else {
window.document.querySelector("#darkMode i").innerHTML = "brightness_low";
window.document.querySelector("#darkMode p").innerHTML = "Dark Mode";
2021-04-14 15:19:52 +00:00
}
}
2021-04-14 15:19:52 +00:00
if (window.localStorage.getItem('theme')) {
window.document.body.setAttribute("data-theme", window.localStorage.getItem("theme"));
}
2021-04-22 10:03:54 +00:00
setDarkMode();
document.getElementById("darkMode").addEventListener("click", function () {
if (window.document.body.getAttribute("data-theme") != "dark") {
window.document.body.setAttribute("data-theme", "dark");
} else {
window.document.body.setAttribute("data-theme", "light");
}
2021-04-14 15:19:52 +00:00
setDarkMode();
});