Jump to content

User:Pratyya Ghosh/crathighlighter.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//********************************************************************************************************************************
// 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 );