Usuario:ZrbtWm/Gadget-quickeditcounter.js

Nota:
Tras guardar el fichero, debes refrescar la caché de tu navegador para ver los cambios.
  • Mozilla: Pulsa el botón Recargar (o ctrl-r)
  • Internet Explorer / Opera: ctrl-f5, *Safari: cmd-r,
  • Konqueror ctrl-r.
// Warning! This gadget also use other projects.
// 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]], [[:pl:User:Rzuwig]], [[:fr:User:Arkanosis]], [[:d:User:Vivaelcelta]], [[m:User:Zerabat]]
 
window.qecGadget = {
	version: 10,
 
	_i18n: ( function() {
 
		var l10n = {
                        ca: {
                                thismaleusermade: 'Aquest usuari ha fet',
                                thisfemaleusermade: 'Aquesta usuària ha fet',
                                total: 'un total de',
                                edits: 'edicions'
                        },
			en: {
				thismaleusermade: 'This user has made',
				thisfemaleusermade: 'This user has made',
				total: 'a total of',
				edits: 'edits'
			},
			es: {
				thismaleusermade: 'Este usuario hizo',
				thisfemaleusermade: 'Esta usuaria hizo',
				total: 'un total de',
				edits: 'ediciones'
			},
			fr: {
				thismaleusermade: 'Cet utilisateur a fait',
				thisfemaleusermade: 'Cette utilisatrice a fait',
				total: 'un total de',
				edits: 'éditions'
			},
			gl: {
				thismaleusermade: 'Este usuario fixo',
				thisfemaleusermade: 'Esta usuaria fixo',
				total: 'un total de',
				edits: 'edicións'
			},
			it: {
				thismaleusermade: 'Questo utente ha fatto',
				thisfemaleusermade: 'Questa utente ha fatto',
				total: 'un totale di',
				edits: 'edizioni'
			},
			ja: {
				thismaleusermade: 'この利用者は',
				thisfemaleusermade: 'この利用者は',
				total: '&nbsp',
				edits: '編集回数持ってます。'
			},
			ko: {
				thismaleusermade: '이 사용자는',
				thisfemaleusermade: '이 사용자는',
				total: '&nbsp',
				edits: '회 편집하였습니다'
			},
			pl: {
				thismaleusermade: 'Ten użytkownik wykonał',
				thisfemaleusermade: 'Ta użytkowniczka wykonała',
				total: 'łącznie',
				edits: 'edycji'
			}
		};
 
		var lang = mw.user.options.get( 'language' );
		if( !l10n[ lang ] ) {
			lang = 'es';
		}
 
		return function( key ) {
			if( l10n[ lang ][ key ] ) {
				return l10n[ lang ][ key ];
			} else {
				return l10n[ 'es' ][ key ];
			}
		};
 
	} )(),
 
	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 request = {
			action:	'query',
			list:	'users',
			usprop:	'editcount|gender',
			format:	'json',
			ususers: this.username,
			requestid: new Date().getTime()
		};
 
		jQuery.getJSON( mw.util.wikiScript( 'api' ), request, function( result ) {
			jQuery( document ).ready( function() {
				if ( result ) {
					that.showResults( result );
				}
			});
		});
	},
 
	showResults: function( data ) {
		data = data.query.users[0];
		if ( !data || 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 = data.gender == 'female'
			? this._i18n( 'thisfemaleusermade' )
			: this._i18n( 'thismaleusermade' );
		var lang = 'www';
		var wiki = 'wikidata';
 
		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 += ' ' + this._i18n( 'total' ) + ' <a href="//tools.wmflabs.org/supercount/index.php?user=' + encodeURIComponent( this.username ) + '&project=' + encodeURIComponent( lang ) + '.' + encodeURIComponent( wiki ) + '">' + data.editcount + '</a> ' + this._i18n( 'edits' ) + '.';
 
		var div = document.createElement( 'div' );
		div.style.cssText = 'font-size:8pt;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();