| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
function reportDisabled() { |
| 6 |
mw.notify( mw.msg( 'skin-minerva-night-mode-unavailable' ) ); |
| 7 |
return true; |
| 8 |
} |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
function reportIfNightModeWasDisabledOnPage( doc ) { |
| 16 |
if ( !doc.classList.contains( 'skin-night-mode-page-disabled' ) ) { |
| 17 |
return false; |
| 18 |
} |
| 19 |
|
| 20 |
let userExpectedNightMode = `${ mw.user.options.get( 'minerva-theme' ) }`; |
| 21 |
if ( !mw.user.isNamed() ) { |
| 22 |
|
| 23 |
|
| 24 |
const cookieValue = mw.cookie.get( 'mwclientpreferences' ) || ''; |
| 25 |
const match = cookieValue.match( /skin-theme-clientpref-(\S+)/ ); |
| 26 |
if ( match ) { |
| 27 |
|
| 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; |