User:Richard Harvey/monobook.js
mw.loader.load(
'https://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s');
//Please leave this link: User:Lupin/popups.js
//Please leave this link: User:ais523/editcount.js
//
//JavaScript edit counter. By User:ais523.
//To install this, you can copy it into your monobook.js or use a script-inclusion
//method (see WikiProject User Scripts). It produces a 'count' tab on contribs pages
//that can be used to count a user's edits. It won't count more than 5000 edits in any
//namespace, to prevent excessive server load.
//Add LI Link and Add Tab, renamed to prevent conflicts. To make installation easier
//for people who haven't used User Scripts before.
function ecAddLILink(tabs, url, name, id, title, key){
var na = document.createElement('a');
na.href = url;
na.appendChild(document.createTextNode(name));
var li = document.createElement('li');
if(id) li.id = id;
li.appendChild(na);
tabs.appendChild(li);
if(id)
{
if(key && title)
{
ta[id] = [key, title];
}
else if(key)
{
ta[id] = [key, ''];
}
else if(title)
{
ta[id] = ['', title];
}
}
// re-render the title and accesskeys from existing code in wikibits.js
akeytt();
return li;
}
function ecAddTab(url, name, id, title, key){
var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
return ecAddLILink(tabs, url, name, id, title, key)
}
addOnloadHook(function() {
if(location.href.indexOf("Special")!=-1&&location.href.indexOf("Contributions")!=-1)
ecAddTab("javascript:ais523contrib()","count","ca-ais523count","Count","");
});
//This function was orignally taken from User:Lupin/autoedit.js. I've renamed it
//because I know many users use popups, and I don't want to cause a naming conflict.
//Edited to decode + to space as well, and to use a decoding function that handles
//a broader range of characters.
function ecGetParamValue(paramName) {
var cmdRe=RegExp('[&?]'+paramName+'=([^&]*)');
var h=document.location;
var m;
if (m=cmdRe.exec(h)) {
try {
while(m[1].indexOf('+')!=-1)
{
m[1]=m[1].substr(0,m[1].indexOf('+'))+" "+m[1].substr(m[1].indexOf('+')+1);
}
return decodeURIComponent(m[1]);
} catch (someError) {}
}
return null;
};
function ais523contrib()
{
var u;
if(location.href.indexOf("?")!=-1) u=ecGetParamValue("target");
else u=location.href.substr(location.href.lastIndexOf("/")+1);
location.href="http://en.wikipedia.org/w/index.php?title=Special:Contributions&limit=5000&target="+u+"&ais523count=1&namespace=0";
}
//Analyses an edit summary and returns a two-letter code indicating what the edit seems
//to be doing. The edit summary is passed with parens round it, written in HTML. This
//doesn't yet work for section edits, which will have to be parsed out in the main
//function.
function ecAnalyseSummary(edsum)
{
edsum=edsum.toLowerCase();
if(edsum.indexOf("→")!=-1) return 'se'; //section edit, can't say any more than that
if(edsum==")") return 'se'; //section edit, no summary
if(edsum.indexOf(" ")==0) edsum="("+edsum.substr(1); //came from section
if(edsum.indexOf("(rvv")==0) return 'rv'; //vandalism revert
if(edsum.indexOf("(rv vand")==0) return 'rv'; //vandalism revert
if(edsum.indexOf("(revv")==0) return 'rv'; //vandalism revert
if(edsum.indexOf("(rev vand")==0) return 'rv'; //vandalism revert
if(edsum.indexOf("(revert vand")==0) return 'rv'; //vandalism revert
if(edsum.indexOf("(rv ")==0&&edsum.indexOf("vandal")!=-1) return 'rv';
if(edsum.indexOf("(rev ")==0&&edsum.indexOf("vandal")!=-1) return 'rv';
if(edsum.indexOf("(rv ")==0) return 'ro'; //other manual revert
if(edsum.indexOf("(rev ")==0) return 'ro'; //other manual revert
if(edsum.indexOf("(reverted ")==0) return 'ra'; //automatic revert
if(edsum.indexOf("(revert to ")==0) return 'ra'; //automatic revert
if(edsum.indexOf("(revert")==0) return 'ro'; //guess manual for time being;
//I need more examples of this sort of rv
if(edsum.indexOf("(rm ")==0) return 'rm'; //removal
if(edsum.indexOf("(rem ")==0) return 'rm'; //removal
if(edsum.indexOf("(remove ")==0) return 'rm'; //removal
if(edsum.indexOf("(redir")==0) return 'rd'; //redirect, including redir auto-summary
if(edsum.indexOf("(#redir")==0) return 'rd'; //redirect, including redir auto-summary
if(edsum.indexOf('(
//at the start of a contrib line.
var contribs=0;
var nosum=0,oldnosum;
var sumloc;
var sortcount=new Array();
var bodyh=document.body.innerHTML;
while(bodyh.indexOf("
")!=-1) {
contribs++;
oldnosum=nosum;
bodyh=bodyh.substr(bodyh.indexOf("
")+4); sumloc=9999999;
if(bodyh.indexOf('')!=-1)
sumloc=bodyh.indexOf('');
if(bodyh.indexOf("
") nosum++;
if(bodyh.indexOf("
")==-1&&sumloc!=9999999) nosum--; //last edit on page if(nosum==oldnosum)
{ //Parse edit summary
var edsum=bodyh.indexOf('>',sumloc);
bodyh=bodyh.substr(edsum+1);
sumloc=bodyh.indexOf("");
edsum=bodyh.substr(0,sumloc);
edsum=ecAnalyseSummary(edsum);
if(edsum=='se')
{
//jump to next
bodyh=bodyh.substr(sumloc+7);
sumloc=bodyh.indexOf("");
edsum=bodyh.substr(0,sumloc);
edsum=ecAnalyseSummary(edsum);
}
if(sortcount[edsum]==undefined) sortcount[edsum]=0;
sortcount[edsum]++;
}
}
bodyh=document.body.innerHTML;
//This is the way IE counts it.
while(bodyh.indexOf("
")!=-1) {
contribs++;
oldnosum=nosum;
bodyh=bodyh.substr(bodyh.indexOf("
")+4); sumloc=9999999;
if(bodyh.indexOf('')!=-1) //a plausible format
sumloc=bodyh.indexOf('');
if(bodyh.indexOf('')!=-1) //The IE method
sumloc=bodyh.indexOf('');
if(bodyh.indexOf("
") nosum++;
if(bodyh.indexOf("
")==-1&&sumloc!=9999999) nosum--; //last edit on page if(nosum==oldnosum)
{ //Parse edit summary
var edsum=bodyh.indexOf('>',sumloc);
bodyh=bodyh.substr(edsum+1);
sumloc=bodyh.indexOf("");
edsum=bodyh.substr(0,sumloc);
edsum=ecAnalyseSummary(edsum);
if(edsum=='se')
{
//jump to next
bodyh=bodyh.substr(sumloc+7);
sumloc=bodyh.indexOf("");
edsum=bodyh.substr(0,sumloc);
edsum=ecAnalyseSummary(edsum);
}
if(sortcount[edsum]==undefined) sortcount[edsum]=0;
sortcount[edsum]++;
}
}
var namespace=ecGetParamValue("namespace");
var scres="";
var scit;
for (scit in sortcount)
{
scres+="&cns"+namespace+scit+"="+sortcount[scit];
}
if(namespace!="101") //Portal talk
location.href=location.href.substr(0,location.href.lastIndexOf("namespace="))+
"countns"+namespace+"="+contribs+scres+"&countnosum"+namespace+"="+nosum+"&namespace="+(namespace=="15"?"100":1+new Number(namespace));
else
{
var lh=location.href;
location.href="http://en.wikipedia.org/wiki/User:ais523/results?ais523countres="+lh+"&countns101="+contribs+"&countnosum101="+nosum+scres;
//You can use a page other than User:ais523/results as long as it's in the
//correct format.
}
}
else if(location.href.indexOf("ais523countres=")!=-1)
{ //This relies on the template page User:ais523/results being in the
//correct format.
document.getElementById("ais523echead").style.display="none";
var h=document.getElementById("ais523ecbody").innerHTML;
while(h.indexOf("((")!=-1)
{
var i=h.indexOf("((");
var f=h.substr(0,i);
var g=h.substr(i+2,h.indexOf("))")-i-2);
if(g.indexOf('#d')==0)
{ //delete unwanted lines to remove clutter
var j=h.indexOf("((/#d))");
var v=false;
j=h.substr(i+6,j-i-2);
while(j.indexOf("((")!=-1)
{
var ii=j.indexOf("((");
var gg=j.substr(ii+2,j.indexOf("))")-ii-2);
j=j.substr(ii+2);
gg=ecGetParamValue(gg);
if(gg!=null&&gg!=0&&gg!='0') v=true;
}
if(v) g="";
else {h=h.substr(h.indexOf("((/#d")); g="";}
}
else if(g.indexOf("/#d")==0)
g="";
else if(g.indexOf("total")==0)
{
g=new Number(ecGetParamValue('countns0'));
g+=new Number(ecGetParamValue('countns1'));
g+=new Number(ecGetParamValue('countns2'));
g+=new Number(ecGetParamValue('countns3'));
g+=new Number(ecGetParamValue('countns4'));
g+=new Number(ecGetParamValue('countns5'));
g+=new Number(ecGetParamValue('countns6'));
g+=new Number(ecGetParamValue('countns7'));
g+=new Number(ecGetParamValue('countns8'));
g+=new Number(ecGetParamValue('countns9'));
g+=new Number(ecGetParamValue('countns10'));
g+=new Number(ecGetParamValue('countns11'));
g+=new Number(ecGetParamValue('countns12'));
g+=new Number(ecGetParamValue('countns13'));
g+=new Number(ecGetParamValue('countns14'));
g+=new Number(ecGetParamValue('countns15'));
g+=new Number(ecGetParamValue('countns100'));
g+=new Number(ecGetParamValue('countns101'));
}
else
g=ecGetParamValue(g);
if(g==null) g='0';
f+=g+h.substr(h.indexOf("))")+2);
h=f;
}
document.getElementById("ais523ecbody").innerHTML=h;
}
});
//JavaScript diff finder. By User:ais523
addOnloadHook(function() {
if(location.href.indexOf("Special")!=-1&&location.href.indexOf("Contributions")!=-1)
{
ecAddTab("javascript:ais523l1000()","last 1000","ca-ais523sort","Random diffs from recent edits","");
document.getElementById('ca-ais523sort').innerHTML=
"last 1000 "+
"2000";
}
if(location.href.indexOf("&ais523sort=last")!=-1)
window.setTimeout("ais523sort();",500); //work around IE bug
});
function ais523l1000()
{
var trg;
trg=ecGetParamValue('target');
if(trg==null) trg=location.href.substr(location.href.lastIndexOf("/")+1);
location.href="http://en.wikipedia.org/w/index.php?title=Special:Contributions"+
"&limit=1000&target="+trg+"&ais523sort=last1000";
}
function ais523l2000()
{
var trg;
trg=ecGetParamValue('target');
if(trg==null) trg=location.href.substr(location.href.lastIndexOf("/")+1);
location.href="http://en.wikipedia.org/w/index.php?title=Special:Contributions"+
"&limit=2000&target="+trg+"&ais523sort=last2000";
}
function ais523sort()
{
var s=document.body.innerHTML;
var re=/href="(\/w\/index\.php\?title=([^"/]*)((\/[^"]*)?)&diff=prev&oldid=[0-9]*)"/i;
var a=new Array();
var b=new Array();
var c=new Array();
var nc=new Array();
var d=new Array();
while(s.search(re)!=-1)
{
var m=s.match(re);
var m2="";
var q;
if(m[3]!='') m2=" subpages";
m[4]=decodeURIComponent(m[2])+m2;
m[5]=m2;
if(c[m[4]]==undefined) c[m[4]]=0;
if(c[m[4]]<10) q=c[m[4]];
else if(Math.random()<10/(c[m[4]]+1)) q=Math.floor(Math.random()*10);
else q=-1;
c[m[4]]++;
if(d[m[4]]==undefined) d[m[4]]=new Array();
if(q>-1) d[m[4]][q]=m;
s=s.substr(s.search(re)+2);
}
var i;
var j;
for(i in c)
{
if(c[i]<5)
{
for(j in d[i])
{
var ns="(main)";
var q;
if(d[i][j][4].indexOf(":")!=-1) ns=d[i][j][4].substr(0,d[i][j][4].indexOf(":"));
m=d[i][j];
m[2]="Others in namespace "+ns;
m[3]="";
m[4]=m[2];
m[5]="";
if(nc[m[4]]==undefined) nc[m[4]]=0;
if(nc[m[4]]<10) q=nc[m[4]];
else if(Math.random()<10/(nc[m[4]]+1)) q=Math.floor(Math.random()*10);
else q=-1;
nc[m[4]]++;
if(d[m[4]]==undefined) d[m[4]]=new Array();
if(q>-1) d[m[4]][q]=m;
}
}
}
for(i in d)
{
if(nc[i]!=undefined||c[i]>=5)
for(j in d[i])
{
var m=d[i][j];
m[2]=decodeURIComponent(m[2]);
if(a[m[4]]==undefined) a[m[4]]="*:"+m[2].split("_").join(" ")+""+m[5]+":";
if(b[m[4]]==undefined) b[m[4]]="
"+m[2].split("_").join(" ")+""+m[5]+":"; a[m[4]]+=" [http://en.wikipedia.org"+m[1]+"]";
b[m[4]]+=" ["+(new Number(j)+1)+"]";
}
}
var e=0;
for(i in c)
{
if(c[i]>=5)
{
a[i]+=(c[i]>10?"...":"")+" ("+c[i]+" edit(s))\n";
b[i]+=(c[i]>10?"...":"")+" ("+c[i]+" edit(s))\n";
if(c[i]>e) e=c[i]+1;
}
}
for(i in nc)
{
if(nc[i]>=5)
{
a[i]+=(nc[i]>10?"...":"")+" ("+nc[i]+" edit(s))\n";
b[i]+=(nc[i]>10?"...":"")+" ("+nc[i]+" edit(s))\n";
}
}
var trg=ecGetParamValue('target');
var h="
Contribution breakdown for User:"+trg+"
\n";h+="
HTML output
";
\nvar j=e;
while(--j>=5)
{
for(i in c)
{
if(c[i]==j) h+=b[i];
}
}
for(i in nc) if(nc[i]>=5) h+=b[i];
j=e;
h+="
Wikimarkup output
"; while(--j>=5)
{
for(i in c)
{
if(c[i]==j) h+=a[i];
}
}
for(i in nc) if(nc[i]>=5) h+=a[i];
h+="
";document.body.innerHTML=h;
}
//