Difference between revisions of "MediaWiki:Gadget-registerToDelete.js"
m (跨站同步) (Tag: Bot) |
|||
Line 1: | Line 1: | ||
− | / | + | /* <pre> */ |
− | / | + | /** |
− | + | * ------------------------------------------------------------------------- | |
− | + | * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!! | |
− | // | + | * ------------------------------------------------------------------------- |
+ | */ | ||
+ | var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/registerToDelete/MediaWiki:Gadget-registerToDelete.js|user=[[U:AnnAngela]]|longId=4c19895c652c248353b0896406ec338edadd2ec3|shortId=4c19895|message=refactor: Use spread syntax}}'; | ||
+ | |||
"use strict"; | "use strict"; | ||
var __extends = (this && this.__extends) || (function () { | var __extends = (this && this.__extends) || (function () { | ||
Line 20: | Line 23: | ||
}; | }; | ||
})(); | })(); | ||
+ | var __assign = (this && this.__assign) || function () { | ||
+ | __assign = Object.assign || function(t) { | ||
+ | for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
+ | s = arguments[i]; | ||
+ | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
+ | t[p] = s[p]; | ||
+ | } | ||
+ | return t; | ||
+ | }; | ||
+ | return __assign.apply(this, arguments); | ||
+ | }; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
Line 55: | Line 69: | ||
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 __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
Line 65: | Line 95: | ||
return to.concat(ar || Array.prototype.slice.call(from)); | return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | }; | ||
− | $(function () { | + | $(function () { |
− | + | try { | |
− | + | if ($(".noarticletext")[0] || $(".will2Be2Deleted")[0] || mw.config.get("wgRevisionId") === 0 || !mw.config.get("wgUserGroups").includes("patroller") && !(new URL(location.href).searchParams.get("AnnTools-debug") || "").split("|").includes("registerToDelete")) { | |
− | + | return; | |
− | + | } | |
− | + | var $body_1 = $("body"); | |
− | + | $("#mw-notification-area").appendTo($body_1); | |
− | + | var loadReason_1 = false; | |
+ | var FFDWindow = (function (_super) { | ||
+ | __extends(FFDWindow, _super); | ||
+ | function FFDWindow(config) { | ||
+ | var _this = _super.call(this, config) || this; | ||
+ | _this.storage = config.data.storage; | ||
+ | return _this; | ||
+ | } | ||
+ | FFDWindow.prototype.initialize = function () { | ||
+ | _super.prototype.initialize.call(this); | ||
+ | this.panelLayout = new OO.ui.PanelLayout({ | ||
+ | scrollable: false, | ||
+ | expanded: false, | ||
+ | padded: true | ||
+ | }); | ||
+ | this.reasonsDropdown = new OO.ui.DropdownInputWidget({ | ||
+ | options: [{ | ||
+ | data: "", | ||
+ | label: "其他(请自行说明理由)" | ||
+ | }, { | ||
+ | data: "", | ||
+ | disabled: true, | ||
+ | label: "加载中……" | ||
+ | }] | ||
+ | }); | ||
+ | this.detailsText = new OO.ui.TextInputWidget(); | ||
+ | this.dbCheckbox = new OO.ui.CheckboxInputWidget(); | ||
+ | this.enterCheckbox = new OO.ui.CheckboxInputWidget({ | ||
+ | selected: this.storage.getItem("enterToSubmit") | ||
+ | }); | ||
+ | this.reasonsDropdownMenu = this.reasonsDropdown.dropdownWidget.getMenu(); | ||
+ | var reasonsField = new OO.ui.FieldLayout(this.reasonsDropdown, { | ||
+ | label: wgULS("挂删理由", "掛删緣由"), | ||
+ | align: "top" | ||
+ | }); | ||
+ | var detailsField = new OO.ui.FieldLayout(this.detailsText, { | ||
+ | label: wgULS("详情", "詳情"), | ||
+ | align: "top" | ||
+ | }); | ||
+ | var dbField = new OO.ui.FieldLayout(this.dbCheckbox, { | ||
+ | label: wgULS("讨论版申请", "討論版申請"), | ||
+ | align: "inline" | ||
+ | }); | ||
+ | var enterField = new OO.ui.FieldLayout(this.enterCheckbox, { | ||
+ | label: wgULS("理由详情按回车提交(浏览器级设置)", "緣由詳情按回車鍵提交(瀏覽器級設置)"), | ||
+ | align: "inline" | ||
+ | }); | ||
+ | this.panelLayout.$element.append(reasonsField.$element, detailsField.$element, dbField.$element, enterField.$element); | ||
+ | this.reasonsDropdownMenu.connect(this, { toggle: "dropdownToggle" }); | ||
+ | this.detailsText.connect(this, { enter: "onEnter" }); | ||
+ | this.enterCheckbox.connect(this, { change: "setStorage" }); | ||
+ | this.$body.append(this.panelLayout.$element); | ||
+ | }; | ||
+ | FFDWindow.prototype.updateReasons = function (reasons) { | ||
+ | this.reasonsDropdown.setOptions(__spreadArray([{ | ||
+ | data: "", | ||
+ | label: "其他(请自行说明理由)" | ||
+ | }], __read(reasons), false)); | ||
+ | }; | ||
+ | FFDWindow.prototype.setStorage = function (selected) { | ||
+ | this.storage.setItem("enterToSubmit", selected); | ||
+ | }; | ||
+ | FFDWindow.prototype.onEnter = function () { | ||
+ | if (this.enterCheckbox.isSelected()) { | ||
+ | this.executeAction("submit"); | ||
} | } | ||
− | + | }; | |
− | + | FFDWindow.prototype.dropdownToggle = function (visible) { | |
− | + | var _this = this; | |
− | + | if (visible) { | |
− | function | + | var newHeight_1 = parseFloat(this.$frame.css("height")) + 300; |
− | + | this.withoutSizeTransitions(function () { | |
− | + | _this.$frame.css("height", newHeight_1); | |
− | + | _this.reasonsDropdownMenu.clip(); | |
− | _this. | + | }); |
− | + | } | |
− | + | else { | |
− | + | this.updateSize(); | |
− | + | } | |
− | + | }; | |
− | + | FFDWindow.prototype.getBodyHeight = function () { | |
− | + | return this.panelLayout.$element.outerHeight(true); | |
− | + | }; | |
− | + | FFDWindow.prototype.getReadyProcess = function (data) { | |
− | + | var _this = this; | |
− | + | return _super.prototype.getReadyProcess.call(this, data).next(function () { | |
− | + | _this.reasonsDropdown.focus(); | |
− | + | }, this); | |
− | + | }; | |
− | + | FFDWindow.prototype.getActionProcess = function (action) { | |
− | + | var _this = this; | |
− | + | var dfd = $.Deferred(); | |
− | + | if (action === "cancel") { | |
− | + | return new OO.ui.Process(function () { | |
− | + | _this.close({ action: action }); | |
− | + | }, this); | |
− | + | } | |
− | + | else if (action === "submit") { | |
− | + | return new OO.ui.Process(function () { | |
− | + | _this.reason = _this.reasonsDropdown.getValue(); | |
− | + | _this.detail = _this.detailsText.getValue(); | |
− | + | if (!_this.reason && !_this.detail) { | |
− | + | dfd.reject(new OO.ui.Error("请填写理由或详情")); | |
− | + | return dfd.promise(); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
− | + | _this.reason = "".concat(_this.dbCheckbox.isSelected() ? "讨论版申请:" : "").concat(_this.reason ? "".concat(_this.reason).concat(_this.detail ? "\uFF1A".concat(_this.detail) : "") : _this.detail); | |
− | + | _this.flagTemplate().then(function () { | |
− | + | _this.close({ action: action }); | |
− | + | mw.notify(wgULS("即将刷新……", "即將刷新……"), { | |
− | + | title: wgULS("挂删成功", "掛删成功"), | |
− | + | type: "success", | |
− | + | tag: "lr-ffd" | |
− | |||
− | |||
− | |||
}); | }); | ||
− | + | dfd.resolve(); | |
− | + | setTimeout(function () { return location.reload(); }, 730); | |
− | + | })["catch"](function (e) { | |
− | + | console.error("[FlagForDeletion] Error:", e); | |
− | + | dfd.reject(new OO.ui.Error(e)); | |
− | + | }); | |
− | + | return dfd.promise(); | |
− | + | }, this); | |
− | + | } | |
− | + | return _super.prototype.getActionProcess.call(this, action); | |
− | + | }; | |
− | . | + | FFDWindow.prototype.flagTemplate = function () { |
− | + | return __awaiter(this, void 0, void 0, function () { | |
− | + | var api, template, d; | |
− | + | return __generator(this, function (_b) { | |
− | + | switch (_b.label) { | |
− | + | case 0: | |
− | + | api = new mw.Api(); | |
− | + | template = /^en/.test(location.hostname) ? "Awaiting_deletion" : "即将删除"; | |
− | + | return [4, api.postWithToken("csrf", { | |
− | + | action: "edit", | |
− | + | format: "json", | |
− | + | title: mw.config.get("wgPageName"), | |
− | + | text: "<noinclude>{{".concat(template, "|1=").concat(this.reason, "|user=").concat(mw.config.get("wgUserName"), "}}</noinclude>"), | |
− | + | summary: "\u6302\u5220\uFF1A".concat(this.reason), | |
− | + | nocreate: true, | |
− | + | watchlist: "nochange", | |
− | if ( | + | tags: "Automation tool" |
− | + | })]; | |
− | + | case 1: | |
+ | d = _b.sent(); | ||
+ | if (d.error) { | ||
+ | throw d.error.code; | ||
} | } | ||
− | + | return [2]; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
}); | }); | ||
− | return FFDWindow; | + | }); |
− | + | }; | |
− | + | FFDWindow.static = __assign(__assign({}, _super.static), { name: "lr-ffd", title: wgULS("挂删", "掛删"), actions: [ | |
− | + | { | |
− | + | action: "cancel", | |
− | + | label: "取消", | |
− | + | flags: ["safe", "close", "destructive"] | |
− | + | }, | |
− | + | { | |
− | if ( | + | action: "submit", |
− | + | label: wgULS("确认", "確認"), | |
− | + | flags: ["primary", "progressive"] | |
− | + | }, | |
− | + | ] }); | |
− | + | return FFDWindow; | |
+ | }(OO.ui.ProcessDialog)); | ||
+ | var storage = new LocalObjectStorage("AnnTools-registerToDelete"); | ||
+ | var windowManager_1 = new OO.ui.WindowManager(); | ||
+ | $body_1.append(windowManager_1.$element); | ||
+ | var ffdDialog_1 = new FFDWindow({ | ||
+ | size: "medium", | ||
+ | data: { storage: storage } | ||
+ | }); | ||
+ | windowManager_1.addWindows([ffdDialog_1]); | ||
+ | $(mw.util.addPortletLink("p-cactions", "#", wgULS("挂删", "掛删"), "ca-lr-ffd", "".concat(wgULS("挂删本页", "掛删本頁"), "[alt-shift-d]")), "d").on("click", function (e) { return __awaiter(void 0, void 0, void 0, function () { | ||
+ | var html, container, result_1, getReason_1; | ||
+ | return __generator(this, function (_b) { | ||
+ | switch (_b.label) { | ||
+ | case 0: | ||
+ | e.preventDefault(); | ||
+ | windowManager_1.openWindow(ffdDialog_1); | ||
+ | $body_1.css("overflow", "auto"); | ||
+ | if (!(loadReason_1 === false)) return [3, 2]; | ||
+ | loadReason_1 = true; | ||
+ | return [4, new mw.Api().post({ | ||
+ | action: "parse", | ||
+ | page: mw.config.get("wgNamespaceNumber") === mw.config.get("wgNamespaceIds").file ? "MediaWiki:Filedelete-reason-dropdown" : "MediaWiki:Deletereason-dropdown", | ||
+ | prop: "text" | ||
+ | })]; | ||
+ | case 1: | ||
+ | html = (_b.sent()).parse.text["*"]; | ||
+ | container = $("<div>"); | ||
+ | container.html(html); | ||
+ | result_1 = []; | ||
+ | getReason_1 = function (ele) { | ||
+ | result_1.push({ | ||
+ | data: ele.innerText.trim(), | ||
+ | label: ele.innerText.trim() | ||
}); | }); | ||
− | + | }; | |
− | } | + | container.children(".mw-parser-output").children("ul").children("li").each(function (_, ele) { |
− | + | var $ele = $(ele); | |
− | + | if ($ele.children("ul").length > 0) { | |
− | var | + | result_1.push({ |
− | + | optgroup: $ele.clone().find("*").remove().end().text().trim() | |
− | + | }); | |
− | + | $ele.children("ul").children("li").each(function (_, e) { return getReason_1(e); }); | |
− | + | } | |
− | + | else { | |
− | + | getReason_1(ele); | |
− | + | } | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
}); | }); | ||
− | + | ffdDialog_1.updateReasons(result_1); | |
− | + | _b.label = 2; | |
− | + | case 2: return [2]; | |
− | + | } | |
− | + | }); | |
− | + | }); }); | |
− | + | } | |
− | + | catch (e) { | |
− | }) | + | var parseError = function (errLike, space) { |
− | + | if (space === void 0) { | |
− | + | space = 4; | |
− | + | } | |
− | + | return JSON.stringify(errLike, function (_, v) { | |
− | + | if (v instanceof Error) { | |
− | + | var stack = []; | |
− | + | if (v.stack) { | |
− | + | stack.push.apply(stack, v.stack.split("\n").map(function (n) { return n.trim(); }).filter(function (n) { var _a; return ((_a = n === null || n === void 0 ? void 0 : n.length) !== null && _a !== void 0 ? _a : -1) > 0; })); | |
− | + | } | |
− | + | var keys = Object.keys(v).filter(function (key) { return !(key in Error.prototype); }); | |
− | if ( | + | if (keys.length) { |
− | space | + | stack.push(JSON.stringify(Object.fromEntries(keys.map(function (key) { return [key, v[key]]; })), null, space)); |
} | } | ||
− | + | return stack.join("\n").trim() || ""; | |
− | + | } | |
− | + | return v; | |
− | + | }, space).replace(/^"(.*)"$/, "$1"); | |
− | + | }; | |
− | + | oouiDialog.alert("错误信息:<br>" + oouiDialog.sanitize(parseError(e)), { | |
− | + | title: "挂删工具发生错误" | |
− | + | }); | |
− | + | console.error("[FlagForDeletion] Setup error:", e); | |
− | + | } | |
− | + | }); | |
− | + | ||
− | + | /* </pre> */ | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | / |
Latest revision as of 18:06, 5 September 2022
/* <pre> */ /** * ------------------------------------------------------------------------- * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!! * ------------------------------------------------------------------------- */ var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/registerToDelete/MediaWiki:Gadget-registerToDelete.js|user=[[U:AnnAngela]]|longId=4c19895c652c248353b0896406ec338edadd2ec3|shortId=4c19895|message=refactor: Use spread syntax}}'; "use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; 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)); }; $(function () { try { if ($(".noarticletext")[0] || $(".will2Be2Deleted")[0] || mw.config.get("wgRevisionId") === 0 || !mw.config.get("wgUserGroups").includes("patroller") && !(new URL(location.href).searchParams.get("AnnTools-debug") || "").split("|").includes("registerToDelete")) { return; } var $body_1 = $("body"); $("#mw-notification-area").appendTo($body_1); var loadReason_1 = false; var FFDWindow = (function (_super) { __extends(FFDWindow, _super); function FFDWindow(config) { var _this = _super.call(this, config) || this; _this.storage = config.data.storage; return _this; } FFDWindow.prototype.initialize = function () { _super.prototype.initialize.call(this); this.panelLayout = new OO.ui.PanelLayout({ scrollable: false, expanded: false, padded: true }); this.reasonsDropdown = new OO.ui.DropdownInputWidget({ options: [{ data: "", label: "其他(请自行说明理由)" }, { data: "", disabled: true, label: "加载中……" }] }); this.detailsText = new OO.ui.TextInputWidget(); this.dbCheckbox = new OO.ui.CheckboxInputWidget(); this.enterCheckbox = new OO.ui.CheckboxInputWidget({ selected: this.storage.getItem("enterToSubmit") }); this.reasonsDropdownMenu = this.reasonsDropdown.dropdownWidget.getMenu(); var reasonsField = new OO.ui.FieldLayout(this.reasonsDropdown, { label: wgULS("挂删理由", "掛删緣由"), align: "top" }); var detailsField = new OO.ui.FieldLayout(this.detailsText, { label: wgULS("详情", "詳情"), align: "top" }); var dbField = new OO.ui.FieldLayout(this.dbCheckbox, { label: wgULS("讨论版申请", "討論版申請"), align: "inline" }); var enterField = new OO.ui.FieldLayout(this.enterCheckbox, { label: wgULS("理由详情按回车提交(浏览器级设置)", "緣由詳情按回車鍵提交(瀏覽器級設置)"), align: "inline" }); this.panelLayout.$element.append(reasonsField.$element, detailsField.$element, dbField.$element, enterField.$element); this.reasonsDropdownMenu.connect(this, { toggle: "dropdownToggle" }); this.detailsText.connect(this, { enter: "onEnter" }); this.enterCheckbox.connect(this, { change: "setStorage" }); this.$body.append(this.panelLayout.$element); }; FFDWindow.prototype.updateReasons = function (reasons) { this.reasonsDropdown.setOptions(__spreadArray([{ data: "", label: "其他(请自行说明理由)" }], __read(reasons), false)); }; FFDWindow.prototype.setStorage = function (selected) { this.storage.setItem("enterToSubmit", selected); }; FFDWindow.prototype.onEnter = function () { if (this.enterCheckbox.isSelected()) { this.executeAction("submit"); } }; FFDWindow.prototype.dropdownToggle = function (visible) { var _this = this; if (visible) { var newHeight_1 = parseFloat(this.$frame.css("height")) + 300; this.withoutSizeTransitions(function () { _this.$frame.css("height", newHeight_1); _this.reasonsDropdownMenu.clip(); }); } else { this.updateSize(); } }; FFDWindow.prototype.getBodyHeight = function () { return this.panelLayout.$element.outerHeight(true); }; FFDWindow.prototype.getReadyProcess = function (data) { var _this = this; return _super.prototype.getReadyProcess.call(this, data).next(function () { _this.reasonsDropdown.focus(); }, this); }; FFDWindow.prototype.getActionProcess = function (action) { var _this = this; var dfd = $.Deferred(); if (action === "cancel") { return new OO.ui.Process(function () { _this.close({ action: action }); }, this); } else if (action === "submit") { return new OO.ui.Process(function () { _this.reason = _this.reasonsDropdown.getValue(); _this.detail = _this.detailsText.getValue(); if (!_this.reason && !_this.detail) { dfd.reject(new OO.ui.Error("请填写理由或详情")); return dfd.promise(); } _this.reason = "".concat(_this.dbCheckbox.isSelected() ? "讨论版申请:" : "").concat(_this.reason ? "".concat(_this.reason).concat(_this.detail ? "\uFF1A".concat(_this.detail) : "") : _this.detail); _this.flagTemplate().then(function () { _this.close({ action: action }); mw.notify(wgULS("即将刷新……", "即將刷新……"), { title: wgULS("挂删成功", "掛删成功"), type: "success", tag: "lr-ffd" }); dfd.resolve(); setTimeout(function () { return location.reload(); }, 730); })["catch"](function (e) { console.error("[FlagForDeletion] Error:", e); dfd.reject(new OO.ui.Error(e)); }); return dfd.promise(); }, this); } return _super.prototype.getActionProcess.call(this, action); }; FFDWindow.prototype.flagTemplate = function () { return __awaiter(this, void 0, void 0, function () { var api, template, d; return __generator(this, function (_b) { switch (_b.label) { case 0: api = new mw.Api(); template = /^en/.test(location.hostname) ? "Awaiting_deletion" : "即将删除"; return [4, api.postWithToken("csrf", { action: "edit", format: "json", title: mw.config.get("wgPageName"), text: "<noinclude>{{".concat(template, "|1=").concat(this.reason, "|user=").concat(mw.config.get("wgUserName"), "}}</noinclude>"), summary: "\u6302\u5220\uFF1A".concat(this.reason), nocreate: true, watchlist: "nochange", tags: "Automation tool" })]; case 1: d = _b.sent(); if (d.error) { throw d.error.code; } return [2]; } }); }); }; FFDWindow.static = __assign(__assign({}, _super.static), { name: "lr-ffd", title: wgULS("挂删", "掛删"), actions: [ { action: "cancel", label: "取消", flags: ["safe", "close", "destructive"] }, { action: "submit", label: wgULS("确认", "確認"), flags: ["primary", "progressive"] }, ] }); return FFDWindow; }(OO.ui.ProcessDialog)); var storage = new LocalObjectStorage("AnnTools-registerToDelete"); var windowManager_1 = new OO.ui.WindowManager(); $body_1.append(windowManager_1.$element); var ffdDialog_1 = new FFDWindow({ size: "medium", data: { storage: storage } }); windowManager_1.addWindows([ffdDialog_1]); $(mw.util.addPortletLink("p-cactions", "#", wgULS("挂删", "掛删"), "ca-lr-ffd", "".concat(wgULS("挂删本页", "掛删本頁"), "[alt-shift-d]")), "d").on("click", function (e) { return __awaiter(void 0, void 0, void 0, function () { var html, container, result_1, getReason_1; return __generator(this, function (_b) { switch (_b.label) { case 0: e.preventDefault(); windowManager_1.openWindow(ffdDialog_1); $body_1.css("overflow", "auto"); if (!(loadReason_1 === false)) return [3, 2]; loadReason_1 = true; return [4, new mw.Api().post({ action: "parse", page: mw.config.get("wgNamespaceNumber") === mw.config.get("wgNamespaceIds").file ? "MediaWiki:Filedelete-reason-dropdown" : "MediaWiki:Deletereason-dropdown", prop: "text" })]; case 1: html = (_b.sent()).parse.text["*"]; container = $("<div>"); container.html(html); result_1 = []; getReason_1 = function (ele) { result_1.push({ data: ele.innerText.trim(), label: ele.innerText.trim() }); }; container.children(".mw-parser-output").children("ul").children("li").each(function (_, ele) { var $ele = $(ele); if ($ele.children("ul").length > 0) { result_1.push({ optgroup: $ele.clone().find("*").remove().end().text().trim() }); $ele.children("ul").children("li").each(function (_, e) { return getReason_1(e); }); } else { getReason_1(ele); } }); ffdDialog_1.updateReasons(result_1); _b.label = 2; case 2: return [2]; } }); }); }); } catch (e) { var parseError = function (errLike, space) { if (space === void 0) { space = 4; } return JSON.stringify(errLike, function (_, v) { if (v instanceof Error) { var stack = []; if (v.stack) { stack.push.apply(stack, v.stack.split("\n").map(function (n) { return n.trim(); }).filter(function (n) { var _a; return ((_a = n === null || n === void 0 ? void 0 : n.length) !== null && _a !== void 0 ? _a : -1) > 0; })); } var keys = Object.keys(v).filter(function (key) { return !(key in Error.prototype); }); if (keys.length) { stack.push(JSON.stringify(Object.fromEntries(keys.map(function (key) { return [key, v[key]]; })), null, space)); } return stack.join("\n").trim() || ""; } return v; }, space).replace(/^"(.*)"$/, "$1"); }; oouiDialog.alert("错误信息:<br>" + oouiDialog.sanitize(parseError(e)), { title: "挂删工具发生错误" }); console.error("[FlagForDeletion] Setup error:", e); } }); /* </pre> */