Debian Codegraph @

skins/MinervaNeue/resources/skins.minerva.scripts/reportIfNightModeWasDisabledOnPage.js

raw symbols SCIP
1 /**
2 * @private
3 * @return {boolean}
4 */
5 function reportDisabled() {
6 mw.notify( mw.msg( 'skin-minerva-night-mode-unavailable' ) );
7 return true;
8 }
9
10 /**
11 * @ignore
12 * @param {Document} doc
13 * @return {boolean} whether it was reported as disabled.
14 */
15 function reportIfNightModeWasDisabledOnPage( doc ) {
16 if ( !doc.classList.contains( 'skin-night-mode-page-disabled' ) ) {
17 return false;
18 }
19 // Cast to string.
20 let userExpectedNightMode = `${ mw.user.options.get( 'minerva-theme' ) }`;
21 if ( !mw.user.isNamed() ) {
22 // bit more convoulated here and will break with upstream changes...
23 // this is protected by an integration test in integration.test.js
24 const cookieValue = mw.cookie.get( 'mwclientpreferences' ) || '';
25 const match = cookieValue.match( /skin-theme-clientpref-(\S+)/ );
26 if ( match ) {
27 // we found something in the cookie.
28 userExpectedNightMode = match[ 1 ];
29 }
30 }
31 if ( userExpectedNightMode === 'night' ) {
32 return reportDisabled();
33 } else if ( userExpectedNightMode === 'os' && matchMedia( '( prefers-color-scheme: dark )' ).matches ) {
34 return reportDisabled();
35 } else {
36 return false;
37 }
38 }
39
40 module.exports = reportIfNightModeWasDisabledOnPage;