auth/tauth/templates/js/theme.js

31 lines
634 B
JavaScript
Raw Normal View History

2024-12-20 08:59:39 -05:00
let _themeMM = matchMedia("(prefers-color-scheme: light)");
let light, useAutoTheme;
// {% if theme == "auto" %}
light = _themeMM.matches;
useAutoTheme = true;
// {% else %}
// {% if theme == "light" %}
light = true;
// {% else %}
light = false;
// {% endif %}
useAutoTheme = false;
// {% endif %}
function setTheme() {
if (light) {
document.documentElement.setAttribute("data-light", "");
} else {
document.documentElement.removeAttribute("data-light");
}
}
_themeMM.addEventListener("change", function() {
if (useAutoTheme) {
light = _themeMM.matches;
setTheme();
}
});
setTheme();