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

Content deleted Content added
requested updates from User:Nardog/dark-mode-toggle.js
Line 57:
// We can't use mw.loader as it doesn't work both ways (see talk page)
var scriptPath = mw.util.wikiScript('load');
var gadgetsLinkElement$gadgetsLink = $('link[rel="stylesheet"][href^="' + scriptPath + '?"][href*="ext.gadget."]')[0];
if (gadgetsLinkElement$gadgetsLink.length) {
var uri = new mw.Uri(gadgetsLinkElement$gadgetsLink.prop('href'));
if (newState) {
uri.query.modules += ',dark-mode';
} else {
if (uri.query.modules === 'ext.gadget.dark-mode') {
// dark-mode is the only module in this link
$gadgetsLink.remove();
return;
}
uri.query.modules = uri.query.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
}
gadgetsLinkElement$gadgetsLink.prop('href =', uri.getRelativePath());
} else {
// No gadget-containing styles are enabled