User:希羽岚/Gadget-MarkRights.js

/** * 取自 oldid=46135902 * MediaWiki:Gadget-MarkRights.js * 修改自 * https://zh.wikipedia.org/w/index.php?title=Draft:MediaWiki:Gadget-MarkRights.js/50678903&oldid=52825311 * * 在最近修改、监视列表、条目历史记录等位置以特殊格式显示有特殊权限的用户 * */

$(function {    var groups = {        // 全站管理型权限        bureaucrat: {list: [], class: "markrights-bureaucrat"},        checkuser: {list: [], class: "markrights-checkuser"},        oversight: {list: [], class: "markrights-oversight"},        sysop: {list: [], class: "markrights-sysop"},        'interface-admin': {list: [], class: "markrights-interface-admin"},        templateeditor: {list: [], class: "markrights-templateeditor"},        transwiki: {list: [], class: "markrights-transwiki"},        // 页面管理型权限        patroller: {list: [], class: "markrights-patroller"},        rollbacker: {list: [], class: "markrights-rollbacker"},        autoreviewer: {list: [], class: "markrights-autoreviewer"},        // 大量操作型权限        accountcreator: {list: [], class: "markrights-accountcreator"},        'massmessage-sender': {list: [], class: "markrights-massmessage-sender"},        // 确认权限        confirmed: {list: [], class: "markrights-confirmed"}, autoconfirmed: {list: [], class: "markrights-autoconfirmed"}, // 机器权限 bot: {list: [], class: "markrights-bot"}, flood: {list: [], class: "markrights-flood"}, // IPBE 'ipblock-exempt': {list: [], class: "markrights-ipblock-exempt"}, };   var markUG = 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 getUsername = function (url) { var username = mw.util.getParamValue('title', url); if (username) { return decodeURIComponent(username.replace('User:', '').replace(/_/g, ' ')); }           username = url.match(/\/wiki\/User:(.+?)$/); if (username) { return decodeURIComponent(username[1].replace(/_/g, ' ')); }           return null; };

var done = function { var group; $('a.mw-userlink:not(.mw-anonuserlink)').each(function (i, el) {               var username = getUsername($(el).attr('href'));                if (username) {                    for (group in groups) {                        if (groups.hasOwnProperty(group)) {                            if (groups[group].list.includes(username)) {                                $(el).append(' ');                            }                        }                    }                }            }); };

var process = function (data) { var users, group; 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) { for (group in groups) { if (groups.hasOwnProperty(group) && user.groups.indexOf(group) > -1) { groups[group].list.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('wgDiffNewId') || mw.config.get('wgDiffOldId')) { // 啟用「互動式瀏覽歷史」，切換差異時重新標記 mw.hook('wikipage.diff').add(function { // Reload alongside the revision slider            markUG;        }); } else if (['Recentchanges', 'Recentchangeslinked', 'Watchlist'].indexOf(mw.config.get('wgCanonicalSpecialPageName')) !== -1) { // 最近/相關更改更新時重新標記 mw.hook('wikipage.content').add(function (element) {           if (element.hasClass('mw-changeslist')) {                markUG;            }        }); markUG; } else { markUG; } });