mirror of
https://github.com/Luzifer/ots.git
synced 2025-08-02 11:16:25 -04:00
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:
parent
45184a496e
commit
e7d1efc505
6 changed files with 77 additions and 23 deletions
|
@ -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())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue