MediaWiki:Gadget-usergroup.js
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
// <pre> "use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; 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; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { 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; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } 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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { 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)); }; // https://zh.moegirl.org.cn/MediaWiki:Gadget-usergroup.js $(function () { return (function () { return __awaiter(void 0, void 0, void 0, function () { var localObjectStorage, groups, groupStr, groupsKey, blocklogFlags, cache, api, eol, fixZero, toLocalTimeZoneString, _i, groupsKey_1, i, _a, result_1, aufrom, _result, blockCache, now, _b, _c, _d, username, _e, timestamp, isBlocked, hook, style, _f, groups_1, _g, group, color, _h, _j, _k, group, strList, _l, _m, _o, lang, str; return __generator(this, function (_p) { switch (_p.label) { case 0: localObjectStorage = new LocalObjectStorage("usergroup"); groups = [ ["staff", "#198754"], ["bureaucrat", "#6610f2"], ["checkuser", "#673ab7"], ["suppress", "#9c27b0"], ["sysop", "#ec407a"], ["patroller", "#f44336"], ["honoredmaintainer", "#ff9800"], ["interface-admin", "#3f51b5"], ["scripteditor", "#1e88e5"], ["techeditor", "#039be5"], ["bot", "#00acc1"], ["flood", "#00acc1"], ["ipblock-exempt", "#009688"], ["goodeditor", "#1aa179"], ].reverse(); groupStr = { bureaucrat: { zh: "行" }, checkuser: { zh: "查" }, suppress: { zh: "监", "zh-hant": "監", "zh-tw": "監", "zh-hk": "監" }, sysop: { zh: "管" }, patroller: { zh: "巡" }, bot: { zh: "机", "zh-hant": "機", "zh-tw": "機", "zh-hk": "機" }, flood: { zh: "机", "zh-hant": "機", "zh-tw": "機", "zh-hk": "機" }, goodeditor: { zh: "优", "zh-hant": "優", "zh-tw": "優", "zh-hk": "優" }, honoredmaintainer: { zh: "荣", "zh-hant": "榮", "zh-tw": "榮", "zh-hk": "榮" }, "interface-admin": { zh: "界", "zh-hant": "介", "zh-tw": "介", "zh-hk": "介" }, scripteditor: { zh: "脚", "zh-hant": "指", "zh-tw": "指", "zh-hk": "指" }, techeditor: { zh: "技" }, "ipblock-exempt": { zh: "免" }, staff: { zh: "职", "zh-hant": "職", "zh-tw": "職", "zh-hk": "職" } }; groupsKey = groups.map(function (_a) { var group = _a[0]; return group; }); blocklogFlags = Object.entries({ anononly: wgULS("仅封禁匿名用户", "僅封鎖匿名使用者", null, null, "僅封鎖匿名用戶"), nocreate: wgULS("阻止创建新账号", "防止建立新帳號"), autoblock: wgULS("自动封禁该用户最后使用的IP地址,以及其随后试图用于编辑的所有IP地址", "自動封鎖最後使用的IP位址,以及在這之後嘗試登入的所有IP位址。"), noemail: wgULS("阻止用户发送电子邮件", "阻止使用者發送電子郵件", null, null, "阻止用戶發送電子郵件"), nousertalk: wgULS("阻止用户在封禁期间编辑自己的讨论页", "阻止使用者在封鎖期間編輯自己的對話頁", null, null, "阻止用戶在封鎖期間編輯自己的討論頁"), hiddenname: wgULS("隐藏用户名", "隱藏使用者名稱", null, null, "隱藏用戶名") }); api = new mw.Api(); eol = Symbol(); fixZero = function (n, l) { if (l === void 0) { l = 2; } var r = "".concat(n); while (r.length < l) { r = "0".concat(r); } return r; }; 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)); }; _p.label = 1; case 1: _p.trys.push([1, 3, , 7]); return [4 /*yield*/, localObjectStorage.getItem("cache")]; case 2: cache = _p.sent(); if (!$.isPlainObject(cache) || typeof cache.timestamp !== "number" || cache.timestamp < new Date().getTime() - 30 * 60 * 1000 || !$.isPlainObject(cache.groups)) { throw new Error(); } else { for (_i = 0, groupsKey_1 = groupsKey; _i < groupsKey_1.length; _i++) { i = groupsKey_1[_i]; if (!Array.isArray(cache.groups[i])) { throw new Error(); } } } return [3 /*break*/, 7]; case 3: _a = _p.sent(); result_1 = Object.fromEntries(groupsKey.map(function (n) { return [n, []]; })); aufrom = undefined; _p.label = 4; case 4: if (!(aufrom !== eol)) return [3 /*break*/, 6]; return [4 /*yield*/, api.post({ action: "query", list: "allusers", augroup: groupsKey.join("|"), aulimit: "max", auprop: "groups", aufrom: aufrom })]; case 5: _result = _p.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 /*break*/, 4]; case 6: cache = { timestamp: new Date().getTime(), groups: result_1 }; return [3 /*break*/, 7]; case 7: return [4 /*yield*/, localObjectStorage.setItem("cache", cache)]; case 8: _p.sent(); return [4 /*yield*/, localObjectStorage.getItem("blockCache", {})]; case 9: blockCache = _p.sent(); now = Date.now(); for (_b = 0, _c = Object.entries(blockCache); _b < _c.length; _b++) { _d = _c[_b], 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) { delete blockCache[username]; } } return [4 /*yield*/, localObjectStorage.setItem("blockCache", blockCache)]; case 10: _p.sent(); hook = function () { return __awaiter(void 0, void 0, void 0, function () { var unknownUsernames, has_apihighlimits, singleRequestLimit, targets, _loop_1, i, l, _i, groupsKey_2, group; return __generator(this, function (_a) { switch (_a.label) { case 0: unknownUsernames = new Set(); $("a.mw-userlink:not(.markrights)").each(function (_, ele) { ele.classList.add("markrights"); var uri = new mw.Uri(ele.href); var username; var path = decodeURI(uri.path); if (/^\/User:[^/=%]+/.test(path)) { username = path.match(/^\/User:([^/=%]+)/)[1].replace(/_/g, " "); } else if (/^User:[^/=%]+/.test(uri.query.title)) { username = uri.query.title.match(/^User:([^/=%]+)/)[1].replace(/_/g, " "); } if (username) { ele.dataset.username = username; var self_1 = $(ele); groupsKey.forEach(function (group) { if (cache.groups[group].includes(username)) { self_1.after("<sup class=\"markrights-".concat(group, "\"></sup>")); } }); if (!self_1.hasClass("markBlockInfo")) { var blockInfo = blockCache[username]; if (blockInfo && blockInfo.timestamp) { self_1.addClass("markBlockInfo").removeClass("unknownBlockInfo"); if (blockInfo.isBlocked) { self_1.css("text-decoration", "underline wavy"); self_1.after("<sup title=\"".concat(blockInfo.info, "\">[\u5C01+]</sup>")); } } else { self_1.addClass("unknownBlockInfo"); unknownUsernames.add(username); } } } }); if (!(unknownUsernames.size > 0)) return [3 /*break*/, 7]; return [4 /*yield*/, mw.user.getRights()]; case 1: has_apihighlimits = (_a.sent()).includes("apihighlimits"); singleRequestLimit = has_apihighlimits ? 500 : 50; targets = __spreadArray([], unknownUsernames.values(), true); _loop_1 = function (i, l) { var bkcontinue, target, blockedUserName, now_1, _result, _b, _c, username; return __generator(this, function (_d) { switch (_d.label) { case 0: bkcontinue = undefined; target = targets.slice(i * singleRequestLimit, (i + 1) * singleRequestLimit); blockedUserName = []; now_1 = Date.now(); _d.label = 1; case 1: if (!(bkcontinue !== eol)) return [3 /*break*/, 3]; return [4 /*yield*/, api.post({ action: "query", list: "blocks", bkusers: target, bklimit: "max", bkprop: "id|user|by|timestamp|expiry|reason|flags", bkcontinue: bkcontinue })]; case 2: _result = _d.sent(); if (_result["continue"]) { bkcontinue = _result["continue"].aufrom; } else { bkcontinue = eol; } _result.query.blocks.forEach(function (blockInfo) { 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(wgULS("持续", "持續"), "\u81F3").concat(toLocalTimeZoneString(new Date(blockInfo.expiry))); } else { info += wgULS("持续时间为无限期", "持續時間為不限期"); } info += "\n ".concat(wgULS("额外限制", "額外限制"), "\uFF1A"); if (!("allowusertalk" in blockInfo)) { blockInfo.nousertalk = true; } var flags = []; for (var _i = 0, blocklogFlags_1 = blocklogFlags; _i < blocklogFlags_1.length; _i++) { var _a = blocklogFlags_1[_i], flag = _a[0], comment = _a[1]; if (flag in blockInfo) { flags.push(comment); } } if (flags.length === 0) { flags.push(wgULS("(无)", "(無)")); } info += flags.join("、"); info += "\n ".concat(wgULS("理由", "緣由"), "\uFF1A").concat(blockInfo.reason); blockCache[blockInfo.user] = { timestamp: now_1, isBlocked: true, info: info }; }); return [3 /*break*/, 1]; case 3: for (_b = 0, _c = target.filter(function (username) { return !blockedUserName.includes(username); }); _b < _c.length; _b++) { username = _c[_b]; blockCache[username] = { timestamp: now_1, isBlocked: false }; } return [2 /*return*/]; } }); }; i = 0, l = Math.ceil(targets.length / singleRequestLimit); _a.label = 2; case 2: if (!(i < l)) return [3 /*break*/, 5]; return [5 /*yield**/, _loop_1(i, l)]; case 3: _a.sent(); _a.label = 4; case 4: i++; return [3 /*break*/, 2]; case 5: $(".unknownBlockInfo").each(function (_, ele) { var username = ele.dataset.username; var blockInfo = blockCache[username]; if (blockInfo && blockInfo.timestamp) { var self_2 = $(ele); self_2.addClass("markBlockInfo").removeClass("unknownBlockInfo"); if (blockInfo.isBlocked) { self_2.css("text-decoration", "underline wavy"); self_2.after("<sup title=\"".concat(blockInfo.info, "\">[\u5C01+]</sup>")); } } }); return [4 /*yield*/, localObjectStorage.setItem("blockCache", blockCache)]; case 6: _a.sent(); _a.label = 7; case 7: for (_i = 0, groupsKey_2 = groupsKey; _i < groupsKey_2.length; _i++) { group = groupsKey_2[_i]; $(".markrights-".concat(group)).nextUntil(':not([class*="markrights-"])').filter(".markrights-".concat(group)).remove(); } return [2 /*return*/]; } }); }); }; hook(); mw.hook("wikipage.content").add(hook); mw.hook("anntools.usergroup").add(hook); $(window).on("load", hook); style = ["sup[class^=markrights-]+sup[class^=markrights-] { margin-left: 2px; }"]; for (_f = 0, groups_1 = groups; _f < groups_1.length; _f++) { _g = groups_1[_f], group = _g[0], color = _g[1]; style.push(".markrights-".concat(group, " { color: ").concat(color, "; }")); } for (_h = 0, _j = Object.entries(groupStr); _h < _j.length; _h++) { _k = _j[_h], group = _k[0], strList = _k[1]; style.push("html .markrights-".concat(group, "::after { content: \"").concat(strList.zh, "\"; }")); for (_l = 0, _m = Object.entries(strList); _l < _m.length; _l++) { _o = _m[_l], lang = _o[0], str = _o[1]; style.push("html[lang=".concat(lang.toLowerCase(), " i] .markrights-").concat(group, "::after { content: \"").concat(str, "\"; }")); } } mw.loader.addStyleTag(style.join("\n")); return [2 /*return*/]; } }); }); })(); }); // </pre>