mirror of
https://codeberg.org/vlw/victorwesterlund.com.git
synced 2025-09-14 11:33:41 +02:00
Added theme color change listener
This commit is contained in:
parent
d4f1438878
commit
bfa9babb35
1 changed files with 13 additions and 0 deletions
|
@ -4,3 +4,16 @@ if(navigator.serviceWorker) {
|
||||||
scope: "/"
|
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);
|
||||||
|
|
Loading…
Add table
Reference in a new issue