跳转到内容

User:Vanished user 1929210/js/MarkRights.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/**
 * MarkIPBE.js
 *
 * 在最近修改、监视列表、条目历史记录等位置以特殊格式显示有特殊权限的用户
 *
 */

$(function () {
    var markIPBE = function () {
        var $users = $('a.mw-userlink:not(.mw-anonuserlink)');
        var users = {};
        $users.each(function (index, link) {
            users[link.textContent] = true;
        });

        var queue1 = [];
        var queue2 = [];
        var i=0, n=0;
        for (var user in users) {
            queue1.push(user);
            i++;
            if (i === 50) {
                queue2.push(queue1);
                queue1 = [];
                n++;
                i = 0;
            }
        }
        if (queue1.length > 0) {
            queue2.push(queue1);
            n++;
        }

        var sysoplist = [];
        var bureaucratlist = [];
        var culist = [];
        var oslist = [];
        var plist = [];
        var rlist = [];
        var alist = [];
        var ipbelist = [];

        var done = function () {
            var j;
            for (j=0; j<bureaucratlist.length; j++) {
                $('a.mw-userlink[title="User:' + bureaucratlist[j] + '"]').append('<sup style="color:black;">B</sup>');
            }
            for (j=0; j<culist.length; j++) {
                $('a.mw-userlink[title="User:' + culist[j] + '"]').append('<sup style="color:purple;">C</sup>');
            }
            for (j=0; j<oslist.length; j++) {
                $('a.mw-userlink[title="User:' + oslist[j] + '"]').append('<sup style="color:purple;">O</sup>');
            }
            for (j=0; j<sysoplist.length; j++) {
                $('a.mw-userlink[title="User:' + sysoplist[j] + '"]').append('<sup style="color:mediumvioletred;">A</sup>');
            }

            for (j=0; j<plist.length; j++) {
                $('a.mw-userlink[title="User:' + plist[j] + '"]').append('<sup style="color:sienna;">p</sup>');
            }
            for (j=0; j<rlist.length; j++) {
                $('a.mw-userlink[title="User:' + rlist[j] + '"]').append('<sup style="color:sienna;">r</sup>');
            }
            for (j=0; j<alist.length; j++) {
                $('a.mw-userlink[title="User:' + alist[j] + '"]').append('<sup style="color:sienna;">a</sup>');
            }

            for (j=0; j<ipbelist.length; j++) {
                $('a.mw-userlink[title="User:' + ipbelist[j] + '"]').append('<sup style="color:green;">E</sup>');
            }
        };

        var process = function (data) {
            var users;
            if (data.query && data.query.users) {
                users = data.query.users;
            } else {
                users = [];
            }
            for (var i=0; i<users.length; i++) {
                var user = users[i];
                if (user.groups) {
                    if (user.groups.indexOf('ipblock-exempt') > -1) {
                        ipbelist.push(user.name);
                    }
                    if (user.groups.indexOf('bureaucrat') > -1) {
                        bureaucratlist.push(user.name);
                    }
                    if (user.groups.indexOf('checkuser') > -1) {
                        culist.push(user.name);
                    }
                    if (user.groups.indexOf('oversight') > -1) {
                        oslist.push(user.name);
                    }
                    if (user.groups.indexOf('sysop') > -1) {
                        sysoplist.push(user.name);
                    }
                    if (user.groups.indexOf('patroller') > -1) {
                        plist.push(user.name);
                    }
                    if (user.groups.indexOf('rollbacker') > -1) {
                        rlist.push(user.name);
                    }
                    if (user.groups.indexOf('autoreviewer') > -1) {
                        alist.push(user.name);
                    }
                }
            }

            n--;
            if (n <= 0) {
                done();
            }
        };

        var api = new mw.Api();
        for (var j=0; j<queue2.length; j++) {
            api.get({
                format: 'json',
                action: 'query',
                list: 'users',
                usprop: 'groups',
                ususers: queue2[j].join('|')
            }).done(process);
        }
    };

    markIPBE();
});