diff options
| author | Murillo Pinheiro de Oliveira <[email protected]> | 2024-02-10 18:04:05 -0300 |
|---|---|---|
| committer | Murillo Pinheiro de Oliveira <[email protected]> | 2024-02-10 18:04:05 -0300 |
| commit | 12609903a777413171ec71e646d4eb775414e6a3 (patch) | |
| tree | 7bab09d51dc78ea3bb86e053886f8d5812b699f7 /src/hooks.server.js | |
| parent | a02ea8e85d789d5acca9922b61222233bbc09ec6 (diff) | |
| download | coinos-ui-12609903a777413171ec71e646d4eb775414e6a3.tar.gz coinos-ui-12609903a777413171ec71e646d4eb775414e6a3.zip | |
added: dark toggle working
Diffstat (limited to 'src/hooks.server.js')
| -rw-r--r-- | src/hooks.server.js | 29 |
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 |
