30 lines
634 B
JavaScript
30 lines
634 B
JavaScript
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();
|