2024-02-08 22:52:46 +00:00
|
|
|
/**
|
|
|
|
* @return {boolean}
|
|
|
|
*/
|
|
|
|
function reportDisabled() {
|
|
|
|
mw.notify( mw.msg( 'skin-minerva-night-mode-unavailable' ) );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {Document} doc
|
|
|
|
* @return {boolean} whether it was reported as disabled.
|
|
|
|
* @ignore
|
|
|
|
*/
|
|
|
|
function reportIfNightModeWasDisabledOnPage( doc ) {
|
|
|
|
if ( !doc.classList.contains( 'skin-night-mode-page-disabled' ) ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Cast to string.
|
2024-03-18 19:14:23 +00:00
|
|
|
let userExpectedNightMode = `${ mw.user.options.get( 'minerva-theme' ) }`;
|
2024-02-08 22:52:46 +00:00
|
|
|
if ( !mw.user.isNamed() ) {
|
|
|
|
// bit more convoulated here and will break with upstream changes...
|
|
|
|
// this is protected by an integration test in integration.test.js
|
|
|
|
const cookieValue = mw.cookie.get( 'mwclientpreferences' ) || '';
|
2024-03-18 19:14:23 +00:00
|
|
|
const match = cookieValue.match( /skin-theme-clientpref-(\S+)/ );
|
2024-02-08 22:52:46 +00:00
|
|
|
if ( match ) {
|
|
|
|
// we found something in the cookie.
|
|
|
|
userExpectedNightMode = match[ 1 ];
|
|
|
|
}
|
|
|
|
}
|
2024-03-18 19:14:23 +00:00
|
|
|
if ( userExpectedNightMode === 'night' ) {
|
2024-02-08 22:52:46 +00:00
|
|
|
return reportDisabled();
|
2024-03-18 19:14:23 +00:00
|
|
|
} else if ( userExpectedNightMode === 'os' && matchMedia( '( prefers-color-scheme: dark )' ).matches ) {
|
2024-02-08 22:52:46 +00:00
|
|
|
return reportDisabled();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = reportIfNightModeWasDisabledOnPage;
|