mediawiki-skins-MinervaNeue/resources/skins.minerva.scripts/reportIfNightModeWasDisabledOnPage.js
Ed Sanders 2be7b9f919 build: Update jsdoc-wmf-theme to 1.1.0
Additional changes:
* Update Minerva so that it doesn't output any APIs
to the documentation - this is intentional as Minerva does
not have any public facing APIs.

Bug: T368081
Change-Id: Ie1a3ea30cbf35663c7fdd2494c1698044882969e
2024-06-28 12:38:54 -07:00

41 lines
1.2 KiB
JavaScript

/**
* @private
* @return {boolean}
*/
function reportDisabled() {
mw.notify( mw.msg( 'skin-minerva-night-mode-unavailable' ) );
return true;
}
/**
* @ignore
* @param {Document} doc
* @return {boolean} whether it was reported as disabled.
*/
function reportIfNightModeWasDisabledOnPage( doc ) {
if ( !doc.classList.contains( 'skin-night-mode-page-disabled' ) ) {
return false;
}
// Cast to string.
let userExpectedNightMode = `${ mw.user.options.get( 'minerva-theme' ) }`;
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' ) || '';
const match = cookieValue.match( /skin-theme-clientpref-(\S+)/ );
if ( match ) {
// we found something in the cookie.
userExpectedNightMode = match[ 1 ];
}
}
if ( userExpectedNightMode === 'night' ) {
return reportDisabled();
} else if ( userExpectedNightMode === 'os' && matchMedia( '( prefers-color-scheme: dark )' ).matches ) {
return reportDisabled();
} else {
return false;
}
}
module.exports = reportIfNightModeWasDisabledOnPage;