feat: synchronize theme browser chrome
CI / backend-and-migrations (push) Canceled after 0s
CI / astro-build (push) Canceled after 0s
CI / dependency-audit (push) Canceled after 0s
CI / compose-e2e (push) Canceled after 0s

This commit is contained in:
ik
2026-09-13 16:17:22 +07:00
parent 54a1e6c042
commit aed541c70c
5 changed files with 13 additions and 5 deletions
+2 -2
View File
@@ -6,8 +6,8 @@
"start_url": "/",
"scope": "/",
"display": "standalone",
"background_color": "#f2f5ee",
"theme_color": "#082226",
"background_color": "#071719",
"theme_color": "#071719",
"icons": [
{ "src": "/icon-192.png", "sizes": "192x192", "type": "image/png", "purpose": "any" },
{ "src": "/icon-512.png", "sizes": "512x512", "type": "image/png", "purpose": "any" },
+7 -1
View File
@@ -52,7 +52,8 @@ const jsonLd = JSON.stringify({
<link rel="icon" href="/favicon-32.png" sizes="32x32" type="image/png" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="manifest" href="/site.webmanifest" />
<meta name="theme-color" content="#082226" />
<meta name="theme-color" content="#f2f5ee" media={theme === "system" ? "(prefers-color-scheme: light)" : theme === "light" ? "all" : "not all"} data-theme-color="light" />
<meta name="theme-color" content="#071719" media={theme === "system" ? "(prefers-color-scheme: dark)" : theme === "dark" ? "all" : "not all"} data-theme-color="dark" />
<meta property="og:locale" content="ru_RU" />
<meta property="og:type" content="website" />
<meta property="og:site_name" content="RF4 Spotter" />
@@ -94,6 +95,7 @@ const jsonLd = JSON.stringify({
<script>
const root = document.documentElement;
const themeButtons = document.querySelectorAll<HTMLButtonElement>("[data-theme-option]");
const themeColors = document.querySelectorAll<HTMLMetaElement>("[data-theme-color]");
const allowedThemes = new Set(["system", "light", "dark"]);
const applyTheme = (value: string) => {
@@ -103,6 +105,10 @@ const jsonLd = JSON.stringify({
themeButtons.forEach((button) => {
button.setAttribute("aria-pressed", String(button.dataset.themeOption === theme));
});
themeColors.forEach((meta) => {
const color = meta.dataset.themeColor;
meta.media = theme === "system" ? `(prefers-color-scheme: ${color})` : color === theme ? "all" : "not all";
});
const secure = location.protocol === "https:" ? "; Secure" : "";
document.cookie = `rf4-theme=${theme}; Max-Age=31536000; Path=/; SameSite=Lax${secure}`;
};