MediaWiki:Gadget-topIcons.js: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
No edit summary Tag: Manual revert |
(Replaced content with "(function () { console.log("Running test script..."); let testVar = 42; console.log("Test variable value:", testVar); })();") Tags: Replaced Reverted |
||
Line 1: | Line 1: | ||
⚫ | |||
/** |
|||
console.log("Running test script..."); |
|||
* Moves icons from [[Template:External]] to the top bar, next to "Article" and "Talk" tabs; |
|||
let testVar = 42; |
|||
* rewritten from scratch for modern MediaWiki |
|||
console.log("Test variable value:", testVar); |
|||
*/ |
|||
⚫ | |||
⚫ | |||
let namespace = mw.config.get('wgNamespaceNumber'); |
|||
// automatically show externals on Special and MediaWiki namespaces |
|||
if (namespace === -1 || namespace === 8) { |
|||
let page = mw.config.get('wgPageName'); |
|||
addLink('the RuneScape Wiki', 'rsw', page); |
|||
addLink('the RuneScape Classic Wiki', 'classicrsw', page); |
|||
addLink('the Meta Weird Gloop Wiki', 'meta', page); |
|||
} |
|||
else { |
|||
// make this work when "Show preview without reloading the page" is checked |
|||
mw.hook('wikipage.content').add(function ($content) { |
|||
if (!$content.has('.rs-external-header-links').length) return; |
|||
// clear existing externals first so previewing doesn't add an infinite amount |
|||
$('.gadget-external-icon').remove(); |
|||
// convert whatever [[Template:External]] gives us |
|||
$('.rs-header-icon').each(function (index, icon) { |
|||
addLink(icon.dataset.wikiname, icon.dataset.interwiki, icon.dataset.page); |
|||
}); |
|||
// clean up |
|||
$('.rs-external-header-links').remove(); |
|||
⚫ | |||
} |
|||
function addLink(wikiname, interwiki, page) { |
|||
let url = mw.util.getUrl(interwiki + ':' + page); |
|||
let title = wikiname + ' also has an article on ' + page + '.'; |
|||
// wikipedia links aren't forwarded - see [[Special:Interwiki]] |
|||
if (interwiki === 'wikipedia') { |
|||
url = '//en.wikipedia.org/wiki/' + encodeURIComponent(page); |
|||
} |
|||
// Special and MediaWiki namespaces |
|||
if (namespace === -1 || namespace === 8) { |
|||
url += window.location.search; // include url parameters |
|||
title = 'Open this page on ' + wikiname + '.'; |
|||
} |
|||
let link = mw.util.addPortletLink( |
|||
'p-namespaces', |
|||
url, |
|||
'', // no text - use background-image instead |
|||
'gadget-external-' + interwiki, // button id |
|||
title // title text shown on hover |
|||
); |
|||
// for styling all links at once - addPortletLink only sets an id |
|||
$(link).addClass('gadget-external-icon'); |
|||
} |
|||
})(jQuery, mediaWiki); |