MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针。
如果在编辑的过程中遇到了什么问题,可以去讨论板提问。
为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证。
MCBBS Wiki GitHub群组已上线!
您可以在回声洞中发表吐槽!
服务器状态监控。点击进入
本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>
Gadget:usergroup.js:修订间差异
跳到导航
跳到搜索
(// Edit via Wikiplus) |
(MoegirlPedia --> Wikipedia // Edit via Wikiplus) |
||
第1行: | 第1行: | ||
// From Wikipedia. MediaWiki:Gadget-MarkRights.js |
|||
// From 萌娘百科 |
|||
$(function () { |
|||
"use strict"; |
|||
var groups = { |
|||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { |
|||
// 全站管理型权限 |
|||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } |
|||
bureaucrat: {list: [], class: "markrights-bureaucrat"}, |
|||
return new (P || (P = Promise))(function (resolve, reject) { |
|||
checkuser: {list: [], class: "markrights-checkuser"}, |
|||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } |
|||
suppress: {list: [], class: "markrights-suppress"}, |
|||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } |
|||
sysop: {list: [], class: "markrights-sysop"}, |
|||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } |
|||
'interface-admin': {list: [], class: "markrights-interface-admin"}, |
|||
step((generator = generator.apply(thisArg, _arguments || [])).next()); |
|||
// 页面管理型权限 |
|||
}); |
|||
patroller: {list: [], class: "markrights-patroller"}, |
|||
}; |
|||
rollbacker: {list: [], class: "markrights-rollbacker"}, |
|||
var __generator = (this && this.__generator) || function (thisArg, body) { |
|||
// 确认权限 |
|||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; |
|||
confirmed: {list: [], class: "markrights-confirmed"}, |
|||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; |
|||
autoconfirmed: {list: [], class: "markrights-autoconfirmed"}, |
|||
function verb(n) { return function (v) { return step([n, v]); }; } |
|||
extendedconfirmed: {list: [], class: "markrights-extendedconfirmed"}, |
|||
function step(op) { |
|||
// 机器权限 |
|||
if (f) throw new TypeError("Generator is already executing."); |
|||
bot: {list: [], class: "markrights-bot"}, |
|||
}; |
|||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; |
|||
var markUG = function () { |
|||
if (y = 0, t) op = [op[0] & 2, t.value]; |
|||
var $users = $('a.mw-userlink:not(.mw-anonuserlink)'); |
|||
switch (op[0]) { |
|||
var users = {}; |
|||
$users.each(function (index, link) { |
|||
case 4: _.label++; return { value: op[1], done: false }; |
|||
users[link.textContent] = true; |
|||
}); |
|||
case 7: op = _.ops.pop(); _.trys.pop(); continue; |
|||
default: |
|||
var queue1 = []; |
|||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } |
|||
var queue2 = []; |
|||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } |
|||
var i = 0, n = 0; |
|||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } |
|||
for (var user in users) { |
|||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } |
|||
queue1.push(user); |
|||
i++; |
|||
if (i === 50) { |
|||
queue2.push(queue1); |
|||
queue1 = []; |
|||
n++; |
|||
i = 0; |
|||
} |
} |
||
op = body.call(thisArg, _); |
|||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } |
|||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; |
|||
} |
|||
}; |
|||
var __read = (this && this.__read) || function (o, n) { |
|||
var m = typeof Symbol === "function" && o[Symbol.iterator]; |
|||
if (!m) return o; |
|||
var i = m.call(o), r, ar = [], e; |
|||
try { |
|||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); |
|||
} |
|||
catch (error) { e = { error: error }; } |
|||
finally { |
|||
try { |
|||
if (r && !r.done && (m = i["return"])) m.call(i); |
|||
} |
} |
||
if (queue1.length > 0) { |
|||
queue2.push(queue1); |
|||
} |
|||
n++; |
|||
}; |
|||
var __values = (this && this.__values) || function(o) { |
|||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; |
|||
if (m) return m.call(o); |
|||
if (o && typeof o.length === "number") return { |
|||
next: function () { |
|||
if (o && i >= o.length) o = void 0; |
|||
return { value: o && o[i++], done: !o }; |
|||
} |
} |
||
}; |
|||
var getUsername = function (url) { |
|||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); |
|||
var username = mw.util.getParamValue('title', url); |
|||
}; |
|||
var decode1 = function (username) { |
|||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { |
|||
return decodeURIComponent((function (u) { |
|||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { |
|||
if (ar || !(i in from)) { |
|||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); |
|||
ar[i] = from[i]; |
|||
} |
|||
} |
|||
return to.concat(ar || Array.prototype.slice.call(from)); |
|||
}; |
|||
(function () { return __awaiter(void 0, void 0, void 0, function () { |
|||
var localObjectStorage, groups, groupStr, groupsKey, blocklogFlags, cache, api, eol, fixZero, toLocalTimeZoneString, groupsKey_1, groupsKey_1_1, i, _a, result_1, aufrom, _result, blockCache, now, _b, _c, _d, username, _e, timestamp, isBlocked, querySelectorAll, markBlocked, hook, style, groups_1, groups_1_1, _f, group, color, _g, _h, _j, group, strList, _k, _l, _m, lang, str; |
|||
var e_1, _o, e_2, _p, e_3, _q, e_4, _r, e_5, _s; |
|||
return __generator(this, function (_t) { |
|||
switch (_t.label) { |
|||
case 0: return [4, $.ready]; |
|||
case 1: |
|||
_t.sent(); |
|||
localObjectStorage = new LocalObjectStorage("usergroup"); |
|||
groups = [ |
|||
["bureaucrat", "#6610f2"], |
|||
["checkuser", "#673ab7"], |
|||
["suppress", "#9c27b0"], |
|||
["sysop", "#ec407a"], |
|||
["patroller", "#f44336"], |
|||
["interface-admin", "#3f51b5"], |
|||
["bot", "#00acc1"], |
|||
["extendedconfirmed", "#2cd5c4"], |
|||
["excellenteditor", "#1aa179"], |
|||
].reverse(); |
|||
groupStr = { |
|||
bureaucrat: {zh: "行"}, |
|||
checkuser: {zh: "查"}, |
|||
suppress: {zh: "监"}, |
|||
sysop: {zh: "管"}, |
|||
patroller: {zh: "巡"}, |
|||
bot: {zh: "机"}, |
|||
excellenteditor: {zh: "优"}, |
|||
"interface-admin": {zh: "界"}, |
|||
extendedconfirmed: {zh: "延"} |
|||
}; |
|||
groupsKey = groups.map(function (_a) { |
|||
var _b = __read(_a, 1), group = _b[0]; |
|||
return group; |
|||
}); |
|||
blocklogFlags = Object.entries({ |
|||
anononly: "仅封禁匿名用户", |
|||
nocreate: "阻止创建新账号", |
|||
autoblock: "自动封禁该用户最后使用的IP地址,以及其随后试图用于编辑的所有IP地址", |
|||
noemail: "阻止用户发送电子邮件", |
|||
nousertalk: "阻止用户在封禁期间编辑自己的讨论页", |
|||
hiddenname: "隐藏用户名" |
|||
}); |
|||
api = new mw.Api(); |
|||
eol = Symbol(); |
|||
fixZero = function (n, l) { |
|||
if (l === void 0) { l = 2; } |
|||
return "".concat(n).padStart(l, "0"); |
|||
}; |
|||
toLocalTimeZoneString = function (date) { |
|||
if (date === void 0) { date = new Date(); } |
|||
return "".concat(date.getFullYear(), "/").concat(fixZero(date.getMonth() + 1), "/").concat(fixZero(date.getDate()), " ").concat(fixZero(date.getHours()), ":").concat(fixZero(date.getMinutes()), ":").concat(fixZero(date.getSeconds()), ".").concat(fixZero(date.getMilliseconds(), 3)); |
|||
}; |
|||
_t.label = 2; |
|||
case 2: |
|||
_t.trys.push([2, 4, , 8]); |
|||
return [4, localObjectStorage.getItem("cache")]; |
|||
case 3: |
|||
cache = _t.sent(); |
|||
if (!cache |
|||
|| typeof cache.timestamp !== "number" || cache.timestamp < new Date().getTime() - 30 * 60 * 1000 |
|||
|| !cache.groups) { |
|||
throw new Error(); |
|||
} |
|||
else { |
|||
try { |
try { |
||
return decodeURIComponent(u.replace('用户:', '').replace(/_/g, ' ')); |
|||
for (groupsKey_1 = __values(groupsKey), groupsKey_1_1 = groupsKey_1.next(); !groupsKey_1_1.done; groupsKey_1_1 = groupsKey_1.next()) { |
|||
} catch (e) { |
|||
return u.replace('用户:', '').replace(/_/g, ' ').replace(/%(?!\d+)/g, '%25'); |
|||
throw new Error(); |
|||
} |
|||
} |
|||
} |
} |
||
})(username)) |
|||
}; |
|||
if (username) { |
|||
return decode1(username); |
|||
} |
|||
username = url.match(/\/wiki\/用户:(.+?)$/); |
|||
finally { if (e_1) throw e_1.error; } |
|||
var decode2 = function (username) { |
|||
return decodeURIComponent((function (u) { |
|||
try { |
|||
return decodeURIComponent(u.replace(/_/g, ' ')); |
|||
} catch (e) { |
|||
return u.replace(/_/g, ' ').replace(/%(?!\d+)/g, '%25'); |
|||
} |
} |
||
} |
})(username)) |
||
}; |
|||
if (username) { |
|||
return decode2(username[1]); |
|||
} |
|||
result_1 = Object.fromEntries(groupsKey.map(function (n) { return [n, []]; })); |
|||
return null; |
|||
}; |
|||
case 5: |
|||
var done = function () { |
|||
var group; |
|||
$('a.mw-userlink:not(.mw-anonuserlink)').each(function (i, el) { |
|||
action: "query", |
|||
var username = getUsername($(el).attr('href')); |
|||
if (username) { |
|||
for (group in groups) { |
|||
if (groups.hasOwnProperty(group)) { |
|||
if (groups[group].list.indexOf(username) > -1) { |
|||
$(el).append('<sup class="' + groups[group].class + '"></sup>'); |
|||
case 6: |
|||
_result = _t.sent(); |
|||
if (_result["continue"]) { |
|||
aufrom = _result["continue"].aufrom; |
|||
} |
|||
else { |
|||
aufrom = eol; |
|||
} |
|||
_result.query.allusers.forEach(function (_a) { |
|||
var name = _a.name, groups = _a.groups; |
|||
groups.forEach(function (group) { |
|||
if (groupsKey.includes(group)) { |
|||
result_1[group] || (result_1[group] = []); |
|||
if (!result_1[group].includes(name)) { |
|||
result_1[group].push(name); |
|||
} |
} |
||
} |
|||
}); |
|||
}); |
|||
return [3, 5]; |
|||
case 7: |
|||
cache = { |
|||
timestamp: new Date().getTime(), |
|||
groups: result_1 |
|||
}; |
|||
return [3, 8]; |
|||
case 8: return [4, localObjectStorage.setItem("cache", cache)]; |
|||
case 9: |
|||
_t.sent(); |
|||
return [4, localObjectStorage.getItem("blockCache", {})]; |
|||
case 10: |
|||
blockCache = _t.sent(); |
|||
now = Date.now(); |
|||
try { |
|||
for (_b = __values(Object.entries(blockCache)), _c = _b.next(); !_c.done; _c = _b.next()) { |
|||
_d = __read(_c.value, 2), username = _d[0], _e = _d[1], timestamp = _e.timestamp, isBlocked = _e.isBlocked; |
|||
if (typeof username !== "string" || typeof timestamp !== "number" || typeof isBlocked !== "boolean" || now - timestamp > 30 * 60 * 1000) { |
|||
Reflect.deleteProperty(blockCache, username); |
|||
} |
} |
||
} |
} |
||
} |
} |
||
}); |
|||
}; |
|||
try { |
|||
var process = function (data) { |
|||
if (_c && !_c.done && (_p = _b["return"])) _p.call(_b); |
|||
var users, group; |
|||
if (data.query && data.query.users) { |
|||
users = data.query.users; |
|||
} else { |
|||
return [4, localObjectStorage.setItem("blockCache", blockCache)]; |
|||
users = []; |
|||
} |
|||
for (var i = 0; i < users.length; i++) { |
|||
querySelectorAll = function (selector) { return __spreadArray([], __read(document.querySelectorAll(selector)), false); }; |
|||
var user = users[i]; |
|||
if (user.groups) { |
|||
for (group in groups) { |
|||
if ( |
if (groups.hasOwnProperty(group) && user.groups.indexOf(group) > -1) { |
||
groups[group].list.push(user.name); |
|||
var sup = document.createElement("sup"); |
|||
sup.classList.add("detailedBlockInfo"); |
|||
sup.title = blockInfo.info; |
|||
ele.after(sup); |
|||
} |
|||
}; |
|||
hook = function () { return __awaiter(void 0, void 0, void 0, function () { |
|||
var unknownUsernames, _a, _b, ele, parent_1, inNavbox, url, username, pathname, title, groupsKey_2, groupsKey_2_1, group, sup, blockInfo, has_apihighlimits, singleRequestLimit, targets, _loop_1, i, l, _c, _d, ele, username, blockInfo, groupsKey_3, groupsKey_3_1, group, _e, _f, node, nextElementSibling, nextNextElementSibling; |
|||
var e_6, _g, e_7, _h, e_8, _j, e_9, _k, e_10, _l; |
|||
return __generator(this, function (_m) { |
|||
switch (_m.label) { |
|||
case 0: |
|||
unknownUsernames = new Set(); |
|||
try { |
|||
for (_a = __values(querySelectorAll("a.mw-userlink:not(.markrights), .userlink > a:not(.markrights)")), _b = _a.next(); !_b.done; _b = _a.next()) { |
|||
ele = _b.value; |
|||
parent_1 = ele.parentElement; |
|||
inNavbox = false; |
|||
while (parent_1) { |
|||
if (parent_1.classList.contains("navbox")) { |
|||
inNavbox = true; |
|||
break; |
|||
} |
|||
parent_1 = parent_1.parentElement; |
|||
} |
|||
if (inNavbox) { |
|||
continue; |
|||
} |
|||
ele.classList.add("markrights"); |
|||
url = new URL(new mw.Uri(ele.href)); |
|||
username = void 0; |
|||
pathname = decodeURIComponent(url.pathname); |
|||
title = url.searchParams.get("title"); |
|||
if (/^\/User:[^/=%]+/.test(pathname)) { |
|||
username = pathname.match(/^\/User:([^/=%]+)/)[1].replace(/_/g, " "); |
|||
} |
|||
else if (/^User:[^/=%]+/.test(title)) { |
|||
username = title.match(/^User:([^/=%]+)/)[1].replace(/_/g, " "); |
|||
} |
|||
if (!username) { |
|||
continue; |
|||
} |
|||
ele.dataset.username = username; |
|||
try { |
|||
for (groupsKey_2 = (e_7 = void 0, __values(groupsKey)), groupsKey_2_1 = groupsKey_2.next(); !groupsKey_2_1.done; groupsKey_2_1 = groupsKey_2.next()) { |
|||
group = groupsKey_2_1.value; |
|||
if (cache.groups[group].includes(username)) { |
|||
sup = document.createElement("sup"); |
|||
sup.classList.add("markrights-".concat(group)); |
|||
ele.after(sup); |
|||
} |
|||
} |
|||
} |
|||
catch (e_7_1) { e_7 = { error: e_7_1 }; } |
|||
finally { |
|||
try { |
|||
if (groupsKey_2_1 && !groupsKey_2_1.done && (_h = groupsKey_2["return"])) _h.call(groupsKey_2); |
|||
} |
|||
finally { if (e_7) throw e_7.error; } |
|||
} |
|||
if (!ele.classList.contains("markBlockInfo")) { |
|||
blockInfo = blockCache[username]; |
|||
if (blockInfo && blockInfo.timestamp) { |
|||
markBlocked(ele, blockInfo); |
|||
} |
|||
else { |
|||
ele.classList.add("unknownBlockInfo"); |
|||
unknownUsernames.add(username); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
catch (e_6_1) { e_6 = { error: e_6_1 }; } |
|||
finally { |
|||
try { |
|||
if (_b && !_b.done && (_g = _a["return"])) _g.call(_a); |
|||
} |
|||
finally { if (e_6) throw e_6.error; } |
|||
} |
|||
if (!(unknownUsernames.size > 0)) return [3, 7]; |
|||
return [4, mw.user.getRights()]; |
|||
case 1: |
|||
has_apihighlimits = (_m.sent()).includes("apihighlimits"); |
|||
singleRequestLimit = has_apihighlimits ? 500 : 50; |
|||
targets = __spreadArray([], __read(unknownUsernames.values()), false); |
|||
_loop_1 = function (i, l) { |
|||
var bkcontinue, target, blockedUserName, now_1, _result, _o, _p, username; |
|||
var e_11, _q; |
|||
return __generator(this, function (_r) { |
|||
switch (_r.label) { |
|||
case 0: |
|||
bkcontinue = undefined; |
|||
target = targets.slice(i * singleRequestLimit, (i + 1) * singleRequestLimit); |
|||
blockedUserName = []; |
|||
now_1 = Date.now(); |
|||
_r.label = 1; |
|||
case 1: |
|||
if (!(bkcontinue !== eol)) return [3, 3]; |
|||
return [4, api.post({ |
|||
action: "query", |
|||
list: "blocks", |
|||
bkusers: target, |
|||
bklimit: "max", |
|||
bkprop: "id|user|by|timestamp|expiry|reason|flags", |
|||
bkcontinue: bkcontinue |
|||
})]; |
|||
case 2: |
|||
_result = _r.sent(); |
|||
if (_result["continue"]) { |
|||
bkcontinue = _result["continue"].aufrom; |
|||
} |
|||
else { |
|||
bkcontinue = eol; |
|||
} |
|||
_result.query.blocks.forEach(function (blockInfo) { |
|||
var e_12, _a; |
|||
blockedUserName.push(blockInfo.user); |
|||
var info = "".concat(blockInfo.id, " - \n \u88ABU:").concat(blockInfo.by).concat(wgULS("封禁", "封鎖"), "\u4E8E").concat(toLocalTimeZoneString(new Date(blockInfo.timestamp)), "\uFF0C"); |
|||
if (moment(blockInfo.expiry).isValid()) { |
|||
info += "".concat("持续", "\u81F3").concat(toLocalTimeZoneString(new Date(blockInfo.expiry))); |
|||
} |
|||
else { |
|||
info += "持续时间为无限期"; |
|||
} |
|||
info += "\n ".concat("额外限制", "\uFF1A"); |
|||
if (!Reflect.has(blockInfo, "allowusertalk")) { |
|||
blockInfo.nousertalk = true; |
|||
} |
|||
var flags = []; |
|||
try { |
|||
for (var blocklogFlags_1 = (e_12 = void 0, __values(blocklogFlags)), blocklogFlags_1_1 = blocklogFlags_1.next(); !blocklogFlags_1_1.done; blocklogFlags_1_1 = blocklogFlags_1.next()) { |
|||
var _b = __read(blocklogFlags_1_1.value, 2), flag = _b[0], comment = _b[1]; |
|||
if (Reflect.has(blockInfo, flag)) { |
|||
flags.push(comment); |
|||
} |
|||
} |
|||
} |
|||
catch (e_12_1) { e_12 = { error: e_12_1 }; } |
|||
finally { |
|||
try { |
|||
if (blocklogFlags_1_1 && !blocklogFlags_1_1.done && (_a = blocklogFlags_1["return"])) _a.call(blocklogFlags_1); |
|||
} |
|||
finally { if (e_12) throw e_12.error; } |
|||
} |
|||
if (flags.length === 0) { |
|||
flags.push("(无)"); |
|||
} |
|||
info += flags.join("、"); |
|||
info += "\n ".concat("理由", "\uFF1A").concat(blockInfo.reason); |
|||
blockCache[blockInfo.user] = { |
|||
timestamp: now_1, |
|||
isBlocked: true, |
|||
info: info |
|||
}; |
|||
}); |
|||
return [3, 1]; |
|||
case 3: |
|||
try { |
|||
for (_o = (e_11 = void 0, __values(target.filter(function (username) { return !blockedUserName.includes(username); }))), _p = _o.next(); !_p.done; _p = _o.next()) { |
|||
username = _p.value; |
|||
blockCache[username] = { |
|||
timestamp: now_1, |
|||
isBlocked: false |
|||
}; |
|||
} |
|||
} |
|||
catch (e_11_1) { e_11 = { error: e_11_1 }; } |
|||
finally { |
|||
try { |
|||
if (_p && !_p.done && (_q = _o["return"])) _q.call(_o); |
|||
} |
|||
finally { if (e_11) throw e_11.error; } |
|||
} |
|||
return [2]; |
|||
} |
|||
}); |
|||
}; |
|||
i = 0, l = Math.ceil(targets.length / singleRequestLimit); |
|||
_m.label = 2; |
|||
case 2: |
|||
if (!(i < l)) return [3, 5]; |
|||
return [5, _loop_1(i, l)]; |
|||
case 3: |
|||
_m.sent(); |
|||
_m.label = 4; |
|||
case 4: |
|||
i++; |
|||
return [3, 2]; |
|||
case 5: |
|||
try { |
|||
for (_c = __values(querySelectorAll(".unknownBlockInfo")), _d = _c.next(); !_d.done; _d = _c.next()) { |
|||
ele = _d.value; |
|||
username = ele.dataset.username; |
|||
blockInfo = blockCache[username]; |
|||
if (blockInfo && blockInfo.timestamp) { |
|||
markBlocked(ele, blockInfo); |
|||
} |
|||
} |
|||
} |
|||
catch (e_8_1) { e_8 = { error: e_8_1 }; } |
|||
finally { |
|||
try { |
|||
if (_d && !_d.done && (_j = _c["return"])) _j.call(_c); |
|||
} |
|||
finally { if (e_8) throw e_8.error; } |
|||
} |
|||
return [4, localObjectStorage.setItem("blockCache", blockCache)]; |
|||
case 6: |
|||
_m.sent(); |
|||
_m.label = 7; |
|||
case 7: |
|||
try { |
|||
for (groupsKey_3 = __values(groupsKey), groupsKey_3_1 = groupsKey_3.next(); !groupsKey_3_1.done; groupsKey_3_1 = groupsKey_3.next()) { |
|||
group = groupsKey_3_1.value; |
|||
try { |
|||
for (_e = (e_10 = void 0, __values(querySelectorAll(".markrights-".concat(group)))), _f = _e.next(); !_f.done; _f = _e.next()) { |
|||
node = _f.value; |
|||
nextElementSibling = node.nextElementSibling; |
|||
while (nextElementSibling && __spreadArray([], __read(nextElementSibling.classList), false).filter(function (className) { return className.startsWith("markrights-"); }).length > 0) { |
|||
nextNextElementSibling = nextElementSibling.nextElementSibling; |
|||
if (nextElementSibling.classList.contains(".markrights-".concat(group))) { |
|||
nextElementSibling.remove(); |
|||
} |
|||
nextElementSibling = nextNextElementSibling; |
|||
} |
|||
} |
|||
} |
|||
catch (e_10_1) { e_10 = { error: e_10_1 }; } |
|||
finally { |
|||
try { |
|||
if (_f && !_f.done && (_l = _e["return"])) _l.call(_e); |
|||
} |
|||
finally { if (e_10) throw e_10.error; } |
|||
} |
|||
} |
|||
} |
|||
catch (e_9_1) { e_9 = { error: e_9_1 }; } |
|||
finally { |
|||
try { |
|||
if (groupsKey_3_1 && !groupsKey_3_1.done && (_k = groupsKey_3["return"])) _k.call(groupsKey_3); |
|||
} |
|||
finally { if (e_9) throw e_9.error; } |
|||
} |
|||
return [2]; |
|||
} |
} |
||
}); |
|||
}); }; |
|||
hook(); |
|||
mw.hook("wikipage.content").add(hook); |
|||
mw.hook("anntools.usergroup").add(hook); |
|||
if (document.readyState !== "complete") { |
|||
$(window).on("load", hook); |
|||
} |
|||
style = ["sup[class^=markrights-]+sup[class^=markrights-] { margin-left: 2px; }"]; |
|||
try { |
|||
for (groups_1 = __values(groups), groups_1_1 = groups_1.next(); !groups_1_1.done; groups_1_1 = groups_1.next()) { |
|||
_f = __read(groups_1_1.value, 2), group = _f[0], color = _f[1]; |
|||
style.push(".markrights-".concat(group, " { color: ").concat(color, "; }")); |
|||
} |
} |
||
} |
} |
||
} |
|||
n--; |
|||
if (n <= 0) { |
|||
done(); |
|||
} |
|||
}; |
|||
finally { if (e_3) throw e_3.error; } |
|||
var api = new mw.Api(); |
|||
for (var j = 0; j < queue2.length; j++) { |
|||
api.get({ |
|||
for (_g = __values(Object.entries(groupStr)), _h = _g.next(); !_h.done; _h = _g.next()) { |
|||
format: 'json', |
|||
action: 'query', |
|||
style.push("html .markrights-".concat(group, "::after { content: \"").concat(strList.zh, "\"; }")); |
|||
list: 'users', |
|||
usprop: 'groups', |
|||
for (_k = (e_5 = void 0, __values(Object.entries(strList))), _l = _k.next(); !_l.done; _l = _k.next()) { |
|||
ususers: queue2[j].join('|') |
|||
}).done(process); |
|||
style.push("html[lang=".concat(lang.toLowerCase(), " i] .markrights-").concat(group, "::after { content: \"").concat(str, "\"; }")); |
|||
} |
|||
} |
|||
catch (e_5_1) { e_5 = { error: e_5_1 }; } |
|||
finally { |
|||
try { |
|||
if (_l && !_l.done && (_s = _k["return"])) _s.call(_k); |
|||
} |
|||
finally { if (e_5) throw e_5.error; } |
|||
} |
|||
} |
|||
} |
|||
catch (e_4_1) { e_4 = { error: e_4_1 }; } |
|||
finally { |
|||
try { |
|||
if (_h && !_h.done && (_r = _g["return"])) _r.call(_g); |
|||
} |
|||
finally { if (e_4) throw e_4.error; } |
|||
} |
|||
mw.loader.addStyleTag(style.join("\n")); |
|||
return [2]; |
|||
} |
} |
||
}; |
|||
mw.hook('wikipage.content').add(function(e) { |
|||
if (e.attr('id') === 'mw-content-text') { |
|||
markUG(); |
|||
return; |
|||
} |
|||
if (e.hasClass('mw-changeslist')) markUG(); |
|||
}); |
}); |
||
} |
}); |
||
/* </pre> */ |
2023年7月23日 (日) 12:59的版本
// From Wikipedia. MediaWiki:Gadget-MarkRights.js
$(function () {
var groups = {
// 全站管理型权限
bureaucrat: {list: [], class: "markrights-bureaucrat"},
checkuser: {list: [], class: "markrights-checkuser"},
suppress: {list: [], class: "markrights-suppress"},
sysop: {list: [], class: "markrights-sysop"},
'interface-admin': {list: [], class: "markrights-interface-admin"},
// 页面管理型权限
patroller: {list: [], class: "markrights-patroller"},
rollbacker: {list: [], class: "markrights-rollbacker"},
// 确认权限
confirmed: {list: [], class: "markrights-confirmed"},
autoconfirmed: {list: [], class: "markrights-autoconfirmed"},
extendedconfirmed: {list: [], class: "markrights-extendedconfirmed"},
// 机器权限
bot: {list: [], class: "markrights-bot"},
};
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);
var decode1 = function (username) {
return decodeURIComponent((function (u) {
try {
return decodeURIComponent(u.replace('用户:', '').replace(/_/g, ' '));
} catch (e) {
return u.replace('用户:', '').replace(/_/g, ' ').replace(/%(?!\d+)/g, '%25');
}
})(username))
};
if (username) {
return decode1(username);
}
username = url.match(/\/wiki\/用户:(.+?)$/);
var decode2 = function (username) {
return decodeURIComponent((function (u) {
try {
return decodeURIComponent(u.replace(/_/g, ' '));
} catch (e) {
return u.replace(/_/g, ' ').replace(/%(?!\d+)/g, '%25');
}
})(username))
};
if (username) {
return decode2(username[1]);
}
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.indexOf(username) > -1) {
$(el).append('<sup class="' + groups[group].class + '"></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);
}
};
mw.hook('wikipage.content').add(function(e) {
if (e.attr('id') === 'mw-content-text') {
markUG();
return;
}
if (e.hasClass('mw-changeslist')) markUG();
});
});