]>
Commit | Line | Data |
---|---|---|
74da6b38 MG |
1 | function set_style(name, trans){ |
2 | if(trans){ | |
3 | document.body.classList.add('transition-color'); | |
4 | setTimeout(() => document.body.classList.remove('transition-color'), 1000); | |
5 | } | |
931541d7 MG |
6 | if(q('html').className == name) |
7 | return; | |
db73dc0c | 8 | q('html').className = name; |
7093e9ba MG |
9 | localStorage.setItem("theme", name); |
10 | } | |
7dc32473 | 11 | |
7093e9ba | 12 | $(function() { |
65d5cb3b | 13 | const theme_ul = '<ul class="list-inline" id="themes">' + |
81c2ef98 MG |
14 | '<li><a role="button" data-theme="cyborg">Black</a>' + |
15 | '<li><a role="button" data-theme="slate">Grey</a>' + | |
16 | '<li><a role="button" data-theme="readable">White</a></ul>'; | |
dee46c5b | 17 | const sidebar = q('#sidebar'); |
81c2ef98 | 18 | sidebar.insertBefore(m(theme_ul), sidebar.firstChild); |
74da6b38 | 19 | $('#themes a').on('click', e => set_style(e.target.dataset.theme, true)); |
7093e9ba | 20 | }); |
7dc32473 | 21 | |
65d5cb3b MG |
22 | const theme = localStorage.getItem("theme"); |
23 | if(theme) | |
24 | set_style(theme == "cerulean" || theme == "cosmo" ? "readable" : theme, false); |