User:KirkLU/js/markRightText.js

注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/*
 取自 oldid=46107689 markIPBE.js 原作者:逆襲的天邪鬼
 在最近修改、监视列表、条目历史记录等位置以特殊格式显示有特殊权限的用户
 
 更新項目:
	1.項目矩陣
	2.用顏色標記權限並提示該標記的權限名稱
	3.權限用for 迴圈重複操作來呈現,並設定上限
	4.不僅限於IPBE用戶。
	5.支援顯示最近更改的按鈕
 更新者:小躍
 */

$(function () {
    var markRight = 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 aclist=[]; var autoclist=[]; var iadlist=[]; var masmlist = [];
        
        var memberlist=[bureaucratlist,sysoplist,iadlist,culist,oslist,plist,rlist,alist,ipbelist,aclist,masmlist,autoclist];
        var membername=['bureaucrat','sysop','interface-admin','checkuser','oversight','patroller','rollbacker','autoreviewer','ipblock-exempt','accountcreator','massmessage','autoconfirmed'];
        var membertag=['red','orange','#FFD700','#CCFF00','yellow','#4DE680','#30D5C8','blue','#8B00FF','#4B0080','#882200','#C0C0C0'];
        var memberabbr=['B','A','I','C','O','P','R','Ar','Ip','Ac','M','Ac'];

        var done = function () {
        	var k;
            var j;
            for(k=0;k<memberlist.length;k++){
            	for (j=0; j<memberlist[k].length; j++) {
                	$('a.mw-userlink[title="User:' + memberlist[k][j] + '"]')
                	.append('<sup style="color:'+membertag[k]+';background-color:transparent" title="'+membername[k]+'">'+memberabbr[k]+'<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) {
                	var m=0;
                	for(m=0;m<memberlist.length;m++){
                		if (user.groups.indexOf(membername[m]) > -1) {
                        	memberlist[m].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);
        }
    };
    if(mw.config.get('wgPageName')=='Special:用户列表'){}else{
    markRight();
    $('.oo-ui-flaggedElement-progressive.oo-ui-buttonWidget > a').click(
    	function(){
    		setTimeout(function(){markRight()},7000);
    	}
    );
    }
});