1
0
mirror of https://github.com/Damillora/Yuika synced 2024-11-23 01:37:33 +00:00
Yuika/assets/js/dark-mode.js

29 lines
964 B
JavaScript
Raw Normal View History

2021-04-14 15:19:52 +00:00
function setDarkMode() {
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") {
$("#darkMode i").text("brightness_high");
$("#darkMode p").text("Light Mode");
} else {
$("#darkMode i").text("brightness_low");
$("#darkMode p").text("Dark Mode");
}
}
2021-04-14 15:19:52 +00:00
if (window.localStorage.getItem('theme')) {
window.document.body.setAttribute("data-theme", window.localStorage.getItem("theme"));
}
$(document).ready(function () {
2021-04-14 15:19:52 +00:00
setDarkMode();
$("#darkMode").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();
})
});