mirror of
https://github.com/iptv-org/iptv-org.github.io.git
synced 2025-05-11 17:40:05 -04:00
Fixes dark mode toggle
https://github.com/iptv-org/iptv-org.github.io/pull/1550
This commit is contained in:
parent
e7dfebdd1a
commit
4477d214a9
2 changed files with 15 additions and 8 deletions
|
@ -4,8 +4,11 @@
|
|||
|
||||
let dark = false
|
||||
function toggleDarkMode() {
|
||||
let mode = localStorage.theme || 'light'
|
||||
if (mode === 'dark' || window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
const prefersColorScheme = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
? 'dark'
|
||||
: 'light'
|
||||
const mode = localStorage.theme || prefersColorScheme
|
||||
if (mode === 'dark') {
|
||||
dark = false
|
||||
document.documentElement.classList.remove('dark')
|
||||
localStorage.theme = 'light'
|
||||
|
@ -17,8 +20,11 @@
|
|||
}
|
||||
|
||||
onMount(() => {
|
||||
let mode = localStorage.theme || 'light'
|
||||
if (mode === 'dark' || window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
const prefersColorScheme = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
? 'dark'
|
||||
: 'light'
|
||||
const mode = localStorage.theme || prefersColorScheme
|
||||
if (mode === 'dark') {
|
||||
dark = true
|
||||
} else {
|
||||
dark = false
|
||||
|
|
|
@ -5,13 +5,14 @@
|
|||
<svelte:head>
|
||||
<script>
|
||||
if (document) {
|
||||
let mode = localStorage.theme || 'light'
|
||||
if (mode === 'dark' || window.matchMedia('(prefers-color-scheme: dark)').matches) {
|
||||
const prefersColorScheme = window.matchMedia('(prefers-color-scheme: dark)').matches
|
||||
? 'dark'
|
||||
: 'light'
|
||||
const mode = localStorage.theme || prefersColorScheme
|
||||
if (mode === 'dark') {
|
||||
document.documentElement.classList.add('dark')
|
||||
localStorage.theme = 'dark'
|
||||
} else {
|
||||
document.documentElement.classList.remove('dark')
|
||||
localStorage.theme = 'light'
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue