User:Rzuwig/Gadget-colored-nicknames.js

// UWAGA! Z tego gadżetu korzystają także inne projekty // Author: pl:User:Beau if (typeof(cn$replacement) == "undefined") { window.cn$replacement = {}; } if (typeof(cn$class) == "undefined") { window.cn$class = {}; } window.coloredNicknamesGadget = { queries: 0, loaded: false, cache: {}, list: {}, version: 9, userLink: /(?:Wiki(?:pedystk?a|skryba|reporter)|U.+ytkownik|U.+ytkowniczka|User)/, contribLink: /Specjalna:Wk/, init: function { if ( mw.config.get( 'wgNamespaceNumber' ) > -1 && mw.config.get( 'wgAction' ) != 'history' ) { return; }		var that = this; var request = { action:	'query', list:	'allusers', augroup:	'sysop', aulimit:	'max', maxage:	43200, smaxage:	600, format:	'json' };		this.queries++; jQuery.getJSON( mw.util.wikiScript( 'api' ), request, function(result) {			that.addToList(result, 'nick_admin');		}); var request = { action:	'query', list:	'allusers', augroup:	'bot', aulimit:	'max', maxage:	43200, smaxage:	600, format:	'json' };		this.queries++; jQuery.getJSON( mw.util.wikiScript( 'api' ), request, function(result) {			that.addToList(result, 'nick_bot');		}); if ( mw.config.get( 'wgServer' ) == 'https://secure.wikimedia.org' ) { var request = { action:	'query', list:	'allusers', augroup:	'steward', aulimit:	'max', maxage:	43200, smaxage:	600, format:	'json' };			this.queries++; jQuery.getJSON('https://secure.wikimedia.org/wikipedia/meta/w/api.php', request, function(result) {				that.addToList(result, 'nick_steward');			}); }		jQuery(document).ready(function {			that.loaded = true;			if (that.queries == 0)				that.doColor;			}		); },	addToList: function(data, type) { if (data) { for (id in data.query.allusers) { var nick = data.query.allusers[id].name; if (this.list[nick]) { this.list[nick].push(type); }				else { this.list[nick] = new Array(type); }			}		}		this.queries--; if (this.queries == 0 && this.loaded) { this.doColor; }	},	getUserClass: function(nick) { if ( nick == null ) { return []; }		var userClass = this.cache[nick]; if (userClass) { return userClass; }		userClass = []; var nc = cn$class[nick]; if (nc) { userClass.push(nc); }		if (this.list[nick]) { userClass = userClass.concat(this.list[nick]); }		if (nick.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)) { userClass.push('nick_ip'); if (this.isDynamic(nick)) { userClass.push('nick_dynamic_ip'); }		}		this.cache[nick] = userClass; return userClass; },	isDynamic: function(ip) { return false; },	doColor: function { this.queries = -1; if ((typeof dynamicIpsGadget) == 'object') { this.isDynamic = function(ip) { return dynamicIpsGadget.isDynamic(ip); } }		var links = document.getElementsByTagName('a'); for (var i = 0; i < links.length; i++) {			var link = links[i]; if (! link.href.match(this.userLink) && ! link.href.match(this.contribLink)) { continue; }			var nick = jQuery(link).text; var replacement = cn$replacement[nick]; if (replacement) { link.innerHTML = replacement; }			var userClass = this.getUserClass(nick); if (userClass.length) { link.className += ' ' + userClass.join(' '); }		}		this.cache = {}; } }; coloredNicknamesGadget.init;