chore: apply color immediately

This commit is contained in:
Ou 2024-10-17 15:43:20 +08:00
parent 3dc9c4b28c
commit 0d84e4b70d
2 changed files with 7 additions and 6 deletions

View File

@ -4,6 +4,13 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/icon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script>
const theme = localStorage.getItem("color-scheme") || "auto"
const isDark = window.matchMedia("(prefers-color-scheme: dark)").matches
if (theme === "auto" ? isDark : theme === "dark") {
document.documentElement.classList.add("dark")
}
</script>
<title>NewsNow</title>
</head>
<body>

View File

@ -17,12 +17,6 @@ export const Route = createRootRouteWithContext<{
component: RootComponent,
notFoundComponent: NotFoundComponent,
beforeLoad: () => {
const theme = localStorage.getItem("color-scheme") || "auto"
const isDark = window.matchMedia("(prefers-color-scheme: dark)").matches
if (theme === "auto" ? isDark : theme === "dark") {
document.documentElement.classList.add("dark")
}
const query = new URLSearchParams(window.location.search)
if (query.has("login")) {
[...query.entries()].forEach(key => localStorage.setItem(key[0], key[1]))