User:Hotaru Natsumi/js/markrights.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/**
* 取自 oldid=46135902
* MediaWiki:Gadget-MarkRights.js
*
* 在最近修改、监视列表、条目历史记录等位置以特殊格式显示有特殊权限的用户
*
*/
mw.loader.using(['ext.gadget.site-lib'], function () {
$(function () {
var groups = {
// 全站管理型权限
bureaucrat: {list: [], style: "color:black;", title: 'B'},
checkuser: {list: [], style: "color:purple;", title: 'C'},
oversight: {list: [], style: "color:purple;", title: 'O'},
sysop: {list: [], style: "color:mediumvioletred;", title: 'A'},
'interface-admin': {list: [], style: "color:mediumvioletred;", title: 'T'},
// 机器账户
flood: {list: [], style: "color:mediumvioletred;", title: 'F'},
// 页面管理型权限
patroller: {list: [], style: "color:sienna;", title: 'P'},
rollbacker: {list: [], style: "color:sienna;", title: 'R'},
autoreviewer: {list: [], style: "color:sienna;", title: 'A'},
filemover: {list: [], style: "color:sienna;", title: 'F'},
// 大量操作型权限
accountcreator: {list: [], style: "color:blue;", title: 'C'},
'massmessage-sender': {list: [], style: "color:blue;", title: 'S'},
// 机器人
bot: {list: [], style: "color:blue;", title: 'B'},
// IPBE
'ipblock-exempt': {list: [], style: "color:green;", title: 'E'},
// 确认权限
confirmed: {list: [], style: "color:green;", title: 'C'},
autoconfirmed: {list: [], style:"color:rgb(127,127,127);", title: 'C'},
};
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 done = function () {
var group, user, j;
for (group in groups) {
if (groups.hasOwnProperty(group)) {
for (j=0; j<groups[group].list.length; j++) {
$('a.mw-userlink[title="User:' + groups[group].list[j] + '"]').append('<sup style="' + groups[group].style + '">' + groups[group].title + '</sup>');
}
}
}
};
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);
}
};
markUG();
});
});