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" /> <link rel="stylesheet" href="%sveltekit.assets%/global.css" />
%sveltekit.head% %sveltekit.head%
</head> </head>
<body> <body class="dark">
<div id="svelte">%sveltekit.body%</div> <div id="svelte">%sveltekit.body%</div>
</body> </body>
</html> </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 // 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. // 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 // TODO: make this use cookies and SSR
const darkmode = writable( // const darkmode = writable(
typeof window === "undefined" ? false : // typeof window === "undefined" ? false :
(JSON.parse(localStorage.getItem("darkmode")) || window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) // (JSON.parse(localStorage.getItem("darkmode")) || window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches)
); // );
const darkmode = writable(true)
darkmode.subscribe(v => { darkmode.subscribe(v => {
if(typeof window !== "undefined") if(typeof window !== "undefined")