User:Yair rand/FastPerUserDiff.js

wgPageName == "Special:Foo" && jQuery(document).ready(function($){ var bodyContent=mw.util.$content[0], loading, diffaction, searchedpage, searcheduser, waiting = [], continuerev=null, sortdir;  bodyContent.innerHTML='';  mw.util.addCSS("table.diff,td.diff-otitle,td.diff-ntitle{background-color:transparent}td.diff-otitle,td.diff-ntitle{text-align:center}td.diff-marker{text-align:right}td.diff-lineno{font-weight:bold}td.diff-addedline{background:#cfc;font-size:smaller}td.diff-deletedline{background:#ffa;font-size:smaller}td.diff-context{background:#eee;font-size:smaller}.diffchange{color:red;font-weight:bold;text-decoration:none;white-space:pre-wrap;white-space:-moz-pre-wrap}table.diff{border:none;width:98%;border-spacing:4px; table-layout:fixed}table.diff td{padding:0}table.diff col.diff-marker{width:2%}table.diff col.diff-content{width:48%}table.diff td div{ word-wrap:break-word; overflow:auto; }#mw-diff-ntitle4,#mw-diff-otitle4,#toc,.mw-rollback-link{display:none}#mw-diff-ntitle2,#mw-diff-otitle2,#mw-diff-ntitle3,#mw-diff-otitle3{display:inline}.diff-lineno{font-size:10px}") bodyContent.appendChild(document.createElement('h2')).appendChild(document.createTextNode("View contributions")); var f=bodyContent.appendChild(document.createElement('form')); f.appendChild(document.createTextNode("User name: "));f.appendChild(document.createElement("input")); f.appendChild(document.createTextNode("Page name (optional): "));f.appendChild(document.createElement("input")); f.appendChild(document.createTextNode("Sort order: ")); f.appendChild(document.createElement("select")).appendChild(document.createElement("option")).appendChild(document.createTextNode("Oldest first")).parentNode.value="newer"; f.lastChild.appendChild(document.createElement("option")).appendChild(document.createTextNode("Newest first")).parentNode.value="older"; f.appendChild(document.createElement("input")).setAttribute("type","submit");f.lastChild.value = "Show contributions"; f.onsubmit = function{searcheduser = f.getElementsByTagName("input")[0].value;if(searcheduser){searchedpage = f.getElementsByTagName("input")[1].value;sortdir = f.getElementsByTagName("select")[0].value;d;bodyContent.removeChild(f)}else{alert("Please input a user name.")};return false;} function e(ri){ $.ajax({url:"/wiki/?diffonly=1&action=render&diff="+ri.revid, success:function(rr){

var zx = bodyContent.appendChild(document.createElement('span')); zx.innerHTML=" "+(ri.title||searchedpage)+" "+rr; loading = false; onscroll; }})   }  onscroll = function{    if(!loading && continuerev && document.body.scrollTop + screen.availHeight > $(document).height - 400){      loading = true;      d      }    }  function d{    if(waiting.length){      e(waiting.shift);      return;      }    var m = searchedpage ? {action:'query',rawcontinue:,prop:'revisions',rvprop:'ids',rvuser:searcheduser,titles:searchedpage,rvlimit:10,rvdir:sortdir,format:'json'} : {action:'query',rawcontinue:,list:'usercontribs',ucuser:searcheduser,ucdir:sortdir,rcprop:'timestamp|ids|title',format:'json'}

if(continuerev){m[m.rvprop?'rvstartid':'ucstart'] = continuerev} $.get( wgScriptPath + "/api.php", m, function(r){     if(r.query.pages){        (continuerev = r['query-continue']) && (continuerev = continuerev.revisions) && (continuerev = continuerev.rvstartid);        r=r.query.pages;        for(var i in r){r=r[i]};        r=r.revisions;        }      else{        r=r.query.usercontribs;        (continuerev = r['query-continue']) && (continuerev = continuerev.usercontribs) && (continuerev = continuerev.ucstart);        };      if(!r){return}      waiting = r;      e(waiting.shift);      }, "json") } })