common/tcommon/static/js/theme.js
2024-12-21 23:25:56 -05:00

25 lines
637 B
JavaScript

let _themeMM = matchMedia("(prefers-color-scheme: light)");
let light, useAutoTheme;
light = _themeMM.matches;
function setTheme() {
let favicon = document.getElementById("favicon");
let fLink = favicon.href.split("/");
if (light) {
document.documentElement.setAttribute("data-light", "");
fLink[fLink.length - 3] = "light";
favicon.href = fLink.join("/");
} else {
document.documentElement.removeAttribute("data-light");
fLink[fLink.length - 3] = "dark";
favicon.href = fLink.join("/");
}
}
_themeMM.addEventListener("change", function() {
light = _themeMM.matches;
setTheme();
});
setTheme();