2020-01-23 10:14:47 +00:00
|
|
|
/* TODO: this should probably be something like night_mode.js since it does nothing specific to utility scripts */2
|
|
|
|
|
2020-01-19 07:51:08 +00:00
|
|
|
Event.observe(window, "load", function() {
|
|
|
|
const UtilityJS = {
|
|
|
|
apply_night_mode: function (is_night, link) {
|
|
|
|
console.log("night mode changed to", is_night);
|
|
|
|
|
|
|
|
if (link) {
|
|
|
|
const css_override = is_night ? "themes/night.css" : "css/default.css";
|
|
|
|
|
|
|
|
link.setAttribute("href", css_override + "?" + Date.now());
|
|
|
|
}
|
|
|
|
},
|
|
|
|
setup_night_mode: function() {
|
|
|
|
const mql = window.matchMedia('(prefers-color-scheme: dark)');
|
|
|
|
|
|
|
|
const link = new Element("link", {
|
|
|
|
rel: "stylesheet",
|
|
|
|
id: "theme_auto_css"
|
|
|
|
});
|
|
|
|
|
|
|
|
link.onload = function() {
|
|
|
|
document.querySelector("body").removeClassName("css_loading");
|
2020-01-25 14:00:51 +00:00
|
|
|
|
|
|
|
if (typeof UtilityApp != "undefined")
|
|
|
|
UtilityApp.init();
|
2020-01-19 07:51:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
mql.addEventListener("change", () => {
|
|
|
|
UtilityJS.apply_night_mode(mql.matches, link);
|
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
console.warn("exception while trying to set MQL event listener");
|
|
|
|
}
|
|
|
|
|
|
|
|
document.querySelector("head").appendChild(link);
|
|
|
|
|
|
|
|
UtilityJS.apply_night_mode(mql.matches, link);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
UtilityJS.setup_night_mode();
|
|
|
|
});
|