From 502aaa7148d87c794fdbd9264836e90d8cac9afd Mon Sep 17 00:00:00 2001 From: "David G. Simmons" Date: Mon, 21 Oct 2024 09:35:54 -0400 Subject: [PATCH] remove in-line script from header --- assets/scripts/core/index.js | 1 + assets/scripts/core/theme-scheme.js | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 assets/scripts/core/theme-scheme.js diff --git a/assets/scripts/core/index.js b/assets/scripts/core/index.js index 31f9d0390..939d5df22 100644 --- a/assets/scripts/core/index.js +++ b/assets/scripts/core/index.js @@ -1,2 +1,3 @@ export * from './device' export * from './insertScript' +export * from './theme-scheme' diff --git a/assets/scripts/core/theme-scheme.js b/assets/scripts/core/theme-scheme.js new file mode 100644 index 000000000..8e50b9666 --- /dev/null +++ b/assets/scripts/core/theme-scheme.js @@ -0,0 +1,11 @@ +let theme = localStorage.getItem('theme-scheme') || localStorage.getItem('darkmode:color-scheme') || 'light' +const b = 'bollocks!'; +console.log(b); +if (theme === 'system') { + if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) { + theme = 'dark' + } else { + theme = 'light' + } +} +document.documentElement.setAttribute('data-theme', theme)