Użytkownik:Chommik12/kolorowanie-nickow.js: Różnice pomiędzy wersjami
Z Nonsensopedii, polskiej encyklopedii humoru
M |
M |
||
Linia 51: | Linia 51: | ||
//if (!nick_replacement) |
//if (!nick_replacement) |
||
nick_replacement = |
var nick_replacement = new Array(); |
||
//if (!nick_color) |
//if (!nick_color) |
||
Linia 163: | Linia 163: | ||
{ |
{ |
||
cn$loaded = true; |
cn$loaded = true; |
||
if (wgNamespaceNumber == -1 || wgAction == 'history') |
if (wgNamespaceNumber == -1 || wgAction == 'history') { |
||
var nick_replacement = new Array(); |
|||
setTimeout("cn$doColor()",500); |
setTimeout("cn$doColor()",500); |
||
} |
|||
}); |
}); |
||
} |
} |
Wersja z 19:09, 22 wrz 2009
/*
* ----- HOWTO, czyli jak sprawić, żeby to działało -----
* 1. do swojego pliku JS ze skórką (np. User:Jakiśuser/monobook.js) dodaj:
* -- importScript('User:Chommik12/kolorowanie-nickow.js');
* 2. do swojego pliku CSS ze skórką dodaj (teraz bedzie nieco więcej):
* -- a.nick_steward, a.nick_steward:visited { font-weight:bold; color: darkorange; }
* -- a.nick_bot, a.nick_bot:visited { font-weight:bold; }
* -- a.nick_admin, a.nick_admin:visited { font-weight: bold; color: darkgreen; }
* -- a.nick_friend, a.nick_friend:visited { color: green; }
*
* UWAGA: to, co masz skopiować zaczyna się PO '--'. Nie kopiuj ich.
*/
/*
* Skrypt pożyczyłem z Wikipedii
* Licencja: CC-BY-SA
* Autor: Beau
* Oryginalny adres: http://pl.wikipedia.org/wiki/MediaWiki:Gadget-lib-beau.js
*/
var beau$userGroups = {};
if (wgUserGroups) {
for (var i = 0; i < wgUserGroups.length; i++) {
beau$userGroups[ wgUserGroups[i] ] = true;
}
}
function beau$callAPI(query) {
var url = wgServer + wgScriptPath + '/api.php?';
for (var field in query) {
var value = query[field];
url += '&' + field + '=' + encodeURIComponent(value);
}
url += '&format=json';
importScriptURI(url);
}
/*
* Skrypt pożyczyłem z Wikipedii
* Licencja: CC-BY-SA
* Autor: Beau
* Oryginalny adres: http://pl.wikipedia.org/wiki/MediaWiki:Gadget-colored-nicknames.js
*/
var cn$userLink = 'Użytkownik';
var cn$contribLink = 'Specjalna:Wk';
if (typeof(beau$callAPI) == 'undefined')
// importScript('MediaWiki:Gadget-lib-beau.js');
// nie importuj, już załączyłem.
//if (!nick_replacement)
var nick_replacement = new Array();
//if (!nick_color)
var nick_color = new Array();
var cn$queries = -1;
var cn$loaded = false;
var cn$list = {
// 'Walter': ['nick_steward']
// tu upychamy liste staffów, która najprawdopodobniej będzie.
};
function cn_gotSysops(data) {
cn$addToList(data, 'nick_admin');
}
function cn_gotBots(data) {
cn$addToList(data, 'nick_bot');
}
function cn$addToList(data, type) {
for (id in data.query.allusers) {
var nick = data.query.allusers[id].name;
if (cn$list[nick]) {
cn$list[nick].push(type);
}
else {
cn$list[nick] = new Array(type);
}
}
cn$queries--;
if (cn$queries == 0 && cn$loaded)
cn$doColor();
}
function cn$getNickReplacement(nick)
{
for (var i = 0; i < nick_replacement.length; i+=2)
{
if (nick_replacement[i] == nick)
{
return nick_replacement[i+1];
}
}
}
function cn$getUserClass(nick)
{
var userClass = new Array();
for (var i = 0; i < nick_color.length; i+=2)
if (nick_color[i] == nick) {
userClass.push(nick_color[i+1]);
break;
}
if (cn$list[nick]) {
userClass = userClass.concat(cn$list[nick]);
}
if (nick.match(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/)) {
userClass.push('nick_ip');
}
return userClass;
}
function cn$doColor() {
cn$queries = -1;
var links = document.getElementsByTagName('a');
for (var i = 0; i < links.length; i++)
{
var link = links[i];
if (! link.href.match(cn$userLink) && ! link.href.match(cn$contribLink))
continue;
var replacement = cn$getNickReplacement(link.text);
if (replacement)
link.innerHTML = replacement;
var userClass = cn$getUserClass(link.text);
if (userClass.length)
link.className += ' ' + userClass.join(' ');
}
}
if (wgNamespaceNumber == -1 || wgAction == 'history')
{
cn$queries = 2;
beau$callAPI({
action: 'query',
list: 'allusers',
augroup: 'sysop',
aulimit: 500,
maxage: 43200,
smaxage: 600,
callback: 'cn_gotSysops'
});
beau$callAPI({
action: 'query',
list: 'allusers',
augroup: 'bot',
aulimit: 500,
maxage: 43200,
smaxage: 600,
callback: 'cn_gotBots'
});
addOnloadHook(function()
{
cn$loaded = true;
if (wgNamespaceNumber == -1 || wgAction == 'history') {
var nick_replacement = new Array();
setTimeout("cn$doColor()",500);
}
});
}