-
-
Notifications
You must be signed in to change notification settings - Fork 389
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[pre-commit.ci lite] apply automatic fixes
1 parent
23ad4a1
commit 4263652
Showing
1 changed file
with
32 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
(function () { | ||
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)'); | ||
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)') | ||
|
||
function updateToggle(darkMode) { | ||
const checkbox = document.querySelector(".theme-toggle input[type='checkbox']"); | ||
if (checkbox) { | ||
checkbox.checked = darkMode; | ||
} | ||
|
||
document.body.classList.toggle('dark-mode', darkMode); | ||
localStorage.setItem('darkMode', darkMode); | ||
localStorage.setItem('darkmode-pref-set', 'true'); | ||
function updateToggle (darkMode) { | ||
const checkbox = document.querySelector(".theme-toggle input[type='checkbox']") | ||
if (checkbox) { | ||
checkbox.checked = darkMode | ||
} | ||
|
||
// Listen for system theme changes | ||
darkModeMediaQuery.addEventListener('change', (e) => { | ||
updateToggle(e.matches); | ||
}); | ||
document.body.classList.toggle('dark-mode', darkMode) | ||
localStorage.setItem('darkMode', darkMode) | ||
localStorage.setItem('darkmode-pref-set', 'true') | ||
} | ||
|
||
// Listen for system theme changes | ||
darkModeMediaQuery.addEventListener('change', (e) => { | ||
updateToggle(e.matches) | ||
}) | ||
|
||
// Set up event listener and initial theme on page load | ||
window.addEventListener('load', function () { | ||
const checkbox = document.querySelector(".theme-toggle input[type='checkbox']"); | ||
if (checkbox) { | ||
checkbox.addEventListener('change', function () { | ||
updateToggle(checkbox.checked); | ||
}); | ||
// Set up event listener and initial theme on page load | ||
window.addEventListener('load', function () { | ||
const checkbox = document.querySelector(".theme-toggle input[type='checkbox']") | ||
if (checkbox) { | ||
checkbox.addEventListener('change', function () { | ||
updateToggle(checkbox.checked) | ||
}) | ||
|
||
// Initialize theme based on user preference or system preference | ||
let initialTheme; | ||
if (localStorage.getItem('darkmode-pref-set') === 'true') { | ||
initialTheme = localStorage.getItem('darkMode') === 'true'; | ||
} else { | ||
initialTheme = darkModeMediaQuery.matches; | ||
} | ||
updateToggle(initialTheme); | ||
} | ||
}); | ||
})(); | ||
// Initialize theme based on user preference or system preference | ||
let initialTheme | ||
if (localStorage.getItem('darkmode-pref-set') === 'true') { | ||
initialTheme = localStorage.getItem('darkMode') === 'true' | ||
} else { | ||
initialTheme = darkModeMediaQuery.matches | ||
} | ||
updateToggle(initialTheme) | ||
} | ||
}) | ||
})() |