Use system theme for default choice
This commit is contained in:
parent
a922d0d9de
commit
f23c2dee02
1 changed files with 16 additions and 4 deletions
|
|
@ -30,11 +30,22 @@ const toggleDisplayMode = () => {
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("DOMContentLoaded", (evt) => {
|
window.addEventListener("DOMContentLoaded", (evt) => {
|
||||||
if (window.localStorage.getItem("displayMode") != null) {
|
if (window.localStorage.getItem("displayMode") == null) {
|
||||||
currentDisplayMode = window.localStorage.getItem("displayMode");
|
// Match with system dark mode
|
||||||
} else {
|
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||||
window.localStorage.setItem("displayMode", "dark");
|
window.localStorage.setItem("displayMode", "dark");
|
||||||
}
|
}
|
||||||
|
// Match with system light mode
|
||||||
|
else if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
|
||||||
|
window.localStorage.setItem("displayMode", "light");
|
||||||
|
}
|
||||||
|
// Literally choose the middle option
|
||||||
|
else {
|
||||||
|
window.localStorage.setItem("displayMode", "moonlight");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentDisplayMode = window.localStorage.getItem("displayMode");
|
||||||
|
|
||||||
if (currentDisplayMode == "dark") {
|
if (currentDisplayMode == "dark") {
|
||||||
document.getElementById("themekit-css").href = "/Libraries/css/themekit/main-dark.css";
|
document.getElementById("themekit-css").href = "/Libraries/css/themekit/main-dark.css";
|
||||||
|
|
@ -43,5 +54,6 @@ window.addEventListener("DOMContentLoaded", (evt) => {
|
||||||
} else {
|
} else {
|
||||||
document.getElementById("themekit-css").href = "/Libraries/css/themekit/main-light.css";
|
document.getElementById("themekit-css").href = "/Libraries/css/themekit/main-light.css";
|
||||||
}
|
}
|
||||||
|
|
||||||
updateDisplayModeIcons();
|
updateDisplayModeIcons();
|
||||||
});
|
});
|
||||||
Loading…
Reference in a new issue