MediaWiki:Gadget-abusefilter33test.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/abusefilter33test/MediaWiki:Gadget-abusefilter33test.js|user=[[U:Leranjun]]|longId=0995688a9b3ce15e3071d163b00975665c387c6a|shortId=0995688|message=fix(abusefilter33test): change URL match rule}}'; "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 __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)); }; 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."); }; $(function () { return (function () { return __awaiter(void 0, void 0, void 0, function () { var getLogVar, timestampVar, user_name, article_prefixedtext, filter, symbolEnter, api, pTable, progress, __details, _details, _rules, _stringRules, stringRules, _regexRules, regexRules, _loop_1, _details_1, _details_1_1, details, e_1; var e_2, _a; var _b, _c, _d, _e, _f; return __generator(this, function (_g) { switch (_g.label) { case 0: if (!mw.config.get("wgUserGroups").includes("sysop") && !mw.config.get("wgUserGroups").includes("staff")) { return [2]; } if (mw.config.get("wgCanonicalSpecialPageName") !== "AbuseLog") { return [2]; } getLogVar = function (varName) { return $(".mw-abuselog-details-".concat(varName, " .mw-abuselog-var-value .mw-abuselog-var-value")).text(); }; timestampVar = getLogVar("timestamp"); user_name = getLogVar("user_name"); article_prefixedtext = getLogVar("article_prefixedtext"); filter = (_f = (_e = (_d = (_c = (_b = __spreadArray([], __read(document.querySelectorAll('a[href*="/Special:%E6%BB%A5%E7%94%A8%E8%BF%87%E6%BB%A4%E5%99%A8/"]')), false).filter(function (_a) { var href = _a.href; return /%E6%BB%A5%E7%94%A8%E8%BF%87%E6%BB%A4%E5%99%A8\/[1-9]\d*$/.test(href); })) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.href) === null || _d === void 0 ? void 0 : _d.match) === null || _e === void 0 ? void 0 : _e.call(_d, /[1-9]\d*$/)) === null || _f === void 0 ? void 0 : _f[0]; if (timestampVar.length === 0 || user_name.length === 0 || article_prefixedtext.length === 0 || typeof filter !== "string") { return [2]; } symbolEnter = function (str) { return typeof str === "string" ? str.replace(/\n/g, "↵") : str; }; api = new mw.Api(); pTable = $("<table/>"); $("#mw-content-text > fieldset > p:first").after(pTable.css("width", "100%").addClass("wikitable")); pTable.empty().append("<tbody><tr><td style=\"text-align: center;\">加载中(<span id=\"abusefiltertest-progress\">0</span>/2)……</td></tr></tbody>"); progress = $("#abusefiltertest-progress"); _g.label = 1; case 1: _g.trys.push([1, 4, , 5]); return [4, api.post({ action: "query", list: "abuselog", afluser: user_name, afltitle: article_prefixedtext, aflprop: "details", aflfilter: +filter })]; case 2: __details = (_g.sent()).query.abuselog; if (__details.length === 0) { throw "无法找到对应用户名和页面标题的滥用过滤器日志"; } progress.text(1); _details = Array.from(new Map(__details.filter(function (_a) { var timestamp = _a.details.timestamp; return timestampVar === timestamp; }).map(function (n) { return [n.new_wikitext, n]; })).values()); if (_details.length === 0) { console.info(__details); throw "无法找到对应时间戳的滥用过滤器日志"; } progress.text(2); return [4, api.post({ action: "query", list: "abusefilters", abfstartid: +filter, abfendid: +filter, abfprop: "pattern" })]; case 3: _rules = (_g.sent()).query.abusefilters[0].pattern.replace(/\r/g, ""); _stringRules = Array.from(_rules.match(/\/\* string rule start \*\/[\s\S]+?(?=\/\* string rule end \*\/)/g) || []).map(function (r) { return r.replace(/\/\* regex rule start \*\//g, "").split("\n"); }).flat().map(function (r) { return r.replace(/^ *"?/, "").replace(/"?,? *$/, ""); }).filter(function (r) { return r !== ""; }); stringRules = new Set(_stringRules); _regexRules = Array.from(_rules.match(/\/\* regex rule start \*\/[\s\S]+?(?=\/\* regex rule end \*\/)/g) || []).map(function (r) { return r.replace(/\/\* regex rule start \*\//g, "").split("\n") || []; }).flat().map(function (r) { return r.replace(/^ *"?/, "").replace(/"?,? *$/, ""); }).filter(function (r) { return r !== ""; }); regexRules = new Set(_regexRules); if (stringRules.size + regexRules.size === 0) { throw "无法找到符合格式的规则"; } _loop_1 = function (details) { var e_3, _h, e_4, _j; var added_lines = details.added_lines || details.new_wikitext; var result = []; var table = $("<table/>").css("width", "100%").addClass("wikitable abusefiltertest").hide(); pTable.after(table); var _loop_2 = function (sr) { if (added_lines.includes(sr)) { var splits_1 = added_lines.split(sr); splits_1.forEach(function (str, i) { if (i === splits_1.length - 1) { return; } var next = splits_1[i + 1]; var start = Math.max(0, str.length - 20); var end = Math.min(next.length, 20); result.push({ isRegexp: false, rule: sr, before: str.substring(start, start + 20), string: sr, after: next.substring(0, end), start: start }); }); } }; try { for (var _k = (e_3 = void 0, __values(stringRules.values())), _l = _k.next(); !_l.done; _l = _k.next()) { var sr = _l.value; _loop_2(sr); } } catch (e_3_1) { e_3 = { error: e_3_1 }; } finally { try { if (_l && !_l.done && (_h = _k["return"])) _h.call(_k); } finally { if (e_3) throw e_3.error; } } var _loop_3 = function (rr) { var regex = RegExp(".{0,20}".concat(rr, ".{0,20}"), "ig"); var findstring = RegExp(rr, "ig"); if (regex.test(added_lines)) { var splits = added_lines.match(regex); var lastFromIndex_1 = 0; splits.forEach(function (str) { var string = str.match(findstring)[0]; var split = str.split(string); var before = split[0]; var after = split.slice(1).join(string); var start = added_lines.indexOf(string, lastFromIndex_1); lastFromIndex_1 = start + string.length; result.push({ isRegex: true, rule: rr, before: before, string: string, after: after, start: start }); }); } }; try { for (var _m = (e_4 = void 0, __values(regexRules.values())), _o = _m.next(); !_o.done; _o = _m.next()) { var rr = _o.value; _loop_3(rr); } } catch (e_4_1) { e_4 = { error: e_4_1 }; } finally { try { if (_o && !_o.done && (_j = _m["return"])) _j.call(_m); } finally { if (e_4) throw e_4.error; } } table.empty(); if (result.length > 0) { table.append("<caption style=\"font-weight: 700;\">\u547D\u4E2D\u9632\u6EE5\u7528\u8FC7\u6EE4\u5668".concat(filter, "\u7684\u5185\u5BB9</caption><tr><th style=\"text-align: right;\">\u89C4\u5219\uFF08\u8BF7\u52FF\u6CC4\u6F0F\uFF01\uFF01\uFF01\uFF09</th><th style=\"text-align: left;\">\u547D\u4E2D\u5B57\u7B26\u4E32\u4E0A\u4E0B\u6587</th></tr>")); result.sort(function (_a, _b) { var a = _a.start; var b = _b.start; return a - b; }); var results_1 = []; result.forEach(function (r) { if (results_1.filter(function (_a) { var isRegex = _a.isRegex, start = _a.start; return isRegex === r.isRegex && start === r.start; }).length === 0) { results_1.push(r); } }); console.info(results_1); results_1.forEach(function (_a) { var isRegex = _a.isRegex, rule = _a.rule, before = _a.before, string = _a.string, after = _a.after, start = _a.start; var tr = $("<tr/>"); var label = $("<td/>"); var ruleCode = $("<code/>"); ruleCode.text(rule); label.addClass("mw-label"); label.text(isRegex ? "正则表达式" : "字符串"); label.append(symbolEnter(ruleCode)).append(":"); tr.append(label); var input = $("<td/>"); input.addClass("mw-input"); var beforeSpan = $("<span/>"); beforeSpan.text(symbolEnter(before)).css({ padding: "0 .25em" }); var strSpan = $("<span/>"); strSpan.text(symbolEnter(string)).css({ "font-weight": "700", "text-decoration": "underline", padding: "0 .25em" }); var afterSpan = $("<span/>"); afterSpan.text(symbolEnter(after)).css({ padding: "0 .25em" }); if (before.length >= 20) { var beforeDot = $("<span/>"); beforeDot.text("[".concat(start, "] \u2026\u2026")).css({ "padding-right": ".25em" }); input.append(beforeDot); } input.append(beforeSpan).append(strSpan).append(afterSpan); if (after.length >= 20) { var afterDot = $("<span/>"); afterDot.text("……").css({ "padding-left": ".25em" }); input.append(afterDot); } tr.append(input); table.append(tr); }); } else { table.empty().append("<tbody><tr><td style=\"text-align: center;\">现有规则没有匹配项……</td></tr></tbody>"); } }; try { for (_details_1 = __values(_details), _details_1_1 = _details_1.next(); !_details_1_1.done; _details_1_1 = _details_1.next()) { details = _details_1_1.value.details; _loop_1(details); } } catch (e_2_1) { e_2 = { error: e_2_1 }; } finally { try { if (_details_1_1 && !_details_1_1.done && (_a = _details_1["return"])) _a.call(_details_1); } finally { if (e_2) throw e_2.error; } } pTable.hide(); $(".abusefiltertest").show(); return [3, 5]; case 4: e_1 = _g.sent(); console.info("abusefiltertest", e_1); $(".abusefiltertest").remove(); pTable.empty(); if (filter === 33) { pTable.append("<tbody><tr><td style=\"text-align: ".concat(typeof e_1 === "string" ? "center" : "left", ";\">\u53D1\u751F\u9519\u8BEF\uFF1A").concat(typeof e_1 === "string" ? e_1 : "".concat(e_1, " ").concat(e_1.stack.split("\n")[1].trim()), "</td></tr></tbody>")); } return [3, 5]; case 5: return [2]; } }); }); })(); }); /* </pre> */