MediaWiki:Gadget-blockEnhance.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/blockEnhance/MediaWiki:Gadget-blockEnhance.js|user=[[U:AnnAngela]]|longId=4f769b86c99bf278bee8d120937a50b49682e4e2|shortId=4f769b8|message=refactor: Stop using jQuery deprecated event shorthand methods}}'; "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 }; } }; $(function () { if (mw.config.get("wgCanonicalSpecialPageName") !== "Block") { return; } var showResults = function (size, cidr) { $("#mw-checkuser-cidr-res").val(cidr); $("#mw-checkuser-ipnote").text(size); }; var updateCIDRresult = function () { var form = document.getElementById("mw-checkuser-cidrform"); if (!form) { return; } form.style.display = "inline"; var iplist = document.getElementById("mw-checkuser-iplist"); if (!iplist) { return; } var text = iplist.value; var ips; if (text.indexOf("\n") !== -1) { ips = text.split("\n"); } else if (text.indexOf("\t") !== -1) { ips = text.split("\t"); } else if (text.indexOf(",") !== -1) { ips = text.split(","); } else if (text.indexOf(" - ") !== -1) { ips = text.split(" - "); } else if (text.indexOf("-") !== -1) { ips = text.split("-"); } else if (text.indexOf(" ") !== -1) { ips = text.split(" "); } else { ips = text.split(";"); } var binPrefix = 0, prefixCidr = 0, prefix = "", foundV4 = false, foundV6 = false, ipCount, blocs, isOverflow; for (var i = 0; i < ips.length; i++) { var addy = ips[i].replace(/^\s*|\s*$/, ""); var ipV4 = mw.util.isIPv4Address(addy, true); var ipV6 = mw.util.isIPv6Address(addy, true); var ipCidr = addy.match(/^(.*)(?:\/(\d+))?$/); var bin = ""; var x = 0, z = 0, start = 0, end = 0, ip = void 0, cidr = void 0, bloc = void 0, binBlock = void 0; if (ipV4) { foundV4 = !0; if (foundV6) { prefix = ""; break; } ip = ipCidr[1]; cidr = ipCidr[2] ? ipCidr[2] : null; blocs = ip.split("."); for (x = 0; x < blocs.length; x++) { bloc = parseInt(blocs[x], 10); binBlock = bloc.toString(2); while (binBlock.length < 8) { binBlock = "0".concat(binBlock); } bin += binBlock; } prefix = ""; if (cidr) { bin = bin.substring(0, cidr); } if (binPrefix === 0) { binPrefix = bin; } else { for (x = 0; x < binPrefix.length; x++) { if (bin[x] === undefined || binPrefix[x] !== bin[x]) { binPrefix = binPrefix.substring(0, x); break; } } } prefixCidr = binPrefix.length; if (prefixCidr < 16) { isOverflow = true; } for (z = 0; z <= 3; z++) { bloc = 0; start = z * 8; end = start + 7; for (x = start; x <= end; x++) { if (binPrefix[x] === undefined) { break; } bloc += parseInt(binPrefix[x], 10) * Math.pow(2, (end - x)); } prefix += z === 3 ? bloc : "".concat(bloc, "."); } ipCount = Math.pow(2, (32 - prefixCidr)); if (prefixCidr === 32) { prefixCidr = !1; } } else if (ipV6) { foundV6 = !0; if (foundV4) { prefix = ""; break; } ip = ipCidr[1]; cidr = ipCidr[2] ? ipCidr[2] : null; var abbrevs = ip.match(/::/g); if (abbrevs && abbrevs.length > 0) { var colons = ip.match(/:/g); var needed = 7 - (colons.length - 2); var insert = ""; while (needed > 1) { insert += ":0"; needed--; } ip = ip.replace("::", "".concat(insert, ":")); if (ip[0] === ":") { ip = "0".concat(ip); } } blocs = ip.split(":"); for (x = 0; x <= 7; x++) { bloc = blocs[x] ? blocs[x] : "0"; var intBlock = parseInt(bloc, 16); binBlock = intBlock.toString(2); while (binBlock.length < 16) { binBlock = "0".concat(binBlock); } bin += binBlock; } prefix = ""; if (cidr) { bin = bin.substring(0, cidr); } if (binPrefix === 0) { binPrefix = bin; } else { for (x = 0; x < binPrefix.length; x++) { if (bin[x] === undefined || binPrefix[x] !== bin[x]) { binPrefix = binPrefix.substring(0, x); break; } } } prefixCidr = binPrefix.length; if (prefixCidr < 32) { isOverflow = true; } for (z = 0; z <= 7; z++) { bloc = 0; start = z * 16; end = start + 15; for (x = start; x <= end; x++) { if (binPrefix[x] === undefined) { break; } bloc += parseInt(binPrefix[x], 10) * Math.pow(2, (end - x)); } bloc = bloc.toString(16); prefix += z === 7 ? bloc : "".concat(bloc, ":"); } ipCount = Math.pow(2, (128 - prefixCidr)); if (prefixCidr === 128) { prefixCidr = !1; } } } if (prefix !== "") { var full = prefix; if (prefixCidr !== false) { full += "/".concat(prefixCidr); } showResults("~".concat(ipCount).concat(isOverflow ? " [OVERFLOW]" : ""), full); } else { showResults("?", ""); } }; $("#mw-content-text form").prepend('<fieldset id="mw-checkuser-cidrform" class="checkuser-show" style="display: block; float: right;"><legend>检查指定IP列表的共同区段</legend><textarea id="mw-checkuser-iplist" dir="ltr" rows="5" cols="50"></textarea><br>通用CIDR: <input name="mw-checkuser-cidr-res" size="35" value="" id="mw-checkuser-cidr-res"> <strong id="mw-checkuser-ipnote">?</strong></fieldset><style>#mw-content-text form .oo-ui-fieldLayout:before, #mw-content-text form .oo-ui-fieldLayout:after {clear: left;}'); updateCIDRresult(); $("#mw-checkuser-iplist").on("keyup click", updateCIDRresult); var autoBlock = OO.ui.infuse($("#mw-input-wpAutoBlock")); if ($("input#mw-input-wpConfirm, input[name=wpConfirm]").val() === "") { autoBlock.setSelected(false); } if (mw.config.get("wgUserGroups").includes("patroller")) { autoBlock.setDisabled(true); } var flag = false; var wpTarget = $('[name="wpTarget"]'); var powerfulUserList = []; var submitButton = OO.ui.infuse($('#mw-content-text [type="submit"]').parent()); var submitForm = submitButton.$element.closest("form"); var submitButtonText = submitButton.getLabel(); submitButton.setDisabled(true).setLabel(wgULS("正在加载中……", "正在載入中……")); submitForm.on("submit.warning", function (e) { return __awaiter(void 0, void 0, void 0, function () { var _a; return __generator(this, function (_b) { switch (_b.label) { case 0: e.preventDefault(); e.stopImmediatePropagation(); if (flag === false) { return [2]; } _a = powerfulUserList.includes(wpTarget.val()); if (!_a) return [3, 2]; return [4, oouiDialog.confirm("\u60A8\u8981".concat(wgULS("封禁的用户", "封鎖的使用者", null, null, "封鎖的用戶"), "\u3010").concat(wpTarget.val(), "\u3011").concat(wgULS("持有“封禁”和“自我解封”权限,您的封禁很可能无效且有可能违反封禁方针,您是否要继续?", "持有「封鎖」和「自我解封」權限,您的封鎖很可能無效且有可能違反封鎖方針,您是否要繼續?")), { title: wgULS("封禁辅助工具", "封鎖輔助工具") })]; case 1: _a = !(_b.sent()); _b.label = 2; case 2: if (_a) { return [2]; } submitForm.off("submit.warning").trigger("submit"); return [2]; } }); }); }); new mw.Api({ timeout: 5000 }).post({ action: "query", list: "allusers", aurights: "block|unblockself", aulimit: "max", auprop: "rights" }).then(function (result) { powerfulUserList = result.query.allusers.filter(function (au) { return au.rights.includes("block") && au.rights.includes("unblockself"); }).map(function (au) { return au.name; }); submitButton.setDisabled(false).setLabel(submitButtonText); flag = true; }, function (error) { console.error(error); submitButton.after("<span class=\"error\">".concat(wgULS("无法获取持有“封禁”和“自我解封”权限的用户列表,请谨慎操作", "無法獲取持有「封鎖」和「自我解封」權限的使用者列表,請謹慎操作", null, null, "無法獲取持有「封鎖」和「自我解封」權限的用戶列表,請謹慎操作"), "\u3002</span>")); submitButton.setDisabled(true).setLabel(submitButtonText); flag = true; }); }); /* </pre> */