User:Nx/Scripts/Editcount.js
Jump to navigation
Jump to search
Note: After saving, 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: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
// Original script: QuickEditCounter script by [[:pl:User:ChP94]]
// Updated version by [[User:Nx]]
// Released under the [http://www.gnu.org/licenses/gpl.txt GNU Public License (GPL)]
// <pre><nowiki>
var qec_ajax;
var qec_username;
var qec_niceuname;
//Function from QuickEdit 2 by ASM
function qec_initAjax()
{
try
{
if (window.XMLHttpRequest)
{
qec_ajax = new XMLHttpRequest();
qec_ajax.overrideMimeType('text/xml');
}
else if (window.ActiveXObject)
qec_ajax = new ActiveXObject('Microsoft.XMLHTTP');
else throw 'Ajax support missing';
}
catch (e)
{
return false;
}
if (!qec_ajax)
{
alert('Error creating ajax object');
return false;
}
return true;
}
function qec_onload()
{
if(wgNamespaceNumber!=2&&wgNamespaceNumber!=3)
return;
qec_initAjax();
qec_username = wgPageName;
qec_niceuname = wgTitle.replace(/\/.*$/, '');
qec_username = qec_username.substring(qec_username.indexOf(':') + 1);
qec_username = qec_username.replace(/\/.*$/, '');
qec_username = encodeURIComponent(qec_username);
qec_ajax.onreadystatechange = qec_processResponse;
qec_ajax.open('GET', wgServer+wgScriptPath+'/api.php' + '?action=query&list=allusers&format=xml&auprop=editcount&aulimit=1&aufrom=' + qec_username, true);
qec_ajax.send(null);
}
function qec_processResponse()
{
if (qec_ajax.readyState != 4 || qec_ajax.status != 200)
return;
var xml = qec_ajax.responseXML;
var conts = document.getElementsByTagName("h1");
for(i=0;i<conts.length;i++) {
var c = conts[i];
if(c.getAttribute("class")=="firstHeading") {
cont = c; break;
}
}
if(!cont) {
cont = document.getElementById("section-0");
}
if(xml.getElementsByTagName("u").length>0) {
count = xml.getElementsByTagName("u")[0].getAttribute("editcount");
name = xml.getElementsByTagName("u")[0].getAttribute("name");
//api.php returns the next username if this user does not exist
// if (encodeURIComponent(name.replace(/ /,'_')) != qec_username) return;
if (name != qec_niceuname) return;
if (typeof(count) == "undefined") count = 0;
elem = document.createElement("span");
elem.style.fontSize = "8pt";
elem.style.marginLeft = "10px";
elem.style.lineHeight = "1em";
elem.innerHTML="<p style=\"margin-bottom:0em;\">This user has a total of <a" + " href=\"" + wgServer+wgScript+"?title=Special:Contributions/" + qec_username + "\">"+count+"</a> edits.</p>";
cont.appendChild(elem);
}
}
addOnloadHook(qec_onload);
//</nowiki></pre>