dark mode only

This commit is contained in:
Daniel Bulant 2025-03-29 20:32:02 +01:00
parent b72498fbbe
commit 8ef657ec02
No known key found for this signature in database
2 changed files with 6 additions and 5 deletions

View file

@ -8,7 +8,7 @@
<link rel="stylesheet" href="%sveltekit.assets%/global.css" />
%sveltekit.head%
</head>
<body>
<body class="dark">
<div id="svelte">%sveltekit.body%</div>
</body>
</html>

View file

@ -4,10 +4,11 @@ import { writable } from "svelte/store";
// it works! But isn't very performant - darkmode is switched after loading the page, not very friendly
// could probably set a cookie and have the class be set in SSR as well, I don't really want to spend the time on that now.
// TODO: make this use cookies and SSR
const darkmode = writable(
typeof window === "undefined" ? false :
(JSON.parse(localStorage.getItem("darkmode")) || window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)
);
// const darkmode = writable(
// typeof window === "undefined" ? false :
// (JSON.parse(localStorage.getItem("darkmode")) || window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)
// );
const darkmode = writable(true)
darkmode.subscribe(v => {
if(typeof window !== "undefined")