User:Nardog/dark-mode-toggle.js: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
 
(20 intermediate revisions by 2 users not shown)
Line 34:
 
function vectorStickyCallback() {
mw.hook('vector.page_title_scroll').remove(vectorStickyCallback);
if (document.getElementById('pt-darkmode-sticky-header')) return;
makePortletLink('p-personal-sticky-header', 'pt-darkmode-sticky-header', '#pt-watchlist-sticky-header');
 
// Work around lack of icon in sticky header
$('#pt-darkmode-sticky-header span:only-child')
.before($('<span>').addClass('mw-ui-icon mw-ui-icon-vector-gadget-pt-darkmode'));
 
mw.hook('vector.page_title_scroll').remove(vectorStickyCallback);
}
 
Line 52 ⟶ 48:
 
function getMsg(suffix) {
var key = 'darkmode-turn-' + (isOn ? 'onoff' : 'offon') + '-' + suffix;
return mw.msg(key);
}
Line 72 ⟶ 68:
case 'vector-2022':
case 'minerva':
labelSelector = '#pt-darkmode span:not(.mw-ui-icon:empty), #pt-darkmode-sticky-header span:not(.mw-ui-icon:empty)';
break;
default:
Line 88 ⟶ 84:
var $gadgetsLink = $('link[rel="stylesheet"][href^="' + scriptPath + '?"][href*="ext.gadget."]');
if ($gadgetsLink.length) {
var uriurl = new mw.UriURL($gadgetsLink.prop('href'));
var modules = url.searchParams.get('modules');
if (isOn) {
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
}
url.searchParams.set('modules', modules);
$gadgetsLink.prop('href', uriurl.getRelativePath()pathname + url.search);
} else {
// No gadget-containing styles are enabled