From 3c003e2a32fe1aaf3626e2cbaf47bf3c613ffcec Mon Sep 17 00:00:00 2001 From: Tobias Berg Date: Thu, 12 Feb 2026 17:14:39 +0100 Subject: [PATCH] set theme in docs based on browser preference --- docs/index.html | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/docs/index.html b/docs/index.html index e8931ea..5b0ffef 100644 --- a/docs/index.html +++ b/docs/index.html @@ -1053,12 +1053,17 @@ const icon = document.getElementById('theme-icon'); icon.textContent = newTheme === 'light' ? '🌙' : '☀️'; } + + function getBrowserThemePreference() { + const prefersDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches; + return prefersDarkMode ? 'dark' : 'light'; + } // Load saved theme on page load (function() { - const savedTheme = localStorage.getItem('theme') || 'light'; + const savedTheme = localStorage.getItem('theme') || getBrowserThemePreference(); document.documentElement.setAttribute('data-theme', savedTheme); - + // Update icon const icon = document.getElementById('theme-icon'); icon.textContent = savedTheme === 'light' ? '🌙' : '☀️';