2021-01-09 21:58:43 +00:00
|
|
|
/*
|
|
|
|
* Citizen - Theme Switcher JS
|
|
|
|
* https://starcitizen.tools
|
|
|
|
*/
|
|
|
|
|
2021-01-09 22:12:17 +00:00
|
|
|
( function () {
|
|
|
|
var isGlobalAutoSet,
|
|
|
|
isUserPreferenceAuto,
|
|
|
|
enable,
|
|
|
|
switchColorScheme,
|
|
|
|
useDarkTheme,
|
|
|
|
prefersColorSchemeDarkQuery;
|
|
|
|
|
|
|
|
if ( typeof window.mw === 'undefined' ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
isGlobalAutoSet = window.mw.config.get( 'wgCitizenColorScheme' ) === 'auto' ||
|
|
|
|
window.mw.config.get( 'wgCitizenColorScheme' ) === null;
|
|
|
|
|
|
|
|
isUserPreferenceAuto = window.mw.user.options.get( 'citizen-color-scheme' ) === 'auto';
|
|
|
|
|
|
|
|
enable = isGlobalAutoSet || isUserPreferenceAuto;
|
|
|
|
|
|
|
|
if ( !enable ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
switchColorScheme = function ( useDark ) {
|
|
|
|
var dark;
|
|
|
|
|
|
|
|
if ( useDark ) {
|
|
|
|
document.documentElement.classList.add( 'skin-citizen-dark' );
|
|
|
|
document.documentElement.classList.remove( 'skin-citizen-light' );
|
|
|
|
dark = true;
|
|
|
|
} else {
|
|
|
|
document.documentElement.classList.add( 'skin-citizen-light' );
|
|
|
|
document.documentElement.classList.remove( 'skin-citizen-dark' );
|
|
|
|
dark = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
localStorage.setItem( 'skin-citizen-dark', dark );
|
|
|
|
} catch ( e ) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
try {
|
|
|
|
useDarkTheme = localStorage.getItem( 'skin-citizen-dark' );
|
|
|
|
} catch ( e ) {}
|
|
|
|
|
|
|
|
prefersColorSchemeDarkQuery = window.matchMedia( '(prefers-color-scheme: dark)' );
|
|
|
|
|
|
|
|
if ( useDarkTheme || prefersColorSchemeDarkQuery.matches ) {
|
|
|
|
switchColorScheme( true );
|
|
|
|
}
|
|
|
|
}() );
|