mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-18 03:41:50 +00:00
59 lines
1.1 KiB
JavaScript
59 lines
1.1 KiB
JavaScript
/*
|
|
* Citizen - Theme Switcher JS
|
|
* https://starcitizen.tools
|
|
*/
|
|
|
|
( function () {
|
|
var prefersColorSchemeDarkQuery,
|
|
userTheme,
|
|
theme,
|
|
setStorageChangeTheme;
|
|
|
|
setStorageChangeTheme = function ( themeName ) {
|
|
try {
|
|
window.localStorage.setItem( 'skin-citizen-theme', themeName );
|
|
} catch ( e ) {
|
|
}
|
|
|
|
window.switchTheme();
|
|
};
|
|
|
|
if ( typeof window.mw === 'undefined' ) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
if ( window.mw.cookie.get( 'skin-citizen-theme-override' ) === '1' ) {
|
|
return;
|
|
}
|
|
} catch ( e ) {}
|
|
|
|
theme = window.mw.config.get( 'wgCitizenThemeDefault' );
|
|
if ( theme === null ) {
|
|
theme = 'auto';
|
|
}
|
|
|
|
userTheme = window.mw.user.options.get( 'CitizenThemeUser' );
|
|
|
|
if ( userTheme !== null ) {
|
|
theme = userTheme;
|
|
}
|
|
|
|
if ( theme !== 'auto' ) {
|
|
setStorageChangeTheme( theme );
|
|
return;
|
|
}
|
|
|
|
prefersColorSchemeDarkQuery = window.matchMedia( '(prefers-color-scheme: dark)' );
|
|
theme = 'light';
|
|
if ( prefersColorSchemeDarkQuery.matches ) {
|
|
theme = 'dark';
|
|
}
|
|
|
|
setStorageChangeTheme( theme );
|
|
|
|
prefersColorSchemeDarkQuery.addEventListener( 'change', function ( e ) {
|
|
setStorageChangeTheme( e.matches ? 'dark' : 'light' );
|
|
} );
|
|
}() );
|