User:Zabshk/common.js: Difference between revisions

From TestWiki
Content added Content deleted
No edit summary
No edit summary
Line 4: Line 4:
// - QuickEditCounter script by [[:pl:User:ChP94]]
// - QuickEditCounter script by [[:pl:User:ChP94]]
// - Released under the [http://www.gnu.org/licenses/gpl.txt GNU Public License (GPL)]
// - Released under the [http://www.gnu.org/licenses/gpl.txt GNU Public License (GPL)]
// Modified by [[:pl:User:Beau]]
//Modified by [[:pl:User:Beau]] and then by [[:pl:User:Zabshk]]


window.qecGadget = {
window.qecGadget = {
Line 21: Line 21:


var that = this;
var that = this;
var global = null;

var request = {
var request = {
action: 'query',
action: 'query',
list: 'users',
list: 'users',
usprop: 'editcount|gender',
usprop: 'editcount',
format: 'json',
format: 'json',
ususers: this.username,
ususers: this.username,
requestid: new Date().getTime()
requestid: new Date().getTime()
};
};
var globalrequest = {
action: 'query',
meta: 'globaluserinfo',
guiprop: 'editcount',
format: 'json',
guiuser: this.username,
requestid: new Date().getTime()
};
jQuery.getJSON( mw.util.wikiScript( 'api' ), request, function(result) {
jQuery(document).ready(function() {
if (result) {
global = result;
}
});
});


jQuery.getJSON( mw.util.wikiScript( 'api' ), request, function(result) {
jQuery.getJSON( mw.util.wikiScript( 'api' ), request, function(result) {
jQuery(document).ready(function() {
jQuery(document).ready(function() {
if (result) {
if (result) {
that.showResults(result);
that.showResults(result, global);
}
}
});
});
});
});
},
},
showResults: function(data) {
showResults: function(data, gdata) {
data = data.query.users[0];
data = data.query.users[0];
gdata = gdata.query.globaluserinfo;
if (!data || data.name != this.username || data.invalid != null || data.editcount === undefined)
if (!data || data.name != this.username || data.invalid != null || data.editcount === undefined)
return;
if (!gdata || data.name != this.username || data.invalid != null || data.editcount === undefined)
return;
return;


Line 63: Line 85:


var html = 'This user made';
var html = 'This user made';

html += ' <font color="#2B60DE">' + data.editcount + '</font> local edits and <font color="#F70D1A">' + gdata.editcount + ' total edits.';
var m;
if (m = mw.config.get( 'wgServer' ).match(/^(?:http:)?\/\/(.+?).([^.]+).org$/)) {
lang = m[1];
wiki = m[2];
}
else if (m = mw.config.get( 'wgScriptPath' ).match(/\/(.+?)\/(.+?)\//)) {
lang = m[2];
wiki = m[1];
}

html += ' <font color="#2B60DE">' + data.editcount + '</font> edits.';


var div = document.createElement("div");
var div = document.createElement("div");

Revision as of 14:00, 15 April 2017

mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:Zabshk/heading-icons.js&action=raw&ctype=text/javascript');

// Original version:
// - QuickEditCounter script by [[:pl:User:ChP94]]
// - Released under the [http://www.gnu.org/licenses/gpl.txt GNU Public License (GPL)]
//Modified by [[:pl:User:Beau]] and then by [[:pl:User:Zabshk]]

window.qecGadget = {
	version: 9,

	init: function() {
		if ( mw.config.get( 'wgNamespaceNumber' ) != 2 && mw.config.get( 'wgNamespaceNumber' ) != 3 ) {
			return;
		}

		if ( mw.util.getParamValue('printable') == 'yes' ) {
			return;
		}

		this.username = mw.config.get( 'wgTitle' ).replace(/\/.*$/, '');

		var that = this;
		var global = null;
		
		var request = {
			action:	'query',
			list:	'users',
			usprop:	'editcount',
			format:	'json',
			ususers:	this.username,
			requestid:	new Date().getTime()
		};
		
		var globalrequest = {
			action:	'query',
			meta:	'globaluserinfo',
			guiprop: 'editcount',
			format:	'json',
			guiuser:	this.username,
			requestid:	new Date().getTime()
		};
		
		jQuery.getJSON( mw.util.wikiScript( 'api' ), request, function(result) {
			jQuery(document).ready(function() {
				if (result) {
					global = result;
				}
			});
		});

		jQuery.getJSON( mw.util.wikiScript( 'api' ), request, function(result) {
			jQuery(document).ready(function() {
				if (result) {
					that.showResults(result, global);
				}
			});
		});
	},
	showResults: function(data, gdata) {
		data = data.query.users[0];
		gdata = gdata.query.globaluserinfo;
		if (!data || data.name != this.username || data.invalid != null || data.editcount === undefined)
			return;
			
		if (!gdata || data.name != this.username || data.invalid != null || data.editcount === undefined)
			return;

		var firstHeading;
		var headers = document.getElementsByTagName( 'h1' );

		for ( var 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 html = 'This user made';
		
		html += ' <font color="#2B60DE">' + data.editcount + '</font> local edits and <font color="#F70D1A">' + gdata.editcount + ' total edits.';

		var div = document.createElement("div");
		div.style.cssText = "font-size:0.5em;line-height:1em";
		div.className = 'plainlinks';
		div.innerHTML = html;

		if ( mw.config.get( 'skin' ) == 'modern' ) {
			div.style.marginLeft = "10px";
			div.style.display = "inline-block";
		}

		firstHeading.appendChild(div);
	}
};

qecGadget.init();