2021-01-16 22:01:58 +00:00
|
|
|
function init() {
|
2021-04-05 18:24:18 +00:00
|
|
|
var theme = window.localStorage.getItem( 'skin-citizen-theme' );
|
2021-01-16 22:01:58 +00:00
|
|
|
var toggleBtn = document.getElementById( 'theme-toggle' );
|
|
|
|
|
|
|
|
toggleBtn.addEventListener( 'click', function ( clickEvent ) {
|
2021-04-05 18:24:18 +00:00
|
|
|
theme = window.localStorage.getItem( 'skin-citizen-theme' );
|
2021-01-31 17:38:37 +00:00
|
|
|
|
2021-01-16 22:01:58 +00:00
|
|
|
try {
|
|
|
|
theme = theme === 'dark' ? 'light' : 'dark';
|
|
|
|
|
2021-01-31 17:38:37 +00:00
|
|
|
clickEvent.target.classList.remove( 'theme-toggle-light', 'theme-toggle-dark', 'theme-toggle-auto' );
|
2021-01-16 22:01:58 +00:00
|
|
|
// * theme-toggle-light
|
|
|
|
// * theme-toggle-dark
|
|
|
|
clickEvent.target.classList.add( 'theme-toggle-' + theme );
|
|
|
|
|
|
|
|
try {
|
2021-04-05 18:24:18 +00:00
|
|
|
window.localStorage.setItem( 'skin-citizen-theme', theme );
|
2021-01-16 22:01:58 +00:00
|
|
|
window.mw.cookie.set( 'skin-citizen-theme-override', '1' );
|
|
|
|
} catch ( e ) {
|
|
|
|
}
|
|
|
|
|
|
|
|
window.switchTheme();
|
|
|
|
} catch ( e ) {
|
|
|
|
}
|
|
|
|
} );
|
2021-01-31 17:38:37 +00:00
|
|
|
|
|
|
|
if ( theme !== 'auto' ) {
|
|
|
|
// * theme-toggle-light
|
|
|
|
// * theme-toggle-dark
|
|
|
|
toggleBtn.classList.add( 'theme-toggle-' + theme );
|
|
|
|
}
|
2021-01-16 22:01:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init: init
|
|
|
|
};
|