aboutsummaryrefslogtreecommitdiffstats
path: root/src/hooks.server.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2024-03-19 10:23:34 -0700
committerAdam Soltys <[email protected]>2024-03-19 10:23:34 -0700
commita4685f61e656ed0e3cd343073931867955be3281 (patch)
treec28c446ef0f6d5cbc37a7c58f954c145bd18ef80 /src/hooks.server.js
parentc6c2ac113186ba304c46580320df91c119ab5314 (diff)
parente2bb9d704878070054fa8ef81da73b248e2c4f97 (diff)
downloadcoinos-ui-a4685f61e656ed0e3cd343073931867955be3281.tar.gz
coinos-ui-a4685f61e656ed0e3cd343073931867955be3281.zip
Merge remote-tracking branch 'muriwolf/swapee' into swapee
Diffstat (limited to 'src/hooks.server.js')
-rw-r--r--src/hooks.server.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/hooks.server.js b/src/hooks.server.js
new file mode 100644
index 00000000..dca44977
--- /dev/null
+++ b/src/hooks.server.js
@@ -0,0 +1,29 @@
+
+export const handle = (async ({ event, resolve }) => {
+ let theme = "dark";
+
+ const newTheme = event.url.searchParams.get("theme");
+ const cookieTheme = event.cookies.get("colortheme");
+
+ if (newTheme) {
+ theme = newTheme;
+ } else if (cookieTheme) {
+ theme = cookieTheme;
+ }
+
+ if (theme) {
+ return await resolve(event, {
+ transformPageChunk: ({ html }) => {
+ const modifiedHtml = html.replace(/<html[^>]*>/, (match) => {
+ // Ensure the class attribute exists or add it if missing
+ return match.includes('class="')
+ ? match.replace(/class="[^"]*"/, `class="${theme}"`)
+ : match.replace('>', ` class="${theme}">`);
+ });
+ return modifiedHtml;
+ }
+ });
+ }
+
+ return await resolve(event);
+}) \ No newline at end of file