User:Casper2k3/Javascript/comparelink.js

/*

// Compare link

function fixCompare { var histForm=document.getElementsByTagName("form")[0]; var finalButton=document.getElementById("historysubmit"); var firstButton=histForm.getElementsByTagName("input")[1]; histForm.removeChild(finalButton); histForm.removeChild(firstButton); var compareLink=document.createElement("a"); var genLink="http://en.wikipedia.org/w/index.php?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")[0]; 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="http://en.wikipedia.org/w/index.php?title=" + histForm.title.value + "&diff=" + histForm.diff[diffInd].value + "&oldid=" + histForm.oldid[oldInd].value; compareLink.setAttribute("href", genLink); endLink.setAttribute("href", genLink); } if(url.indexOf("action=history")!=-1) $(fixCompare); /*