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