feat: support auto theme mode (#212)

Co-authored-by: Mave <11227996+Ma-ve@users.noreply.github.com>
Co-authored-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Wesley 2025-05-01 00:08:32 +02:00 committed by GitHub
parent 45184a496e
commit e7d1efc505
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 77 additions and 23 deletions

View file

@ -31,7 +31,17 @@
<title>{{ .Customize.AppTitle }}</title>
<script nonce="{{ .InlineContentNonce }}">
window.getTheme = () => localStorage.getItem('set-color-scheme') || (window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark')
window.getThemeFromStorage = () => localStorage.getItem('set-color-scheme') || 'auto'
window.getTheme = () => {
const colorScheme = window.getThemeFromStorage()
if (!colorScheme || colorScheme === 'auto') {
return window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark'
}
return colorScheme
}
window.refreshTheme = () => {
document.querySelector('html').setAttribute('data-bs-theme', window.getTheme())