User:Pratyya Ghosh/crathighlighter.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:Pratyya Ghosh/crathighlighter. |
//********************************************************************************************************************************
// I've created this script by modifying "User:Liangent/userhighlighter.js@wikidata"
// That's why I can't take the full credit of this script. I thank Liangent for creating the sysop highlighter :-)
// If you know how a js works and know js then I'm giving you the permission to edit this page without blowing it up.
// If you don't know about js then I'll ask you to leave this script.
// You are free to Share or remix this work.
//*********************************************************************************************************************************
( function( $, mw ) { mw.loader.using( [ 'mediawiki.util', 'mediawiki.api', 'mediawiki.Title' ], function() {
var api = new mw.Api();
var bureaucrats = {};
var params = {
rawcontinue: '',
list: 'allusers',
augroup: 'bureaucrat',
aulimit: 'max'
};
var load = function() {
api.get( params, {
ok: function( data ) {
$.each( data.query.allusers, function() {
bureaucrats[this.name] = 1;
} );
if ( data['query-continue'] ) {
$.extend( params, data['query-continue'].allusers );
load();
} else {
$( function() {
$( 'a', mw.util.$content ).each( function() {
var $this = $( this );
var title = $this.attr( 'title' );
if ( !title ) {
return;
}
if ( $this.hasClass( 'new' ) ) {
title = title.replace( /[(\(][^)\)]+[)\)]$/, '' );
}
title = new mw.Title( title );
if ( ( title.getNamespaceId() & ~1 ) == 2 && bureaucrats[title.getMainText().split( '/' )[0]] == 1
|| title.getNamespaceId() == -1 && title.getMainText().indexOf( '/' ) != -1
&& bureaucrats[title.getMainText().split( '/' )[1]] == 1 ) {
$this.css( 'background-color', 'yellow' ).addClass( 'amalthea_userhighlighter_sysop' );
}
} );
} );
}
}
} );
};
load();
} ); } )( jQuery, mediaWiki );