mirror of
https://github.com/KivotosRailway/website.git
synced 2026-11-03 11:06:32 +09:00
优化页面数据加载并完善多语言 SEO、新闻回退、主题首屏及自动化回归测试
This commit is contained in:
+10
-2
@@ -3,10 +3,18 @@
|
||||
let preference = "system";
|
||||
try {
|
||||
const cookieTheme = document.cookie.split(";").map((entry) => entry.trim()).find((entry) => entry.startsWith("kr-theme="))?.slice("kr-theme=".length);
|
||||
const savedTheme = isTheme(cookieTheme) ? cookieTheme : localStorage.getItem("kr-theme");
|
||||
if (isTheme(savedTheme)) preference = savedTheme;
|
||||
if (isTheme(cookieTheme)) preference = cookieTheme;
|
||||
else {
|
||||
try {
|
||||
const saved = localStorage.getItem("kr-theme");
|
||||
if (isTheme(saved)) preference = saved;
|
||||
} catch {}
|
||||
}
|
||||
} catch {}
|
||||
const theme = preference === "system" ? (matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light") : preference;
|
||||
document.documentElement.dataset.theme = theme;
|
||||
document.documentElement.style.colorScheme = theme;
|
||||
const color = theme === "dark" ? "#10151d" : "#ffffff";
|
||||
document.documentElement.style.backgroundColor = color;
|
||||
document.querySelectorAll('meta[name="theme-color"]').forEach((meta) => meta.setAttribute("content", color));
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user