|
|
| Line 1: |
Line 1: |
| (function () {
| |
| function currentTheme() {
| |
| var h = document.documentElement;
| |
| if (h.classList.contains('theme-dark')) { return 'dark'; }
| |
| if (h.classList.contains('theme-light')) { return 'light'; }
| |
| return ( window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ) ? 'dark' : 'light';
| |
| }
| |
|
| |
|
| function applyTheme(t) {
| |
| var h = document.documentElement;
| |
| h.classList.remove('theme-dark', 'theme-light');
| |
| h.classList.add('theme-' + t);
| |
| try { localStorage.setItem('mb-theme', t); } catch (e) {}
| |
| }
| |
|
| |
| mw.loader.using('mediawiki.util').then(function () {
| |
| var link = mw.util.addPortletLink(
| |
| 'p-personal', '#', 'Theme', 'pt-theme', 'Switch between light and dark theme'
| |
| );
| |
| if (!link) { return; }
| |
| link.addEventListener('click', function (e) {
| |
| e.preventDefault();
| |
| applyTheme(currentTheme() === 'dark' ? 'light' : 'dark');
| |
| });
| |
| });
| |
| }());
| |