victorwesterlund.com/public/assets/js/script.js
2021-09-05 18:21:27 +02:00

22 lines
No EOL
607 B
JavaScript

// Copyright © Victor Westerlund - No libraries! 😲
import { default as Interaction } from "./modules/UI.mjs";
const theme = window.matchMedia("(prefers-color-scheme: dark)");
const main = new Interaction();
function updateTheme() {
const media = window.matchMedia("(prefers-color-scheme: dark)");
document.body.classList.remove("dark");
// Force dark theme on all pages
if(media.matches) {
document.body.classList.add("dark");
return;
}
main.setThemeColor("background");
}
// Set the current page theme, and listen for changes
theme.addEventListener("change",updateTheme);
updateTheme();