mirror of
https://github.com/thomasjsn/hugo-theme-hello-friend.git
synced 2024-11-14 20:35:07 +01:00
12 lines
408 B
JavaScript
12 lines
408 B
JavaScript
// Toggle theme
|
|
|
|
const getTheme = localStorage.getItem('theme')
|
|
const themeToggle = document.querySelector('.theme-toggle')
|
|
const isDark = getTheme === 'dark'
|
|
|
|
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')
|
|
}) |