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