fix: pwa color

This commit is contained in:
hamster1963
2024-12-02 23:12:55 +08:00
parent 59ec052374
commit 66b474c5de
3 changed files with 19 additions and 1 deletions

View File

@@ -10,6 +10,7 @@
name="apple-mobile-web-app-status-bar-style"
content="black-translucent"
/>
<meta name="theme-color" content="#242424" />
<title>NEZHA</title>
<script>
(function () {
@@ -17,14 +18,23 @@
const theme = localStorage.getItem(storageKey) || "system";
const root = document.documentElement;
function updateThemeColor(isDark) {
const themeColor = isDark ? "#242424" : "#fafafa";
document
.querySelector('meta[name="theme-color"]')
.setAttribute("content", themeColor);
}
if (theme === "system") {
const systemTheme = window.matchMedia("(prefers-color-scheme: dark)")
.matches
? "dark"
: "light";
root.classList.add(systemTheme);
updateThemeColor(systemTheme === "dark");
} else {
root.classList.add(theme);
updateThemeColor(theme === "dark");
}
})();
</script>