| 1 |
const userPreferences = require( './userPreferences.js' ); |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
function isNightModeGadgetEnabled() { |
| 18 |
return mw.msg( 'vector-night-mode-gadget-names' ).split( '|' ).some( ( gadget ) => { |
| 19 |
const state = mw.loader.getState( `ext.gadget.${ gadget }` ); |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
return state !== null && state !== 'registered'; |
| 24 |
} ); |
| 25 |
} |
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
function disableNightModeForGadget() { |
| 31 |
document.documentElement.classList.remove( 'skin-theme-clientpref-night', 'skin-theme-clientpref-os' ); |
| 32 |
|
| 33 |
document.documentElement.classList.add( 'skin-theme-clientpref--excluded' ); |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
function alterDisableLink( container ) { |
| 44 |
const gadgetNames = mw.msg( 'vector-night-mode-gadget-names' ); |
| 45 |
const link = container.querySelector( 'a' ); |
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
if ( !gadgetNames || !link ) { |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
link.removeAttribute( 'title' ); |
| 54 |
link.removeAttribute( 'href' ); |
| 55 |
link.style.display = 'inline'; |
| 56 |
|
| 57 |
link.addEventListener( 'click', () => { |
| 58 |
|
| 59 |
const disableOptions = {}; |
| 60 |
|
| 61 |
gadgetNames.split( '|' ).forEach( ( gadgetName ) => { |
| 62 |
disableOptions[ `gadget-${ gadgetName }` ] = 0; |
| 63 |
} ); |
| 64 |
|
| 65 |
userPreferences.saveOptions( disableOptions ).then( () => { |
| 66 |
window.location.reload(); |
| 67 |
} ); |
| 68 |
} ); |
| 69 |
} |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
function removeBetaNotice() { |
| 75 |
const feedbackNoticeContainer = document.getElementById( 'skin-theme-beta-notice' ); |
| 76 |
if ( feedbackNoticeContainer ) { |
| 77 |
feedbackNoticeContainer.remove(); |
| 78 |
} |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
function alterExclusionMessage() { |
| 86 |
const noticeContainer = document.querySelector( '#skin-client-prefs-skin-theme .exclusion-notice' ); |
| 87 |
|
| 88 |
if ( !noticeContainer ) { |
| 89 |
return; |
| 90 |
} |
| 91 |
|
| 92 |
mw.loader.using( 'mediawiki.jqueryMsg' ).then( () => { |
| 93 |
|
| 94 |
noticeContainer.textContent = ''; |
| 95 |
|
| 96 |
mw.message( 'vector-night-mode-gadget-warning' ).parseDom().appendTo( noticeContainer ); |
| 97 |
|
| 98 |
alterDisableLink( noticeContainer ); |
| 99 |
} ); |
| 100 |
} |
| 101 |
|
| 102 |
module.exports = { |
| 103 |
isNightModeGadgetEnabled, |
| 104 |
disableNightModeForGadget, |
| 105 |
alterDisableLink, |
| 106 |
alterExclusionMessage, |
| 107 |
removeBetaNotice |
| 108 |
}; |