mirror of
https://codeberg.org/vlw/victorwesterlund.com.git
synced 2025-09-13 19:13:42 +02:00
Renamed the folder `public/` to make it usable with GH Pages only non-root directory.
19 lines
568 B
JavaScript
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);
|