summaryrefslogtreecommitdiff
path: root/public/js/theme.js
blob: be2a9d143575c754a463607842f749a91bfebc34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const key = 'current_emily_zola_style';

function getTheme() {
  let theme = document.getElementById('stylesheet');
  let current_style = localStorage.getItem(key);
  if (current_style === null) {
    localStorage.setItem(key, theme.href);
  }
  theme.href = localStorage.getItem(key);
}

function changeTheme() {
  let current_style = localStorage.getItem(key);
  if (current_style.includes('dark')) {
    localStorage.setItem(key, '/light.css');
  }
  else {
    localStorage.setItem(key, '/dark.css');
  }
  let theme = document.getElementById('stylesheet');
  theme.href = localStorage.getItem(key);
}