2021-04-27 16:57:54 +00:00
|
|
|
/*
|
2022-04-26 00:29:29 +00:00
|
|
|
* Citizen
|
2021-04-27 16:57:54 +00:00
|
|
|
*
|
2023-01-21 01:18:58 +00:00
|
|
|
* Inline script used in includes/Hooks/SkinHooks.php
|
2021-04-27 16:57:54 +00:00
|
|
|
*/
|
2024-04-25 00:23:45 +00:00
|
|
|
const LEGACY_PREFIX = 'skin-citizen-';
|
2022-04-26 00:29:29 +00:00
|
|
|
|
2024-04-25 00:23:45 +00:00
|
|
|
/**
|
|
|
|
* Backported from MW 1.42
|
|
|
|
* Modified to use localStorage only
|
|
|
|
*/
|
|
|
|
window.clientPrefs = () => {
|
|
|
|
let className = document.documentElement.className;
|
|
|
|
const storage = localStorage.getItem( 'mwclientpreferences' );
|
|
|
|
if ( storage ) {
|
|
|
|
// TODO: Just use array for localStorage
|
2024-04-25 19:59:07 +00:00
|
|
|
storage.split( ',' ).forEach( function ( pref ) {
|
2024-04-25 00:23:45 +00:00
|
|
|
className = className.replace(
|
|
|
|
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
|
|
new RegExp( '(^| )' + pref.replace( /-clientpref-\w+$|[^\w-]+/g, '' ) + '-clientpref-\\w+( |$)' ),
|
|
|
|
'$1' + pref + '$2'
|
|
|
|
);
|
|
|
|
|
|
|
|
// Legacy support
|
|
|
|
if ( pref.startsWith( 'skin-theme-clientpref-' ) ) {
|
|
|
|
const CLIENTPREFS_THEME_MAP = {
|
|
|
|
os: 'auto',
|
|
|
|
day: 'light',
|
|
|
|
night: 'dark'
|
|
|
|
};
|
|
|
|
const matchedKey = CLIENTPREFS_THEME_MAP[ pref.replace( 'skin-theme-clientpref-', '' ) ];
|
|
|
|
if ( matchedKey ) {
|
|
|
|
// eslint-disable-next-line max-len, es-x/no-object-values
|
|
|
|
const classesToRemove = Object.values( CLIENTPREFS_THEME_MAP ).map( ( theme ) => LEGACY_PREFIX + theme );
|
|
|
|
className = className.replace(
|
|
|
|
// eslint-disable-next-line security/detect-non-literal-regexp
|
|
|
|
new RegExp( classesToRemove.join( '|' ), 'g' ),
|
|
|
|
''
|
|
|
|
);
|
|
|
|
className += ` ${ LEGACY_PREFIX }${ matchedKey }`;
|
|
|
|
}
|
|
|
|
}
|
2022-05-20 21:33:10 +00:00
|
|
|
} );
|
2024-04-25 00:23:45 +00:00
|
|
|
document.documentElement.className = className;
|
2022-04-19 22:17:53 +00:00
|
|
|
}
|
2022-05-20 21:33:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
( () => {
|
2024-04-25 00:23:45 +00:00
|
|
|
window.clientPrefs();
|
2022-04-26 00:29:29 +00:00
|
|
|
} )();
|