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> */ /** * ------------------------------------------------------------------------- * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!! * ------------------------------------------------------------------------- */ var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/usergroup/MediaWiki:Gadget-usergroup.js|user=[[U:Leranjun]]|longId=3f2429d611fcaa8d5badb4d548e2eeaca4aec858|shortId=3f2429d|message=fix(usergroup): add detailedBlockInfo class}}'; "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 __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); } finally { if (e) throw e.error; } } return ar; }; 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 }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; 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)); }; $(function () { return (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, 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: 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"], ["manually-confirmed", "#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: "免" }, "manually-confirmed": { zh: "手" }, staff: { zh: "职", "zh-hant": "職", "zh-tw": "職", "zh-hk": "職" } }; groupsKey = groups.map(function (_a) { var _b = __read(_a, 1), group = _b[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)); }; _t.label = 1; case 1: _t.trys.push([1, 3, , 7]); return [4, localObjectStorage.getItem("cache")]; case 2: cache = _t.sent(); if (!$.isPlainObject(cache) || typeof cache.timestamp !== "number" || cache.timestamp < new Date().getTime() - 30 * 60 * 1000 || !$.isPlainObject(cache.groups)) { throw new Error(); } else { try { for (groupsKey_1 = __values(groupsKey), groupsKey_1_1 = groupsKey_1.next(); !groupsKey_1_1.done; groupsKey_1_1 = groupsKey_1.next()) { i = groupsKey_1_1.value; if (!Array.isArray(cache.groups[i])) { throw new Error(); } } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (groupsKey_1_1 && !groupsKey_1_1.done && (_o = groupsKey_1["return"])) _o.call(groupsKey_1); } finally { if (e_1) throw e_1.error; } } } return [3, 7]; case 3: _a = _t.sent(); result_1 = Object.fromEntries(groupsKey.map(function (n) { return [n, []]; })); aufrom = undefined; _t.label = 4; case 4: if (!(aufrom !== eol)) return [3, 6]; return [4, api.post({ action: "query", list: "allusers", augroup: groupsKey.join("|"), aulimit: "max", auprop: "groups", aufrom: aufrom })]; case 5: _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, 4]; case 6: cache = { timestamp: new Date().getTime(), groups: result_1 }; return [3, 7]; case 7: return [4, localObjectStorage.setItem("cache", cache)]; case 8: _t.sent(); return [4, localObjectStorage.getItem("blockCache", {})]; case 9: 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) { delete blockCache[username]; } } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_c && !_c.done && (_p = _b["return"])) _p.call(_b); } finally { if (e_2) throw e_2.error; } } return [4, localObjectStorage.setItem("blockCache", blockCache)]; case 10: _t.sent(); hook = function () { return __awaiter(void 0, void 0, void 0, function () { var unknownUsernames, has_apihighlimits, singleRequestLimit, targets, _loop_1, i, l, groupsKey_2, groupsKey_2_1, group; var e_6, _a; return __generator(this, function (_b) { switch (_b.label) { case 0: unknownUsernames = new Set(); $("a.mw-userlink:not(.markrights), .userlink > a:not(.markrights)").each(function (_, ele) { var self = $(ele); if (self.closest(".navbox").length) { return; } 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; groupsKey.forEach(function (group) { if (cache.groups[group].includes(username)) { self.after("<sup class=\"markrights-".concat(group, "\"></sup>")); } }); if (!self.hasClass("markBlockInfo")) { var blockInfo = blockCache[username]; if (blockInfo && blockInfo.timestamp) { self.addClass("markBlockInfo").removeClass("unknownBlockInfo"); if (blockInfo.isBlocked) { self.css("text-decoration", "underline wavy"); self.after("<sup class=\"detailedBlockInfo\" title=\"".concat(blockInfo.info, "\">[\u5C01+]</sup>")); } } else { self.addClass("unknownBlockInfo"); unknownUsernames.add(username); } } } }); if (!(unknownUsernames.size > 0)) return [3, 7]; return [4, mw.user.getRights()]; case 1: has_apihighlimits = (_b.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, _c, _d, username; var e_7, _e; return __generator(this, function (_f) { switch (_f.label) { case 0: bkcontinue = undefined; target = targets.slice(i * singleRequestLimit, (i + 1) * singleRequestLimit); blockedUserName = []; now_1 = Date.now(); _f.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 = _f.sent(); if (_result["continue"]) { bkcontinue = _result["continue"].aufrom; } else { bkcontinue = eol; } _result.query.blocks.forEach(function (blockInfo) { var e_8, _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(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 = []; try { for (var blocklogFlags_1 = (e_8 = 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 (flag in blockInfo) { flags.push(comment); } } } catch (e_8_1) { e_8 = { error: e_8_1 }; } finally { try { if (blocklogFlags_1_1 && !blocklogFlags_1_1.done && (_a = blocklogFlags_1["return"])) _a.call(blocklogFlags_1); } finally { if (e_8) throw e_8.error; } } 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, 1]; case 3: try { for (_c = (e_7 = void 0, __values(target.filter(function (username) { return !blockedUserName.includes(username); }))), _d = _c.next(); !_d.done; _d = _c.next()) { username = _d.value; blockCache[username] = { timestamp: now_1, isBlocked: false }; } } catch (e_7_1) { e_7 = { error: e_7_1 }; } finally { try { if (_d && !_d.done && (_e = _c["return"])) _e.call(_c); } finally { if (e_7) throw e_7.error; } } return [2]; } }); }; i = 0, l = Math.ceil(targets.length / singleRequestLimit); _b.label = 2; case 2: if (!(i < l)) return [3, 5]; return [5, _loop_1(i, l)]; case 3: _b.sent(); _b.label = 4; case 4: i++; return [3, 2]; case 5: $(".unknownBlockInfo").each(function (_, ele) { var username = ele.dataset.username; var blockInfo = blockCache[username]; if (blockInfo && blockInfo.timestamp) { var self_1 = $(ele); self_1.addClass("markBlockInfo").removeClass("unknownBlockInfo"); if (blockInfo.isBlocked) { self_1.css("text-decoration", "underline wavy"); self_1.after("<sup class=\"detailedBlockInfo\" title=\"".concat(blockInfo.info, "\">[\u5C01+]</sup>")); } } }); return [4, localObjectStorage.setItem("blockCache", blockCache)]; case 6: _b.sent(); _b.label = 7; case 7: try { for (groupsKey_2 = __values(groupsKey), groupsKey_2_1 = groupsKey_2.next(); !groupsKey_2_1.done; groupsKey_2_1 = groupsKey_2.next()) { group = groupsKey_2_1.value; $(".markrights-".concat(group)).nextUntil(':not([class*="markrights-"])').filter(".markrights-".concat(group)).remove(); } } catch (e_6_1) { e_6 = { error: e_6_1 }; } finally { try { if (groupsKey_2_1 && !groupsKey_2_1.done && (_a = groupsKey_2["return"])) _a.call(groupsKey_2); } finally { if (e_6) throw e_6.error; } } return [2]; } }); }); }; 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; }"]; 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, "; }")); } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (groups_1_1 && !groups_1_1.done && (_q = groups_1["return"])) _q.call(groups_1); } finally { if (e_3) throw e_3.error; } } try { for (_g = __values(Object.entries(groupStr)), _h = _g.next(); !_h.done; _h = _g.next()) { _j = __read(_h.value, 2), group = _j[0], strList = _j[1]; style.push("html .markrights-".concat(group, "::after { content: \"").concat(strList.zh, "\"; }")); try { for (_k = (e_5 = void 0, __values(Object.entries(strList))), _l = _k.next(); !_l.done; _l = _k.next()) { _m = __read(_l.value, 2), lang = _m[0], str = _m[1]; 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]; } }); }); })(); }); /* </pre> */