From 2e435683aa0080bda6e8be0955e86b03004e70fb Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Sun, 31 Jul 2022 20:44:12 +0200 Subject: refactor: Move shared preloaded js and css into web-shared --- apps/web-shared/src/assets/preload.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 apps/web-shared/src/assets/preload.js (limited to 'apps/web-shared/src/assets/preload.js') diff --git a/apps/web-shared/src/assets/preload.js b/apps/web-shared/src/assets/preload.js new file mode 100644 index 0000000..379902f --- /dev/null +++ b/apps/web-shared/src/assets/preload.js @@ -0,0 +1,13 @@ +const value = `; ${document.cookie}`; +const parts = value.split(`; go_theme=`); +let currentTheme = "system"; +if (parts.length === 2) { + currentTheme = parts.pop().split(";").shift(); +} +if (currentTheme === "light") { + document.querySelector("html").dataset.theme = "light"; +} else if (currentTheme === "dark") { + document.querySelector("html").dataset.theme = "dark"; +} else { + document.querySelector("html").dataset.theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light"; +} \ No newline at end of file -- cgit v1.3