victorwesterlund.com/docs/assets/js/script.js
Victor Westerlund 52b8945086 Renamed public/ to docs/
Renamed the folder `public/` to make it usable with GH Pages only non-root directory.
2021-08-06 13:42:42 +02:00

19 lines
568 B
JavaScript

// Register SW if supported by browser
if(navigator.serviceWorker) {
navigator.serviceWorker.register("sw.js",{
scope: "/"
});
}
const theme = window.matchMedia("(prefers-color-scheme: dark)");
// Set theme color
function updateTheme() {
// Get theme color from stylesheet
const color = window.getComputedStyle(document.body).getPropertyValue("--color-background");
document.querySelector("meta[name='theme-color']").setAttribute("content",color);
}
// Set theme color and listen for changes
theme.addEventListener("change",updateTheme);
updateTheme(theme);