New Version - 1.0.1 — Set dark theme as default & fix eslint

This commit is contained in:
panr 2018-08-24 09:37:55 +02:00
parent b442ae90c9
commit a8b843adb8
6 changed files with 113 additions and 52 deletions

View file

@ -51,6 +51,7 @@
height: 24px;
fill: currentColor;
margin-left: 10px;
cursor: pointer;
}
a {
@ -66,4 +67,4 @@
margin-right: 0;
}
}
}
}

View file

@ -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',
)
})