User:Sunwell5/Common.js/interlinker.js
Appearance
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
// Fix links like User:Example@somewiki. Author: VasilievVV, with modifications by Kalan and attempted rewrite by Splarka
function fixCrosswikiLinks() {
function host(id) {
if(id == 'enwiki') {
return 'http://sunwell5.0lx.net/testwiki';
} else if(id == 'autoguide1') {
return 'http://sunwell5.0lx.net/autoguide1';
}
return false;
}
var docobj = document.getElementById('bodyContent') || document.getElementById('content') || document.getElementById('mw_content') || document.body
var li = docobj.getElementsByTagName('li');
for(var i=0;i<li.length;i++) {
var a = getElementsByClassName(li[i],'a','new');
for(var j=0;j<a.length;j++) {
var atxt = getText(a[j]);
if(atxt.indexOf('@') != -1 && atxt.indexOf('/') == -1 && /^User\:/i.test(atxt)) {
var bits = atxt.split('@',2);
var user = encodeURIComponent(bits[0].replace(/^\s*User:(.+)\s*$/g, '$1'));
var wiki = bits[1];
var hostName = host(wiki);
if(!hostName) continue
a[j].setAttribute('href',hostName + '/wiki/User:' + user);
a[j].className = (wiki=='metawiki') ? '' : 'extiw'
a[j].setAttribute('title',atxt);
}
}
}
}
if(wgCanonicalSpecialPageName == 'Log' || wgCanonicalSpecialPageName == 'Recentchanges') addOnloadHook(fixCrosswikiLinks)
function getText(object) {
if (object.nodeType == 3) return object.nodeValue;
var txt = [];
var i=0;
while(object.childNodes[i]) {
txt[txt.length] = getText(object.childNodes[i]);
i++;
}
return txt.join('');
}