User:Mike.lifeguard/fixCompare.js
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)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
//fixcompare.js
//By Superm401
function fixCompare() {
var histForm=document.getElementsByTagName("form")[1];
var finalButton=document.getElementById("pagehistory").nextSibling;
if(!finalButton || finalButton == null) return;
var firstButton=histForm.getElementsByTagName("input")[1];
histForm.removeChild(finalButton);
histForm.removeChild(firstButton);
var compareLink=document.createElement("a");
var genLink = mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + histForm.title.value + "&diff=" + histForm.diff[0].value + "&oldid=" + histForm.oldid[1].value;
compareLink.setAttribute("href", genLink);
compareLink.appendChild(document.createTextNode("Compare selected versions"));
histForm.insertBefore(compareLink, document.getElementById("pagehistory"));
var endLink=compareLink.cloneNode(true);
histForm.appendChild(endLink);
var diffList=document.getElementById("pagehistory");
diffList.setAttribute("onchange", "updateCompare()");
}
function updateCompare() {
var histForm=document.getElementsByTagName("form")[1];
var diffList=document.getElementById("pagehistory");
var compareLink=diffList.previousSibling;
var endLink=diffList.nextSibling;
var oldInd=-1;
var i=0;
while(oldInd==-1 & i<histForm.oldid.length){
if(histForm.oldid[i].checked)
oldInd=i;
i++;
}
var diffInd=-1;
var j=0;
while(diffInd==-1 & j<histForm.diff.length){
if(histForm.diff[j].checked)
diffInd=j;
j++;
}
var genLink = mw.config.get('wgServer') + mw.config.get('wgScript') + "?title=" + histForm.title.value + "&diff=" + histForm.diff[diffInd].value + "&oldid=" + histForm.oldid[oldInd].value;
compareLink.setAttribute("href", genLink);
endLink.setAttribute("href", genLink);
}
if( mw.config.get('wgAction') == "history" ) addOnloadHook(fixCompare);