Welcome to mirror list, hosted at ThFree Co, Russian Federation.

theme.js « js « source - github.com/rhazdon/hugo-theme-hello-friend-ng.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b30171fc6f97d25bfbf0aec8932ff3b905c05039 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Toggle theme

const getTheme = window.localStorage && window.localStorage.getItem('theme')
const themeToggle = document.querySelector('.theme-toggle')
const isDark = getTheme === 'dark' || getTheme === null

document.body.classList.toggle('dark-theme', isDark)

themeToggle.addEventListener('click', () => {
  document.body.classList.toggle('dark-theme')
  window.localStorage &&
    window.localStorage.setItem(
      'theme',
      document.body.classList.contains('dark-theme') ? 'dark' : 'light',
    )
})