Use system theme for default choice

This commit is contained in:
oitsjustjose 2020-03-23 14:28:07 -04:00
commit f23c2dee02

View file

@ -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();
}); });