“MediaWiki:Gadget-usergroup.js”的版本间的差异
星海-adminbot(讨论 | 贡献) (同步小工具) (1个标签:Bot) |
星海-interfacebot(讨论 | 贡献) 小 (跨站同步) (1个标签:Bot) |
||
第1行: | 第1行: | ||
− | / | + | /* <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"; | "use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
第36行: | 第43行: | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | 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) { | var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
第46行: | 第80行: | ||
return to.concat(ar || Array.prototype.slice.call(from)); | return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | }; | ||
− | |||
$(function () { return (function () { return __awaiter(void 0, void 0, void 0, function () { | $(function () { return (function () { return __awaiter(void 0, void 0, void 0, function () { | ||
− | var localObjectStorage, groups, groupStr, groupsKey, blocklogFlags, cache, api, eol, fixZero, toLocalTimeZoneString, | + | 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; |
− | return __generator(this, function ( | + | var e_1, _o, e_2, _p, e_3, _q, e_4, _r, e_5, _s; |
− | switch ( | + | return __generator(this, function (_t) { |
+ | switch (_t.label) { | ||
case 0: | case 0: | ||
localObjectStorage = new LocalObjectStorage("usergroup"); | localObjectStorage = new LocalObjectStorage("usergroup"); | ||
第67行: | 第101行: | ||
["flood", "#00acc1"], | ["flood", "#00acc1"], | ||
["ipblock-exempt", "#009688"], | ["ipblock-exempt", "#009688"], | ||
+ | ["manually-confirmed", "#009688"], | ||
["goodeditor", "#1aa179"], | ["goodeditor", "#1aa179"], | ||
].reverse(); | ].reverse(); | ||
第129行: | 第164行: | ||
"ipblock-exempt": { | "ipblock-exempt": { | ||
zh: "免" | zh: "免" | ||
+ | }, | ||
+ | "manually-confirmed": { | ||
+ | zh: "手" | ||
}, | }, | ||
staff: { | staff: { | ||
第138行: | 第176行: | ||
}; | }; | ||
groupsKey = groups.map(function (_a) { | groupsKey = groups.map(function (_a) { | ||
− | var group = | + | var _b = __read(_a, 1), group = _b[0]; |
return group; | return group; | ||
}); | }); | ||
第163行: | 第201行: | ||
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)); | 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: | case 1: | ||
− | + | _t.trys.push([1, 3, , 7]); | |
− | return [4 | + | return [4, localObjectStorage.getItem("cache")]; |
case 2: | case 2: | ||
− | cache = | + | cache = _t.sent(); |
if (!$.isPlainObject(cache) | if (!$.isPlainObject(cache) | ||
|| typeof cache.timestamp !== "number" || cache.timestamp < new Date().getTime() - 30 * 60 * 1000 | || typeof cache.timestamp !== "number" || cache.timestamp < new Date().getTime() - 30 * 60 * 1000 | ||
第175行: | 第213行: | ||
} | } | ||
else { | else { | ||
− | for ( | + | 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 | + | return [3, 7]; |
case 3: | case 3: | ||
− | _a = | + | _a = _t.sent(); |
result_1 = Object.fromEntries(groupsKey.map(function (n) { return [n, []]; })); | result_1 = Object.fromEntries(groupsKey.map(function (n) { return [n, []]; })); | ||
aufrom = undefined; | aufrom = undefined; | ||
− | + | _t.label = 4; | |
case 4: | case 4: | ||
− | if (!(aufrom !== eol)) return [3 | + | if (!(aufrom !== eol)) return [3, 6]; |
− | return [4 | + | return [4, api.post({ |
action: "query", | action: "query", | ||
list: "allusers", | list: "allusers", | ||
第199行: | 第246行: | ||
})]; | })]; | ||
case 5: | case 5: | ||
− | _result = | + | _result = _t.sent(); |
if (_result["continue"]) { | if (_result["continue"]) { | ||
aufrom = _result["continue"].aufrom; | aufrom = _result["continue"].aufrom; | ||
第217行: | 第264行: | ||
}); | }); | ||
}); | }); | ||
− | return [3 | + | return [3, 4]; |
case 6: | case 6: | ||
cache = { | cache = { | ||
第223行: | 第270行: | ||
groups: result_1 | groups: result_1 | ||
}; | }; | ||
− | return [3 | + | return [3, 7]; |
− | case 7: return [4 | + | case 7: return [4, localObjectStorage.setItem("cache", cache)]; |
case 8: | case 8: | ||
− | + | _t.sent(); | |
− | return [4 | + | return [4, localObjectStorage.getItem("blockCache", {})]; |
case 9: | case 9: | ||
− | blockCache = | + | blockCache = _t.sent(); |
now = Date.now(); | now = Date.now(); | ||
− | for (_b = | + | 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]; | ||
+ | } | ||
} | } | ||
} | } | ||
− | return [4 | + | 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: | case 10: | ||
− | + | _t.sent(); | |
hook = function () { return __awaiter(void 0, void 0, void 0, function () { | hook = function () { return __awaiter(void 0, void 0, void 0, function () { | ||
− | var unknownUsernames, has_apihighlimits, singleRequestLimit, targets, _loop_1, i, l, | + | var unknownUsernames, has_apihighlimits, singleRequestLimit, targets, _loop_1, i, l, groupsKey_2, groupsKey_2_1, group; |
− | return __generator(this, function ( | + | var e_6, _a; |
− | switch ( | + | return __generator(this, function (_b) { |
+ | switch (_b.label) { | ||
case 0: | case 0: | ||
unknownUsernames = new Set(); | unknownUsernames = new Set(); | ||
− | $("a.mw-userlink:not(.markrights)").each(function (_, ele) { | + | $("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"); | ele.classList.add("markrights"); | ||
var uri = new mw.Uri(ele.href); | var uri = new mw.Uri(ele.href); | ||
第259行: | 第320行: | ||
if (username) { | if (username) { | ||
ele.dataset.username = username; | ele.dataset.username = username; | ||
− | |||
groupsKey.forEach(function (group) { | groupsKey.forEach(function (group) { | ||
if (cache.groups[group].includes(username)) { | if (cache.groups[group].includes(username)) { | ||
− | + | self.after("<sup class=\"markrights-".concat(group, "\"></sup>")); | |
} | } | ||
}); | }); | ||
− | if (! | + | if (!self.hasClass("markBlockInfo")) { |
var blockInfo = blockCache[username]; | var blockInfo = blockCache[username]; | ||
if (blockInfo && blockInfo.timestamp) { | if (blockInfo && blockInfo.timestamp) { | ||
− | + | self.addClass("markBlockInfo").removeClass("unknownBlockInfo"); | |
if (blockInfo.isBlocked) { | if (blockInfo.isBlocked) { | ||
− | + | self.css("text-decoration", "underline wavy"); | |
− | + | self.after("<sup class=\"detailedBlockInfo\" title=\"".concat(blockInfo.info, "\">[\u5C01+]</sup>")); | |
} | } | ||
} | } | ||
else { | else { | ||
− | + | self.addClass("unknownBlockInfo"); | |
unknownUsernames.add(username); | unknownUsernames.add(username); | ||
} | } | ||
第281行: | 第341行: | ||
} | } | ||
}); | }); | ||
− | if (!(unknownUsernames.size > 0)) return [3 | + | if (!(unknownUsernames.size > 0)) return [3, 7]; |
− | return [4 | + | return [4, mw.user.getRights()]; |
case 1: | case 1: | ||
− | has_apihighlimits = ( | + | has_apihighlimits = (_b.sent()).includes("apihighlimits"); |
singleRequestLimit = has_apihighlimits ? 500 : 50; | singleRequestLimit = has_apihighlimits ? 500 : 50; | ||
− | targets = __spreadArray([], unknownUsernames.values(), | + | targets = __spreadArray([], __read(unknownUsernames.values()), false); |
_loop_1 = function (i, l) { | _loop_1 = function (i, l) { | ||
− | var bkcontinue, target, blockedUserName, now_1, _result, | + | var bkcontinue, target, blockedUserName, now_1, _result, _c, _d, username; |
− | return __generator(this, function ( | + | var e_7, _e; |
− | switch ( | + | return __generator(this, function (_f) { |
+ | switch (_f.label) { | ||
case 0: | case 0: | ||
bkcontinue = undefined; | bkcontinue = undefined; | ||
第296行: | 第357行: | ||
blockedUserName = []; | blockedUserName = []; | ||
now_1 = Date.now(); | now_1 = Date.now(); | ||
− | + | _f.label = 1; | |
case 1: | case 1: | ||
− | if (!(bkcontinue !== eol)) return [3 | + | if (!(bkcontinue !== eol)) return [3, 3]; |
− | return [4 | + | return [4, api.post({ |
action: "query", | action: "query", | ||
list: "blocks", | list: "blocks", | ||
第308行: | 第369行: | ||
})]; | })]; | ||
case 2: | case 2: | ||
− | _result = | + | _result = _f.sent(); |
if (_result["continue"]) { | if (_result["continue"]) { | ||
bkcontinue = _result["continue"].aufrom; | bkcontinue = _result["continue"].aufrom; | ||
第316行: | 第377行: | ||
} | } | ||
_result.query.blocks.forEach(function (blockInfo) { | _result.query.blocks.forEach(function (blockInfo) { | ||
+ | var e_8, _a; | ||
blockedUserName.push(blockInfo.user); | blockedUserName.push(blockInfo.user); | ||
var info = "".concat(blockInfo.id, " - \n \u88ABU:").concat(blockInfo.by).concat(wgULS("封禁", "封鎖"), "\u4E8E").concat(toLocalTimeZoneString(new Date(blockInfo.timestamp)), "\uFF0C"); | var info = "".concat(blockInfo.id, " - \n \u88ABU:").concat(blockInfo.by).concat(wgULS("封禁", "封鎖"), "\u4E8E").concat(toLocalTimeZoneString(new Date(blockInfo.timestamp)), "\uFF0C"); | ||
第329行: | 第391行: | ||
} | } | ||
var flags = []; | var flags = []; | ||
− | for (var | + | 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) { | if (flags.length === 0) { | ||
第346行: | 第417行: | ||
}; | }; | ||
}); | }); | ||
− | return [3 | + | return [3, 1]; |
case 3: | case 3: | ||
− | for ( | + | 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 | + | return [2]; |
} | } | ||
}); | }); | ||
}; | }; | ||
i = 0, l = Math.ceil(targets.length / singleRequestLimit); | i = 0, l = Math.ceil(targets.length / singleRequestLimit); | ||
− | + | _b.label = 2; | |
case 2: | case 2: | ||
− | if (!(i < l)) return [3 | + | if (!(i < l)) return [3, 5]; |
− | return [5 | + | return [5, _loop_1(i, l)]; |
case 3: | case 3: | ||
− | + | _b.sent(); | |
− | + | _b.label = 4; | |
case 4: | case 4: | ||
i++; | i++; | ||
− | return [3 | + | return [3, 2]; |
case 5: | case 5: | ||
$(".unknownBlockInfo").each(function (_, ele) { | $(".unknownBlockInfo").each(function (_, ele) { | ||
第375行: | 第455行: | ||
var blockInfo = blockCache[username]; | var blockInfo = blockCache[username]; | ||
if (blockInfo && blockInfo.timestamp) { | if (blockInfo && blockInfo.timestamp) { | ||
− | var | + | var self_1 = $(ele); |
− | + | self_1.addClass("markBlockInfo").removeClass("unknownBlockInfo"); | |
if (blockInfo.isBlocked) { | if (blockInfo.isBlocked) { | ||
− | + | self_1.css("text-decoration", "underline wavy"); | |
− | + | self_1.after("<sup class=\"detailedBlockInfo\" title=\"".concat(blockInfo.info, "\">[\u5C01+]</sup>")); | |
} | } | ||
} | } | ||
}); | }); | ||
− | return [4 | + | return [4, localObjectStorage.setItem("blockCache", blockCache)]; |
case 6: | case 6: | ||
− | + | _b.sent(); | |
− | + | _b.label = 7; | |
case 7: | case 7: | ||
− | for ( | + | 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 | + | return [2]; |
} | } | ||
}); | }); | ||
第401行: | 第490行: | ||
$(window).on("load", hook); | $(window).on("load", hook); | ||
style = ["sup[class^=markrights-]+sup[class^=markrights-] { margin-left: 2px; }"]; | style = ["sup[class^=markrights-]+sup[class^=markrights-] { margin-left: 2px; }"]; | ||
− | for (_f = 0, | + | try { |
− | _g = | + | 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")); | mw.loader.addStyleTag(style.join("\n")); | ||
− | return [2 | + | return [2]; |
} | } | ||
}); | }); | ||
}); })(); }); | }); })(); }); | ||
− | / | + | |
+ | /* </pre> */ |
2022年9月6日 (二) 01:35的版本
/* <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> */