「MediaWiki:Gadget-rollback-summary.js」の版間の差分

提供: 萌えっ娘百科事典
移動先: 案内検索
(bot work)
(タグ: Bot)
 
(跨站同步)
(タグ: Bot)
 
(他の1人の利用者による、間の1版が非表示)
1行目: 1行目:
$(function() {
+
/* <pre> */
 +
/**
 +
* -------------------------------------------------------------------------
 +
* !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 +
* -------------------------------------------------------------------------
 +
*/
 +
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/rollback-summary/MediaWiki:Gadget-rollback-summary.js|user=[[U:AnnAngela]]|longId=919932be0afb735fe504f53f5b4df6f83d8c6bd8|shortId=919932b|message=init}}';
 +
 
 +
"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 () {
 +
    var wgUserGroups = mw.config.get("wgUserGroups", []);
 +
    if (!wgUserGroups.includes("sysop") && !wgUserGroups.includes("patroller")) {
 +
        return;
 +
    }
 
     mw.config.set({
 
     mw.config.set({
         'wgRollbacking': false,
+
         wgRollbacking: false,
         'wgRollbackTool': 'inited'
+
         wgRollbackTool: "inited"
 
     });
 
     });
     $.fn.extend({
+
     var possibleError = {
         getParamValue: function getParamValue(param) {
+
        alreadyrolled: wgULS("已被回退", "已被還原"),
            var href = this.data('href');
+
        onlyauthor: wgULS("该页面只有一位编辑者参与编辑,无法回退", "該頁面只有一位編輯者參與編輯,無法還原"),
            if (!href) return undefined;
+
        missingparams: wgULS('必须要有参数"title"或参数"pageid"之一', '必須存在參數"title"或參數"pageid"之一'),
             return mw.util.getParamValue(param, href);
+
        notitle: wgULS('参数"title"必须被设置', '參數"title"必須被設置'),
 +
        notoken: wgULS('参数"token"必须被设置', '參數"token"必須被設置'),
 +
         nouser: wgULS('参数"user"必须被设置', '參數"user"必須被設置')
 +
    };
 +
    var loop = function (_, ele) {
 +
        var self = $(ele);
 +
        self.data("href", self.attr("href")).removeAttr("href")
 +
            .attr("title", "".concat(ele.title, "\uFF08\u542F\u7528\u81EA\u5B9A\u4E49\u6458\u8981\uFF09")).css("cursor", "pointer").append("<sup>+</sup>");
 +
        if ($(".ns-special")[0] && self.text().includes("10")) {
 +
             self.parent().text(wgULS("[超过10次的编辑]", "[超過10次的編輯]")).attr("title", "超过10次的编辑请使用撤销功能,以便检查差异(自定义摘要小工具)");
 
         }
 
         }
     });
+
        ele.onmouseover = $.noop;
     $('.mw-rollback-link a').each(loop);
+
        ele.onmouseout = $.noop;
     $(document.body).on('click', function(event) {
+
        ele.onmousedown = $.noop;
         if (!$(event.target).is('.mw-rollback-link a')) return true;
+
     };
        var self = $(event.target),
+
    var exit = function () {
            parent = self.parent();
+
        var rbcount = $("#rbcount");
        if (!self.data('href')) loop.bind(event.target)();
+
        var count = 3;
        if (!parent.find(self)[0]) return false;
+
        setInterval(function () {
        if (mw.config.get('wgRollbacking')) return true;
+
            if (--count === 0) {
        var rollbackSummary = prompt('回退操作的编辑摘要【xxx//Rollback】\n【空白则使用默认回退摘要】\n【取消则不进行回退】:');
+
                window.location.reload();
        if (rollbackSummary !== null) $.ajax({
+
            }
            type: 'POST',
+
            rbcount.text(count > 0 ? count : "0");
            url: 'https://zh.moegirl.org/api.php',
+
        }, 1000);
            beforeSend: function() {
+
    };
                self.replaceWith('<span id="rbing"><img src="https://static.mengniang.org/common/d/d1/Windows_10_loading.gif" style="height: 1em; margin-top: -.25em;">正在回退中……</span>');
+
     $(".mw-rollback-link a").each(loop);
                self = $('#rbing');
+
    var api = new mw.Api();
                $('.mw-rollback-link a').not(self).css({
+
     $(document.body).on("click", function (event) { return __awaiter(void 0, void 0, void 0, function () {
                    color: '#aaa',
+
        var target, self, parent, rollbackSummary, uri, rbing_1, summary;
                    "text-decoration": 'none'
+
         return __generator(this, function (_a) {
                });
+
            switch (_a.label) {
                mw.config.set('wgRollbacking', true);
+
                case 0:
            },
+
                    target = event.target;
            data: {
+
                    if (!$(target).is(".mw-rollback-link a")) {
                title: self.getParamValue('title'),
+
                        return [2, true];
                user: self.getParamValue('from'),
+
                    }
                summary: rollbackSummary ? rollbackSummary + ' //Rollback' : '//Rollback',
+
                    self = $(target);
                token: self.getParamValue('token'),
+
                    parent = self.parent();
                action: 'rollback',
+
                    if (!self.data("href")) {
                format: 'json'
+
                        loop(null, target);
            },
+
                    }
            error: function(eO, eM, eC) {
+
                    if (!parent.find(self)[0]) {
                eC = eM ? eC + '(' + eM + ')' : eC;
+
                        return [2, false];
                self.css('color', 'red').html('错误:' + eC + '。将在<span id="rbcount">3</span>秒内刷新');
+
                    }
                exit();
+
                    if (mw.config.get("wgRollbacking")) {
            },
+
                        return [2, false];
            success: function(d) {
+
                    }
                if (d.error) self.css('color', 'red').html('错误:已被回退。将在<span id="rbcount">3</span>秒内刷新');
+
                    return [4, oouiDialog.prompt("<ul><li>".concat(wgULS("回退操作的编辑摘要", "還原操作的編輯摘要"), "\uFF1A<code>xxx//Rollback</code></li><li>").concat(wgULS("空白则使用默认回退摘要", "留空則使用默認的還原摘要"), "\uFF0C").concat(wgULS("取消则不进行回退", "取消則不進行還原"), "</li></ul><hr>").concat(wgULS("请输入回退摘要", "請輸入還原摘要"), "\uFF1A"), {
                else self.css('color', 'green').html('成功!将在<span id="rbcount">3</span>秒内刷新');
+
                            title: "回退小工具",
                exit();
+
                            size: "medium",
 +
                            required: false
 +
                        })];
 +
                case 1:
 +
                    rollbackSummary = _a.sent();
 +
                    if (rollbackSummary !== null) {
 +
                        uri = new mw.Uri(self.data("href"));
 +
                        self.replaceWith("<span id=\"rbing\"><img src=\"https://img.moegirl.org.cn/common/d/d1/Windows_10_loading.gif\" style=\"height: 1em; margin-top: -.25em;\">".concat(wgULS("正在回退中", "正在還原"), "\u2026\u2026</span>"));
 +
                        rbing_1 = $("#rbing");
 +
                        $(".mw-rollback-link a").not(rbing_1).css({
 +
                            color: "#aaa",
 +
                            "text-decoration": "none"
 +
                        });
 +
                        mw.config.set("wgRollbacking", true);
 +
                        summary = rollbackSummary ? "".concat(rollbackSummary, " //Rollback") : "//Rollback";
 +
                        if (uri.query.from) {
 +
                            api.post({
 +
                                title: uri.query.title,
 +
                                user: uri.query.from,
 +
                                summary: summary,
 +
                                token: uri.query.token,
 +
                                action: "rollback",
 +
                                format: "json"
 +
                            }).then(function () {
 +
                                rbing_1.css("color", "green").html("\u6210\u529F\uFF01".concat(wgULS("将在", "將在"), "<span id=\"rbcount\">3</span>\u79D2").concat(wgULS("内刷新", "內重新整理")));
 +
                                exit();
 +
                            }, function (e) {
 +
                                var errorText = e instanceof Error ? "".concat(e, " ").concat(e.stack.split("\n")[1].trim()) : $.isPlainObject(e) ? JSON.stringify(e) : typeof e === "string" && e in possibleError ? possibleError[e] : "".concat(e);
 +
                                rbing_1.css("color", "red").html("".concat(wgULS("错误", "錯誤"), "\uFF1A").concat(errorText, "\u3002").concat(wgULS("将在", "將在"), "<span id=\"rbcount\">3</span>").concat(wgULS("秒内刷新", "秒內重新整理")));
 +
                                exit();
 +
                            });
 +
                        }
 +
                        else {
 +
                            uri.query.summary = summary;
 +
                            window.open(uri.toString(), "_self");
 +
                        }
 +
                    }
 +
                    return [2, false];
 
             }
 
             }
 
         });
 
         });
        return false;
+
     }); });
     });
+
     new Image().src = "https://img.moegirl.org.cn/common/d/d1/Windows_10_loading.gif";
    function exit() {
 
        window.setInterval(function() {
 
            var count = +$('#rbcount').text();
 
            if (count-- == 1) window.location.reload();
 
            $('#rbcount').text(count > 0 ? count : '0');
 
        }, 1000);
 
     }
 
    function loop() {
 
        var self = $(this);
 
        self.data('href', self.attr('href')).removeAttr('href') //取消拖动链接回退
 
            .attr('title', this.title + '(启用自定义摘要)').css('cursor', 'pointer').append('<sup>+</sup>');
 
        if ($('.ns-special')[0] && self.text().indexOf('10') != -1) self.parent().text('[超过10次的编辑]').attr('title', '超过10次的编辑请使用撤销功能,以便检查差异(自定义摘要小工具)');
 
    }
 
 
});
 
});
 +
 +
/* </pre> */

2022年9月6日 (火) 02:54時点における最新版

/* <pre> */
/**
 * -------------------------------------------------------------------------
 * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 * -------------------------------------------------------------------------
 */
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/rollback-summary/MediaWiki:Gadget-rollback-summary.js|user=[[U:AnnAngela]]|longId=919932be0afb735fe504f53f5b4df6f83d8c6bd8|shortId=919932b|message=init}}';

"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 () {
    var wgUserGroups = mw.config.get("wgUserGroups", []);
    if (!wgUserGroups.includes("sysop") && !wgUserGroups.includes("patroller")) {
        return;
    }
    mw.config.set({
        wgRollbacking: false,
        wgRollbackTool: "inited"
    });
    var possibleError = {
        alreadyrolled: wgULS("已被回退", "已被還原"),
        onlyauthor: wgULS("该页面只有一位编辑者参与编辑,无法回退", "該頁面只有一位編輯者參與編輯,無法還原"),
        missingparams: wgULS('必须要有参数"title"或参数"pageid"之一', '必須存在參數"title"或參數"pageid"之一'),
        notitle: wgULS('参数"title"必须被设置', '參數"title"必須被設置'),
        notoken: wgULS('参数"token"必须被设置', '參數"token"必須被設置'),
        nouser: wgULS('参数"user"必须被设置', '參數"user"必須被設置')
    };
    var loop = function (_, ele) {
        var self = $(ele);
        self.data("href", self.attr("href")).removeAttr("href")
            .attr("title", "".concat(ele.title, "\uFF08\u542F\u7528\u81EA\u5B9A\u4E49\u6458\u8981\uFF09")).css("cursor", "pointer").append("<sup>+</sup>");
        if ($(".ns-special")[0] && self.text().includes("10")) {
            self.parent().text(wgULS("[超过10次的编辑]", "[超過10次的編輯]")).attr("title", "超过10次的编辑请使用撤销功能,以便检查差异(自定义摘要小工具)");
        }
        ele.onmouseover = $.noop;
        ele.onmouseout = $.noop;
        ele.onmousedown = $.noop;
    };
    var exit = function () {
        var rbcount = $("#rbcount");
        var count = 3;
        setInterval(function () {
            if (--count === 0) {
                window.location.reload();
            }
            rbcount.text(count > 0 ? count : "0");
        }, 1000);
    };
    $(".mw-rollback-link a").each(loop);
    var api = new mw.Api();
    $(document.body).on("click", function (event) { return __awaiter(void 0, void 0, void 0, function () {
        var target, self, parent, rollbackSummary, uri, rbing_1, summary;
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0:
                    target = event.target;
                    if (!$(target).is(".mw-rollback-link a")) {
                        return [2, true];
                    }
                    self = $(target);
                    parent = self.parent();
                    if (!self.data("href")) {
                        loop(null, target);
                    }
                    if (!parent.find(self)[0]) {
                        return [2, false];
                    }
                    if (mw.config.get("wgRollbacking")) {
                        return [2, false];
                    }
                    return [4, oouiDialog.prompt("<ul><li>".concat(wgULS("回退操作的编辑摘要", "還原操作的編輯摘要"), "\uFF1A<code>xxx//Rollback</code></li><li>").concat(wgULS("空白则使用默认回退摘要", "留空則使用默認的還原摘要"), "\uFF0C").concat(wgULS("取消则不进行回退", "取消則不進行還原"), "</li></ul><hr>").concat(wgULS("请输入回退摘要", "請輸入還原摘要"), "\uFF1A"), {
                            title: "回退小工具",
                            size: "medium",
                            required: false
                        })];
                case 1:
                    rollbackSummary = _a.sent();
                    if (rollbackSummary !== null) {
                        uri = new mw.Uri(self.data("href"));
                        self.replaceWith("<span id=\"rbing\"><img src=\"https://img.moegirl.org.cn/common/d/d1/Windows_10_loading.gif\" style=\"height: 1em; margin-top: -.25em;\">".concat(wgULS("正在回退中", "正在還原"), "\u2026\u2026</span>"));
                        rbing_1 = $("#rbing");
                        $(".mw-rollback-link a").not(rbing_1).css({
                            color: "#aaa",
                            "text-decoration": "none"
                        });
                        mw.config.set("wgRollbacking", true);
                        summary = rollbackSummary ? "".concat(rollbackSummary, " //Rollback") : "//Rollback";
                        if (uri.query.from) {
                            api.post({
                                title: uri.query.title,
                                user: uri.query.from,
                                summary: summary,
                                token: uri.query.token,
                                action: "rollback",
                                format: "json"
                            }).then(function () {
                                rbing_1.css("color", "green").html("\u6210\u529F\uFF01".concat(wgULS("将在", "將在"), "<span id=\"rbcount\">3</span>\u79D2").concat(wgULS("内刷新", "內重新整理")));
                                exit();
                            }, function (e) {
                                var errorText = e instanceof Error ? "".concat(e, " ").concat(e.stack.split("\n")[1].trim()) : $.isPlainObject(e) ? JSON.stringify(e) : typeof e === "string" && e in possibleError ? possibleError[e] : "".concat(e);
                                rbing_1.css("color", "red").html("".concat(wgULS("错误", "錯誤"), "\uFF1A").concat(errorText, "\u3002").concat(wgULS("将在", "將在"), "<span id=\"rbcount\">3</span>").concat(wgULS("秒内刷新", "秒內重新整理")));
                                exit();
                            });
                        }
                        else {
                            uri.query.summary = summary;
                            window.open(uri.toString(), "_self");
                        }
                    }
                    return [2, false];
            }
        });
    }); });
    new Image().src = "https://img.moegirl.org.cn/common/d/d1/Windows_10_loading.gif";
});

/* </pre> */