| There is no RationalWiki without you. We are a small non-profit with no staff – we are hundreds of volunteers who document pseudoscience and crankery around the world every day. We will never allow ads because we must remain independent. We cannot rely on big donors with corresponding big agendas. We are not the largest website around, but we believe we play an important role in defending truth and objectivity. If everyone seeing this today donates $5, we will meet our goal for 2019. |
Fighting pseudoscience isn't free. We are 100% user-supported! Help and donate $5, $20 or whatever you can today with |
User:MordantMaenad/scripts/contemplinks.js
From RationalWiki
Note: After saving, 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)
- Internet Explorer: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
// be warned: only works for first 500 revisions of nontalk page
if (wgNamespaceNumber == 1) {
var name = wgTitle;
} else {
var name = new String(wgPageName);
name = name.replace(/_talk/i, "");
}
name = escape(name);
function genurl(id, list) {
if (id == "null") {
return wgServer + '/wiki/' + name;
}
for (var j in list) {
if (eval(list[j]) < eval(id)) {
return wgServer + wgScriptPath + "/index.php?title=" + name + "&oldid=" + list[j];
}
}
}
function genlist(data) {
var pages = data.query.pages;
var rlist = new Array();
for (var n = 0; n < 500; n++) {
for (var page in pages) {
try {
var oldid = pages[page].revisions[n].revid;
} catch(err) {
break;
}
}
rlist.push(oldid);
}
var histlinkies = getElementsByClassName(document.getElementById('bodyContent'),"*","mw-history-histlinks");
var datelinks = getElementsByClassName(document.getElementById('bodyContent'),"*","history-user");
for (var j = 0; j< histlinkies.length; j++) {
var addspan = document.createElement('span');
var adda = document.createElement('a');
var d = datelinks[j].parentNode.getElementsByTagName('a');
if (j != 0) {
var idurl = new String(d[2].href);
var idtarget = idurl.substr(idurl.length-6);
} else {
var idtarget = "null";
}
var contempurl = genurl(idtarget, rlist);
adda.href = contempurl;
adda.innerHTML = "contemp";
addspan.appendChild(document.createTextNode("("));
if (contempurl != undefined) {
addspan.appendChild(adda);
} else {
addspan.appendChild(document.createTextNode("contemp"));
}
addspan.appendChild(document.createTextNode(")"));
addspan.className = "contemp-link";
histlinkies[j].parentNode.insertBefore(addspan,histlinkies[j].nextSibling);
histlinkies[j].parentNode.insertBefore(document.createTextNode(addspan.nextSibling.textContent),addspan);
}
var last = document.getElementById("pagehistory").lastChild;
if (last.getElementsByTagName("span")[1].className != "contemp-link") last.insertBefore(document.createTextNode("(contemp)"), last.getElementsByTagName("span")[0].nextSibling);
}
function init_contemp() {
var t = wgCanonicalNamespace;
if (t.search(/talk/i) != -1) {
var u = new String(document.URL);
var target = u.replace(/_talk/i, "");
var obt = document.createElement('script');
obt.src = wgServer + wgScriptPath + '/api.php?format=json&action=query&titles=' + name + '&prop=revisions&rvprop=ids|timestamp&rvlimit=500&callback=genlist';
document.body.appendChild(obt);
}
}
addOnloadHook(init_contemp);