1
0
mirror of https://github.com/Damillora/Yuika synced 2024-11-13 21:47:32 +00:00

feat(theme): persist dark mode

This commit is contained in:
Damillora 2021-04-14 22:19:52 +07:00
parent 5394121818
commit c7187ebcc4

View File

@ -1,14 +1,27 @@
function setDarkMode() {
if (!window.localStorage.getItem('theme') && window.document.body.getAttribute("data-theme")){
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");
}
}
if (window.localStorage.getItem('theme')) {
window.document.body.setAttribute("data-theme", window.localStorage.getItem("theme"));
}
$(document).ready(function () {
setDarkMode();
$("#darkMode").click(function () {
if (window.document.body.getAttribute("data-theme") != "dark") {
window.document.body.setAttribute("data-theme", "dark");
$("#darkMode i").text("brightness_high");
$("#darkMode p").text("Light Mode");
} else {
window.document.body.setAttribute("data-theme", "light");
$("#darkMode i").text("brightness_low");
$("#darkMode p").text("Dark Mode");
}
setDarkMode();
})
});