User:Lampak/quickeditcounter.js

var qec_username;

function qec_callapi(query) { var url = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + '/api.php?'; for (var field in query) { var value = query[field]; url += '&' + field + '=' + encodeURIComponent(value); }	url += '&format=json'; mw.loader.load(url); }

function qec_init { var firstHeading; var headers = document.getElementsByTagName("h1"); for(i=0; i<headers.length; i++) { var header = headers[i]; if(header.className == "firstHeading" || header.id == "firstHeading" || header.className == "pagetitle") { firstHeading = header; break; }	}	if(!firstHeading) firstHeading = document.getElementById("section-0"); if(!firstHeading) return; var qec_span = document.createElement("div"); qec_span.id = 'qec_span'; qec_span.style.cssText = "font-size:8pt;line-height:1em"; if (skin == 'modern') {		qec_span.style.marginLeft = "10px"; qec_span.style.display = "inline-block"; }	firstHeading.appendChild(qec_span); qec_username = wgTitle.replace(/\/.*$/, ''); qec_callapi({		action:	'query',		list:	'allusers',		auprefix:	qec_username,		auprop:	'editcount',		aulimit:	1,		callback:	'qec_callback',	}); } function qec_callback(data) {	data = data.query.allusers[0]; if (!data || data.name != qec_username) return; var html = ''; var lang = 'en'; var wiki = 'wikipedia'; var m;	if (m = wgServer.match(/^http:\/\/(.+?).([^.]+).org$/)) { lang = m[1]; wiki = m[2]; }	else if (m = wgScriptPath.match(/\/(.+?)\/(.+?)\//)) { lang = m[2]; wiki = m[1]; }	html += 'This user has ' + data.editcount + ' edits.'; var qec_span = document.getElementById("qec_span"); qec_span.innerHTML = html; } if(wgNamespaceNumber==2 || wgNamespaceNumber==3) addOnloadHook(qec_init);