From e58f2ba8c6ec65c49a753a1f0f665887a8dd1721 Mon Sep 17 00:00:00 2001 From: Theodore Brown Date: Wed, 18 Nov 2026 11:26:27 -0600 Subject: [PATCH 1/2] Update page theme when system color scheme changes When the theme is set to system, listen for changes to the prefers-color-scheme media query so the page switches between light and dark mode without requiring a reload. --- public/js/common.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/public/js/common.js b/public/js/common.js index 8219e4db2c..97f3e74e15 100644 --- a/public/js/common.js +++ b/public/js/common.js @@ -838,8 +838,8 @@ function getLanguage() { })(jQuery); const savedTheme = localStorage.theme || 'system'; -const prefersDark = matchMedia('(prefers-color-scheme: dark)').matches; -const isDark = savedTheme === 'dark' || (savedTheme === 'system' && prefersDark); +const darkSchemeQuery = matchMedia('(prefers-color-scheme: dark)'); +const isDark = savedTheme === 'dark' || (savedTheme === 'system' && darkSchemeQuery.matches); if (isDark) document.documentElement.classList.add('dark'); @@ -855,9 +855,15 @@ btn?.addEventListener('click', () => { applyTheme(newTheme); }); +darkSchemeQuery.addEventListener('change', () => { + const current = localStorage.theme || 'system'; + if (current === 'system') { + applyTheme(current); + } +}); + function applyTheme(theme) { - const prefersDark = matchMedia('(prefers-color-scheme: dark)').matches; - const isDark = theme === 'dark' || (theme === 'system' && prefersDark); + const isDark = theme === 'dark' || (theme === 'system' && darkSchemeQuery.matches); document.documentElement.classList.toggle('dark', isDark); From d3fbd6970c1e3f3168b40362906ece7eedfe8e94 Mon Sep 17 00:00:00 2001 From: Theodore Brown Date: Wed, 18 Nov 2026 11:34:06 -0600 Subject: [PATCH 2/2] Make theme toggle switch between system and opposite of system Instead of cycling between light, dark, and system, the theme button now switches to the opposite of the displayed theme. If the new theme matches the system theme, the setting is saved as system, so every click changes the theme and a saved light or dark setting is kept even if the system theme later changes to match it. --- public/js/common.js | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/public/js/common.js b/public/js/common.js index 97f3e74e15..d7d9ee6a57 100644 --- a/public/js/common.js +++ b/public/js/common.js @@ -837,30 +837,32 @@ function getLanguage() { }); })(jQuery); -const savedTheme = localStorage.theme || 'system'; const darkSchemeQuery = matchMedia('(prefers-color-scheme: dark)'); -const isDark = savedTheme === 'dark' || (savedTheme === 'system' && darkSchemeQuery.matches); -if (isDark) document.documentElement.classList.add('dark'); +function getSystemTheme() { + return darkSchemeQuery.matches ? 'dark' : 'light'; +} + +function getSavedTheme() { + return localStorage.theme || 'system'; +} -const themeOrder = ['light', 'dark', 'system']; +const themeIcons = ['light', 'dark', 'system']; const btn = document.querySelector('button.js-theme-switcher'); btn?.addEventListener('click', () => { - const current = localStorage.theme || 'system'; - const nextIndex = (themeOrder.indexOf(current) + 1) % themeOrder.length; - const newTheme = themeOrder[nextIndex]; + // Switch to the opposite of the displayed theme, using "system" + // when the new theme matches the system theme + const savedTheme = getSavedTheme(); + const displayedTheme = savedTheme === 'system' ? getSystemTheme() : savedTheme; + const oppositeTheme = displayedTheme === 'dark' ? 'light' : 'dark'; + const newTheme = oppositeTheme === getSystemTheme() ? 'system' : oppositeTheme; localStorage.theme = newTheme; applyTheme(newTheme); }); -darkSchemeQuery.addEventListener('change', () => { - const current = localStorage.theme || 'system'; - if (current === 'system') { - applyTheme(current); - } -}); +darkSchemeQuery.addEventListener('change', () => applyTheme(getSavedTheme())); function applyTheme(theme) { const isDark = theme === 'dark' || (theme === 'system' && darkSchemeQuery.matches); @@ -868,10 +870,10 @@ function applyTheme(theme) { document.documentElement.classList.toggle('dark', isDark); const icons = [btn?.querySelector('svg:nth-of-type(1)'), btn?.querySelector('svg:nth-of-type(2)'), btn?.querySelector('svg:nth-of-type(3)')]; - icons.forEach((icon, i) => icon?.classList.toggle('hidden', themeOrder[i] !== theme)); + icons.forEach((icon, i) => icon?.classList.toggle('hidden', themeIcons[i] !== theme)); } -applyTheme(savedTheme) +applyTheme(getSavedTheme()); const downloads = document.querySelector('.downloads'); downloads?.addEventListener('click', function (event) {