add Lisntener to prefers-color-scheme

This commit is contained in:
2023-06-27 16:22:45 +08:00
parent a890a40a62
commit 5b33cc8d96
2 changed files with 18 additions and 1 deletions

View File

@@ -2,3 +2,11 @@ export function detect_darkmode() {
return window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches;
}
export function addDarkModeListener(e: (e: MediaQueryListEvent) => void) {
return window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").addEventListener(
"change",
e,
);
}