feat: dynamic PWA theme color

This commit is contained in:
qier222 2020-10-25 21:55:20 +08:00
parent b655c59761
commit c448230c14
3 changed files with 19 additions and 24 deletions

View file

@ -95,3 +95,15 @@ export function dailyTask() {
dailySignin(1);
}
}
export function changeAppearance(appearance) {
if (appearance === "auto" || appearance === undefined) {
appearance = window.matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light";
}
document.body.setAttribute("data-theme", appearance);
document
.querySelector('meta[name="theme-color"]')
.setAttribute("content", appearance === "dark" ? "#222" : "#fff");
}