common/tcommon/static/js/theme.js

26 lines
637 B
JavaScript
Raw Normal View History

2024-12-20 21:18:31 -05:00
let _themeMM = matchMedia("(prefers-color-scheme: light)");
let light, useAutoTheme;
2024-12-20 23:44:40 -05:00
light = _themeMM.matches;
2024-12-20 21:18:31 -05:00
function setTheme() {
2024-12-21 23:25:56 -05:00
let favicon = document.getElementById("favicon");
let fLink = favicon.href.split("/");
2024-12-20 21:18:31 -05:00
if (light) {
document.documentElement.setAttribute("data-light", "");
2024-12-21 23:25:56 -05:00
fLink[fLink.length - 3] = "light";
favicon.href = fLink.join("/");
2024-12-20 21:18:31 -05:00
} else {
document.documentElement.removeAttribute("data-light");
2024-12-21 23:25:56 -05:00
fLink[fLink.length - 3] = "dark";
favicon.href = fLink.join("/");
2024-12-20 21:18:31 -05:00
}
}
_themeMM.addEventListener("change", function() {
2024-12-20 23:44:40 -05:00
light = _themeMM.matches;
setTheme();
2024-12-20 21:18:31 -05:00
});
setTheme();