User:PerfektesChaos/js/markGroupMembers/eo.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:PerfektesChaos/js/markGroupMembers/eo. |
/// User:PerfektesChaos/js/markGroupMembers/eo.js
/// 2015-11-18 PerfektesChaos@de.wikipedia
// Mark users who are members of arbitrary groups
// ResourceLoader: compatible;
// dependencies: mediawiki.util
// Requires: JavaScript 1.5, MediaWiki 1.23 (mw.hook, jQuery core)
/// @license GPL [//www.mediawiki.org/w/COPYING] (+GFDL, LGPL, CC-BY-SA)
/// <nowiki>
/* global window:false */
/* jshint forin:false,
bitwise:true, curly:true, eqeqeq:true, latedef:true,
laxbreak:true,
nocomma:true, strict:true, undef:true, unused:true */
( function ( mw, $ ) {
"use strict";
var Groups = [ "A", "B" ],
Users = { "A": [ "Alaŭdo",
"Alaudo",
"Andy",
"AndyHM",
"Blahma",
"Castelobranco",
"Chuck SMITH",
"Darkweasel94",
"DidiWeidmann",
"KuboF",
"Marcos",
"Narvalo",
"PaulP",
"Pino",
"Pino~eowiki",
"Roboto de Marcos",
"Salatonbv",
"Thomas Guibal",
"ThomasPusch",
"Tlustulimu",
"Umbert'",
"Yekrats",
"לערי ריינהארט" ],
"B": [ "Alaŭdo",
"Alaudo",
"DidiWeidmann",
"Tlustulimu" ],
"C": false,
"I": false,
"O": false,
"K": false,
"Ar": false,
"Ar+": false },
Tips = { "A": "Administranto",
"B": "Burokrato",
"C": "checkuser",
"I": "подводящий итоги",
"O": "Revizianto",
"K": "клерк",
"Ar": "Arbitracianto",
"Ar+": "Rezerva arbitracianto" },
Live = true, // true: page is required to exist
Lower = false, // true: include links to subpages
Sep = "/",
Spaces = "Uzant(?:o|ino)", // + talk NS
Style = "color:#0645AD;" +
"font-size:small;" +
"font-weight:bold;" +
"margin-left:0.2em;" +
"vertical-align:super;",
Badges, Learnt, Modes, REurl;
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program;
* if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*/
function found( i, dom ) {
// Matching result
// i -- element count
// dom -- DOM element <a>
var got = REurl.exec( dom.href ),
badge, k, mode, s, sign, staff, story, suffix, users, $a;
if ( got ) {
staff = got[ 1 ].replace( /_/, " " );
try {
staff = decodeURIComponent( staff );
} catch (e) {
if ( window.console &&
typeof window.console.log === "function" ) {
window.console.log( "eo:Gadget-markGroupMembers decode",
staff );
}
} // try decode
got = [ ];
for ( k = 0; k < Groups.length; k++ ) {
sign = Groups[ k ];
users = Users[ sign ];
if ( users && $.inArray( staff, users ) >= 0 ) {
got.push( sign );
}
} // for k
if ( got.length ) {
sign = got.join();
if ( typeof Badges[ sign ] === "object" ) {
badge = Badges[ sign ];
story = badge.story;
mode = badge.mode;
} else {
mode = ++Modes;
Badges[ sign ] = { };
for ( k = 0; k < got.length; k++ ) {
s = got[ k ];
if ( story ) {
story = story + ", ";
suffix = suffix + Sep + s;
} else {
story = "";
suffix = "(" + s;
}
} // for k
story = story + Tips[ s ];
suffix = suffix + ")";
badge = Badges[ sign ];
badge.learnt = true;
badge.mode = mode;
badge.story = story;
badge.suffix = suffix;
Learnt = true;
}
$a = $( dom );
$a.attr( "title", $a.attr( "title" ) + "\n" + story );
$a.addClass( "markGroupMembers markGroupMembers-" + mode );
}
}
} // found()
function furnish( $area ) {
// Page content has been updated
// $area -- jQuery $content
var badge, sign, styles;
Learnt = false;
$area.find( "a[href^=\"/wiki/\"]" ).each( found );
if ( Learnt ) {
styles = "";
for ( sign in Badges ) {
badge = Badges[ sign ];
if ( badge.learnt ) {
badge.learnt = false;
styles = styles +
".markGroupMembers-" + badge.mode + ":after {" +
"content:\"" + badge.suffix + "\";" +
Style + "}";
}
} // for sign in Badges
mw.util.addCSS( styles );
}
} // furnish()
function fire() {
// Initialize gadget
if ( Live ) {
REurl = "/wiki/";
} else {
REurl = "/(?:wiki/|.+[?&]title=)";
}
REurl = REurl + Spaces;
if ( Lower ) {
REurl = REurl + ":([^#?&]+)";
} else {
REurl = REurl + ":([^/#?&]+)";
}
REurl = REurl + "(?:[#?].*)?$";
Badges = { };
Modes = 0;
REurl = new RegExp( REurl );
mw.hook( "wikipage.content" ).add( furnish );
} // fire()
mw.loader.using( [ "mediawiki.util" ],
fire );
}( window.mediaWiki, window.jQuery ) );
// Emacs
// Local Variables:
// coding: utf-8-dos
// End:
/// EOF </nowiki> markGroupMembers/eo.js