Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// BetterHistory v0.6// Copyright (c) 2005 by Colin Hill (colin@colinhill.us)// This is 100% free code. Use it for anything.// Arrays to hold revision infooldids=newArray(100);revisions=newArray(100);vartitle="Error";varoffset=0;// Object that will soon be the slider buttonvarhandleImg;// Diff status (determines which pages to request)// 0 Current revision html// 1 Diff w/ most recent revision// 2 Diff w/ previous revision// 3 Raw wikicode (doesn't work in Opera yet)vardiffStatus=0;/* Updates diff status */functionChangeDiffStatus(newStatus){if(diffStatus!=newStatus){diffStatus=newStatus;SetArticle(currentArticle);}elsediffStatus=newStatus;}/* Returns an XMLHttpRequest object */functionCreateXMLHTTPObject(){varobject=false;// Internet Explorer/*@cc_on @*//*@if (@_jscript_version >= 5) try{ object = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e){ try{ object = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e2){ object = false; } } @end @*/// Other UAsif(!object&&typeofXMLHttpRequest!='undefined'){object=newXMLHttpRequest();}returnobject;}functionNullPage(){return'<br /><center>This is the end.<br /><br />'+'<a href="http://en.wikipedia.org/wiki/Special:BetterHistory?article='+title+'&offset='+(offset-100)+'">Go forward 100 revisions.</a><br />'+'<a href="http://en.wikipedia.org/wiki/Special:BetterHistory?article='+title+'&offset='+(offset-(-100))+'">Go back 100 revisions.</a>'+'</center>';}/* Extract & format revision strings from history page */functionExtractRevisions(string){// Extract revision stringsvarinsideTagPair=false;varsubstring="";varcurrentRevision=0;for(i=0;i<string.length;i++){// Start of tag pair?if(!insideTagPair){if((""+string.charAt(i))=="<")if(string.substr(i,4)=="<li>"){// Skip past the starting li tagi+=3;// strlen("<li>")insideTagPair=true;continue;}}// End of tag pair?else{// Check for ending tagif((""+string.charAt(i))=="<")if(string.substr(i,5)=="</li>"){// Append the extracted revision to the arrayrevisions[currentRevision]=substring;currentRevision++;substring="";insideTagPair=false;continue;}}// Append current char?if(insideTagPair)substring+=string.charAt(i);}// Remove all the radio buttons from the stringsfor(x=0;x<100;x++){varblanking=false;vartemp="";currentRevision=revisions[x]for(i=0;i<currentRevision.length;i++){// Not blanking?if(!blanking){// Start blanking?if(currentRevision.substr(i,7)=="<input ")blanking=true;// Continue not blankingelsetemp+=currentRevision.charAt(i);}// Blankingelse{// Check for ending tagif((""+currentRevision.charAt(i))=="/")if((""+currentRevision.charAt(i+1))==">"){// Skip last char of the tagi++;// Stop blanking charsblanking=false;}}}revisions[x]=temp;}// Extract oldids, add to arrayvarmatches=null;varvalidRevision=newRegExp("oldid=([0-9]+)");for(i=0;i<100;i++)if(matches=validRevision.exec(revisions[i]))oldids[i]=matches[1];}/* Extracts articles from surrounding html */functionExtractArticle(string){varfirstChar=string.indexOf("<!-- start content -->");varlastChar=string.indexOf("<!-- end content -->");returnstring.substring(firstChar,lastChar);}varcurrentArticle;/* Download & show an article */functionSetArticle(oldidIndex){currentArticle=oldidIndex;varxmlhttp=CreateXMLHTTPObject();document.getElementById("articleHTML").innerHTML="<br /><center><b>Loading...</b></center>";// Diff w/ most recent revisionif(diffStatus==1)xmlhttp.open("GET","http://en.wikipedia.org/w/index.php?title="+title+"&diff=0&oldid="+oldids[oldidIndex],true);// Diff w/ previous revisionelseif((diffStatus==2)&&oldids[oldidIndex]&&oldids[oldidIndex+1])xmlhttp.open("GET","http://en.wikipedia.org/w/index.php?title="+title+"&diff="+oldids[oldidIndex]+"&oldid="+oldids[oldidIndex+1],true);// This revision's wikicodeelseif(diffStatus==3)xmlhttp.open("GET","http://en.wikipedia.org/w/index.php?title="+title+"&oldid="+oldids[oldidIndex]+"&action=raw",true);// Selected revisionelsexmlhttp.open("GET","http://en.wikipedia.org/w/index.php?title="+title+"&oldid="+oldids[oldidIndex],true);// Function to handle resultsxmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){// Show raw if viewing wikicodeif(diffStatus!=3)document.getElementById("articleHTML").innerHTML=ExtractArticle(xmlhttp.responseText);elsedocument.getElementById("articleHTML").innerHTML="<pre>"+xmlhttp.responseText+"</pre>";// Page resizes when new article loads. Snap onto notch again.Snap(true);}}// Send requestxmlhttp.send(null);}// Keeps track of the mouse button's statusvarmousedown=false;/* Returns the x coordinate of a specific notch */functionNotchCoord(notch){return6*notch;}/* Returns the number of the nearest slider notch */functionNearestNotch(x){returnMath.round(x/6.0);}// Current x pos on the trackcurrentX=NotchCoord(100);/* Snaps slider button onto the nearest notch */functionSnap(butDontLoad){// Get X position of the trackvarobject=document.getElementById("track");vartrackPos=0;while(object.offsetParent){trackPos+=object.offsetLeftobject=object.offsetParent;}// Snap to the nearest notchhandleImg.style.left=""+(trackPos+NotchCoord(NearestNotch(currentX))-(12/2))+"px";// Update the currentX positioncurrentX=NotchCoord(NearestNotch(currentX));// Null pageif(NearestNotch(currentX)==0)document.getElementById("articleHTML").innerHTML=NullPage();// Older revisionelseif(!butDontLoad)SetArticle(100-NearestNotch(currentX));}/* Moves the slider button to a new position */functionSlideto(x){// If the the mouse isn't dragging the button, return.if(!mousedown)return;// Get X position of the trackvarobject=document.getElementById("track");vartrackPos=0;while(object.offsetParent){trackPos+=object.offsetLeftobject=object.offsetParent;}// Too far to the left?if(x<trackPos){currentX=0;handleImg.style.left=""+(trackPos-6)+"px";// on the mouse pointer}// Too far to the right?elseif(x>(trackPos+600)){currentX=600;handleImg.style.left=""+(trackPos+600-6)+"px";}else{currentX=x-trackPos;handleImg.style.left=""+(x-7)+"px";}// Show the current revision stringif(NearestNotch(currentX)!=0)document.getElementById('link').innerHTML=revisions[100-NearestNotch(currentX)];elsedocument.getElementById('link').innerHTML="Change offset?";}/* Handles all mouse movement */functiononmousemove_Handler(event){// Firefoxif(event)Slideto(event.clientX);// Internet Explorer & OperaelseSlideto(window.event.clientX);}document.onmousemove=onmousemove_Handler;/* Handles mouseup events */functiononmouseup_Handler(){if(mousedown)Snap(false);mousedown=false;}document.onmouseup=onmouseup_Handler;functiononmousedown_Handler(e){varfocusObject=!document.all?e.target:event.srcElement;vartopElement=!document.all?"HTML":"BODY";if(focusObject.id=="handleImg"){mousedown=true;returnfalse;}}document.onmousedown=onmousedown_Handler;/* Takes over the page if URL is for certain pages */functionCheckPage(){// Put a link on the normal history pagevarvalidHistoryURL=newRegExp(".+action=history.*");if(validHistoryURL.exec(location.href)){// What article?varmatches;vartitleExp=newRegExp("title=([^&]+)");if(matches=titleExp.exec(location.href))title=matches[1];// Offset?varmatches;varoffsetExp=newRegExp("offset=([^&]+)");if(matches=offsetExp.exec(location.href))offset=matches[1];document.getElementById("contentSub").innerHTML+=' <a href="http://en.wikipedia.org/wiki/Special:BetterHistory?article='+title+'&offset='+offset+'">BetterHistory</a>';}validHistoryURL=newRegExp(".+Special:BetterHistory.*");if(validHistoryURL.exec(location.href)){// What article to request?varmatches;vartitleExp=newRegExp("article=([^&]+)");if(matches=titleExp.exec(location.href))title=matches[1];// Offset?varmatches;varoffsetExp=newRegExp("offset=([^&]+)");if(matches=offsetExp.exec(location.href))offset=matches[1];// Set window titledocument.title=title+" - BetterHistory - Wikipedia, the free encyclopedia"// Update weird little tab thingiedocument.getElementById("ca-article").innerHTML="<a href=\"\">BetterHistory</a>";document.getElementById("content").style.position="relative";document.getElementById("content").innerHTML=// Start of new body content'<!-- Options -->'+'<center><table border="0" cellpadding="0" cellspacing="0" width="100%" height="30"><tr><td align="center">'+'<form><input type="radio" name="diffStatus" checked onclick="ChangeDiffStatus(0);"/>This revision <input type="radio" name="diffStatus" onclick="ChangeDiffStatus(1);"/>Diff w/ most recent <input type="radio" name="diffStatus" onclick="ChangeDiffStatus(2);"/>Diff w/ previous <input type="radio" name="diffStatus" onclick="ChangeDiffStatus(3);"/>Raw wikicode</form>'+'</td></tr></table></center>'+'<!-- Header -->'+'<center><table border="0" cellpadding="0" cellspacing="0" width="75%" height="40"><tr><td align="center"><span id="link">Downloading...</span></td></tr></table></center>'+'<!-- Slider track -->'+'<center><img id="track" src="http://gladstone.uoregon.edu/~chill1/betterhistory/slider_track.png"></center>'+'<!-- Spacer image -->'+'<div id="spacer" style="position:relative;"><br /></div>'+'<!-- Article area -->'+'<div id="articleHTML" style="position:relative;"></div>';// End of body content}// Get X position of the trackvarobject=document.getElementById("track");varxPos=0;varyPos=0;while(object.offsetParent){xPos+=object.offsetLeftyPos+=object.offsetTopobject=object.offsetParent;}// Create the slider buttonhandleImg=document.createElement('img');handleImg.style.position="absolute";handleImg.id="handleImg";handleImg.style.left=""+(594+xPos)+"px";handleImg.style.top=""+(6+yPos)+"px";handleImg.style.zIndex="10000";handleImg.setAttribute("src","http://gladstone.uoregon.edu/~chill1/betterhistory/slider_button.gif");handleImg.ondragstart=function(){window.event.returnValue=false;}document.body.appendChild(handleImg);// Create XMLHttpRequest objectvarxmlhttp=CreateXMLHTTPObject();document.getElementById("articleHTML").innerHTML="<br /><center><b>Loading...</b></center>";// Make request for history pagexmlhttp.open("GET","http://en.wikipedia.org/w/index.php?title="+title+"&action=history&limit=100&offset="+offset);// Function to handle resultsxmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){ExtractRevisions(xmlhttp.responseText);document.getElementById('link').innerHTML=revisions[0];// Set article to current revisionSetArticle(0);}}// Send requestxmlhttp.send(null);}window.onload=CheckPage;