mediawiki-skins-Citizen/resources/skins.citizen.scripts.theme/inline.js
alistair3149 abffe590b5
refactor: remove cookie theme for local storage
Co-authored-by: H. C. Kruse <6594492+octfx@users.noreply.github.com>
Co-authored-by: github-actions <github-actions@users.noreply.github.com>
2021-04-05 14:24:18 -04:00

37 lines
924 B
JavaScript

/* eslint-disable */
/*
* Citizen - Inline script used in SkinCitizen.php
*
* https://starcitizen.tools
*
* Mangle using https://jscompress.com/
*/
window.switchTheme = () => {
// Generates an array of prefix-(auto|dark|light) strings
const classNames = (prefix) => {
return ['auto', 'dark', 'light'].map(themeType => {
return prefix + themeType;
});
}
const themeToggle = document.getElementById('theme-toggle');
try {
const theme = window.localStorage.getItem('skin-citizen-theme');
if (theme !== null) {
// First remove all theme classes
document.documentElement.classList.remove(...classNames('skin-citizen-'));
// Then add the right one
document.documentElement.classList.add('skin-citizen-' + theme);
themeToggle.classList.remove(...classNames('theme-toggle'))
themeToggle.classList.add('theme-toggle-' + theme);
}
} catch (e) {
}
}
(() => {
window.switchTheme()
})();