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:
parent
5394121818
commit
c7187ebcc4
@ -1,14 +1,27 @@
|
||||
|
||||
$(document).ready(function () {
|
||||
$("#darkMode").click(function () {
|
||||
if (window.document.body.getAttribute("data-theme") != "dark") {
|
||||
window.document.body.setAttribute("data-theme", "dark");
|
||||
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 {
|
||||
window.document.body.setAttribute("data-theme", "light");
|
||||
$("#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");
|
||||
} else {
|
||||
window.document.body.setAttribute("data-theme", "light");
|
||||
}
|
||||
setDarkMode();
|
||||
})
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user