Added theme color change listener

This commit is contained in:
Victor Westerlund 2021-06-03 13:47:15 +02:00
parent d4f1438878
commit bfa9babb35

View file

@ -4,3 +4,16 @@ if(navigator.serviceWorker) {
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);