mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-18 03:41:50 +00:00
54 lines
1 KiB
JavaScript
54 lines
1 KiB
JavaScript
/*
|
|
* Citizen - Theme Switcher JS
|
|
* https://starcitizen.tools
|
|
*/
|
|
|
|
( function () {
|
|
var prefersColorSchemeDarkQuery,
|
|
userTheme,
|
|
theme;
|
|
|
|
if ( typeof window.mw === 'undefined' ) {
|
|
return;
|
|
}
|
|
|
|
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' ) {
|
|
return;
|
|
}
|
|
try {
|
|
if ( window.mw.cookie.get( 'skin-citizen-theme-override' ) === '1' ) {
|
|
return;
|
|
}
|
|
} catch ( e ) {}
|
|
|
|
prefersColorSchemeDarkQuery = window.matchMedia( '(prefers-color-scheme: dark)' );
|
|
if ( prefersColorSchemeDarkQuery.matches ) {
|
|
theme = 'dark';
|
|
}
|
|
|
|
prefersColorSchemeDarkQuery.addEventListener( 'change', function ( e ) {
|
|
if ( e.matches ) {
|
|
theme = 'dark';
|
|
} else {
|
|
theme = 'light';
|
|
}
|
|
} );
|
|
|
|
try {
|
|
window.mw.cookie.set( 'skin-citizen-theme', null );
|
|
window.mw.cookie.set( 'skin-citizen-theme', theme );
|
|
} catch ( e ) {
|
|
}
|
|
}() );
|