MediaWiki:Gadget-dark-mode-toggle.js: Difference between revisions

Content deleted Content added
As discussed on Discord, the new beta feature dark mode is conflicting with this gadget so for now handle this in the gadget until phab:T365083
Tag: Reverted
Remove mw.uri
 
(8 intermediate revisions by 4 users not shown)
Line 84:
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
Line 122:
// Broadcast state change to other tabs
broadcastChannel.postMessage(isOn);
}
 
function checkDisableNativeDarkMode() {
const classList = document.documentElement.classList;
if ( classList.contains( 'skin-theme-clientpref-night' ) || classList.contains( 'skin-theme-clientpref-os' ) ) {
classList.remove( 'skin-theme-clientpref-night', 'skin-theme-clientpref-os' );
mw.notify( 'Native dark mode has been enabled. Please set "Color" to light theme to avoid conflicts with the dark mode gadget to supress this message.' );
}
}
 
Line 143 ⟶ 135:
togglePortlets();
actuallyToggleDarkMode();
checkNativeDarkMode();
}
 
Line 161 ⟶ 152:
 
 
$.when($.ready, mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.Uri', 'mediawiki.storage'])).then(function () {
setHtmlClass();
setThemeColor();