-
-
Notifications
You must be signed in to change notification settings - Fork 378
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
- Loading branch information
1 parent
7405b99
commit 35b9a7e
Showing
1 changed file
with
27 additions
and
27 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,34 +1,34 @@ | ||
(function () { | ||
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)') | ||
let initialTheme | ||
if (localStorage.getItem('darkmode-pref-set') === 'true') { | ||
initialTheme = localStorage.getItem('darkMode') === 'true' | ||
} else { | ||
initialTheme = darkModeMediaQuery.matches | ||
} | ||
const darkModeMediaQuery = window.matchMedia('(prefers-color-scheme: dark)') | ||
let initialTheme | ||
if (localStorage.getItem('darkmode-pref-set') === 'true') { | ||
initialTheme = localStorage.getItem('darkMode') === 'true' | ||
} else { | ||
initialTheme = darkModeMediaQuery.matches | ||
} | ||
|
||
function updateToggle (darkMode) { | ||
document.querySelector(".theme-toggle input[type=radio][value='dark']").checked = darkMode | ||
document.querySelector(".theme-toggle input[type=radio][value='light']").checked = !darkMode | ||
function updateToggle (darkMode) { | ||
document.querySelector(".theme-toggle input[type=radio][value='dark']").checked = darkMode | ||
document.querySelector(".theme-toggle input[type=radio][value='light']").checked = !darkMode | ||
|
||
document.body.classList.toggle('dark-mode', darkMode) | ||
localStorage.setItem('darkMode', darkMode) | ||
localStorage.setItem('darkmode-pref-set', 'true') | ||
} | ||
document.body.classList.toggle('dark-mode', darkMode) | ||
localStorage.setItem('darkMode', darkMode) | ||
localStorage.setItem('darkmode-pref-set', 'true') | ||
} | ||
|
||
darkModeMediaQuery.addEventListener('change', (e) => { | ||
const darkModeOn = e.matches | ||
updateToggle(darkModeOn) | ||
}) | ||
|
||
window.addEventListener('load', function () { | ||
const radios = document.querySelectorAll('.theme-toggle input[type=radio]') | ||
radios.forEach((radio) => { | ||
radio.addEventListener('change', function (e) { | ||
updateToggle(e.target.value === 'dark') | ||
}) | ||
}) | ||
darkModeMediaQuery.addEventListener('change', (e) => { | ||
const darkModeOn = e.matches | ||
updateToggle(darkModeOn) | ||
}) | ||
|
||
updateToggle(initialTheme) | ||
window.addEventListener('load', function () { | ||
const radios = document.querySelectorAll('.theme-toggle input[type=radio]') | ||
radios.forEach((radio) => { | ||
radio.addEventListener('change', function (e) { | ||
updateToggle(e.target.value === 'dark') | ||
}) | ||
}) | ||
|
||
updateToggle(initialTheme) | ||
}) | ||
})() |