]>
Commit | Line | Data |
---|---|---|
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 | } | |
6 | if(q('html').className == name) | |
7 | return; | |
8 | q('html').className = name; | |
9 | localStorage.setItem("theme", name); | |
10 | $(function() { | |
11 | if(name == 'slate' || name == 'cyborg') | |
12 | $('img').each(e => e.setAttribute('src', e.getAttribute('src').replace('logos/light', 'logos/dark'))); | |
13 | else | |
14 | $('img').each(e => e.setAttribute('src', e.getAttribute('src').replace('logos/dark', 'logos/light'))); | |
15 | }); | |
16 | } | |
17 | ||
18 | $(function() { | |
19 | const theme_ul = '<ul class="list-inline" id="themes">' + | |
20 | '<li><a role="button" data-theme="cyborg">Black</a>' + | |
21 | '<li><a role="button" data-theme="slate">Grey</a>' + | |
22 | '<li><a role="button" data-theme="readable">White</a></ul>'; | |
23 | const sidebar = q('#sidebar'); | |
24 | sidebar.insertBefore(m(theme_ul), sidebar.firstChild); | |
25 | $('#themes a').on('click', e => set_style(e.target.dataset.theme, true)); | |
26 | }); | |
27 | ||
28 | const theme = localStorage.getItem("theme"); | |
29 | if(theme) | |
30 | set_style(theme == "cerulean" || theme == "cosmo" ? "readable" : theme, false); |