New Version - 1.0.1 — Set dark theme as default & fix eslint
This commit is contained in:
parent
b442ae90c9
commit
a8b843adb8
6 changed files with 113 additions and 52 deletions
|
@ -1,12 +1,16 @@
|
|||
// Toggle theme
|
||||
|
||||
const getTheme = localStorage.getItem('theme')
|
||||
const getTheme = window.localStorage && window.localStorage.getItem('theme')
|
||||
const themeToggle = document.querySelector('.theme-toggle')
|
||||
const isDark = getTheme === 'dark'
|
||||
const isDark = getTheme === 'dark' || getTheme === null
|
||||
|
||||
document.body.classList.toggle('dark-theme', isDark)
|
||||
|
||||
themeToggle.addEventListener('click', () => {
|
||||
document.body.classList.toggle('dark-theme')
|
||||
localStorage.setItem('theme', document.body.classList.contains('dark-theme') ? 'dark' : 'light')
|
||||
})
|
||||
window.localStorage &&
|
||||
window.localStorage.setItem(
|
||||
'theme',
|
||||
document.body.classList.contains('dark-theme') ? 'dark' : 'light',
|
||||
)
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue