From f1c2eb435e4fd7c5000ec18c48177598244ecb30 Mon Sep 17 00:00:00 2001 From: Sam Henry Date: Tue, 25 Jan 2022 10:01:59 +1000 Subject: [PATCH 1/2] added auto switch on change to system theme if the user hasn't set chosen a theme this code will switch the dark/light mode based on changes to the system theme after first page load --- helper.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/helper.js b/helper.js index 63d16d4..6ee08be 100644 --- a/helper.js +++ b/helper.js @@ -15,7 +15,11 @@ module.exports = { } return 'light'; } - getInitialColorMode() == 'light' ? document.documentElement.classList.remove('dark') : document.documentElement.classList.add('dark'); + function setTheme () { + getInitialColorMode() == 'light' ? document.documentElement.classList.remove('dark') : document.documentElement.classList.add('dark'); + } + window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', setTheme); + setTheme(); })() `; return codeToRunOnClient; From 15aeff04be36657d4ec11e8f53114f8551cb69a6 Mon Sep 17 00:00:00 2001 From: Sam Henry Date: Tue, 25 Jan 2022 10:02:08 +1000 Subject: [PATCH 2/2] added auto switch on change to system theme if the user hasn't set chosen a theme this code will switch the dark/light mode based on changes to the system theme after first page load