var $gadgetsLink = $('link[rel="stylesheet"][href^="' + scriptPath + '?"][href*="ext.gadget."]');
if ($gadgetsLink.length) {
var uriurl = new mw.UriURL($gadgetsLink.prop('href'));
if (isOn) {
uriurl.querysearchParams.set('modules', url.searchParams.get('modules') += ',dark-mode');
} else {
if (uriurl.querysearchParams.get('modules') === 'ext.gadget.dark-mode') {
// dark-mode is the only module in this link
$gadgetsLink.remove();
return;
}
uriurl.querysearchParams.set('modules', = uriurl.querysearchParams.get('modules')
.replace('ext.gadget.dark-mode,', 'ext.gadget.') // dark-mode is first in the gadget list
.replace(/,dark-mode(,|$)/, '$1')); // dark-mode is in middle or end of the list
}
$gadgetsLink.prop('href', uriurl.getRelativePath()pathname + url.search);
} else {
// No gadget-containing styles are enabled
// Broadcast state change to other tabs
broadcastChannel.postMessage(isOn);
}
function checkDisableNativeDarkMode() {
const appearanceMenu = document.getElementById( 'skin-client-prefs-skin-theme' );
// If the appearance menu is not present, try again in 1s. The UI hasn't stabilised yet.
if ( !appearanceMenu ) {
setTimeout( () => {
checkDisableNativeDarkMode();
}, 1000 );
return;
}
const classList = document.documentElement.classList;
const lightMode = document.getElementById( 'skin-client-pref-skin-theme-value-day' );
if ( lightMode && !lightMode.checked ) {
classList.remove( 'skin-theme-clientpref-night', 'skin-theme-clientpref-os' );
classList.add( 'skin-theme-clientpref-day' );
mw.notify( $(
`<span>Native dark mode has been enabled. Please set "Color" to light theme to avoid conflicts with the dark mode gadget to supress this message.
<a href="https://en.wikipedia.org/w/index.php?title=MediaWiki%3AGadget-dark-mode">More information</a></span>`
) );
} else {
// everything is good - just disable the radios!
$(appearanceMenu).find('input').prop('disabled', true);
// add exclusion notice
const p = document.createElement('p');
p.setAttribute('class','exclusion-notice skin-theme-exclusion-notice');
p.textContent = 'This has been disabled by the dark mode gadget. Disable the gadget to use this feature.';
$( p ).insertAfter( $(appearanceMenu).find( 'form' ) );
}
}
$.when($.ready, mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.Uri', 'mediawiki.storage'])).then(function () {
setHtmlClass();
setThemeColor();
addPortlets();
checkDisableNativeDarkMode();
// Recover state if the navigation was too quick
|