跳转到内容

MediaWiki:Gadget-rollback-summary.js:修订间差异

来自萌娘共享
代码变动:103d1a56 - feat: rename (#594) by U:AnnAngela, co-authored-by: GH:github-actions[bot]
标签由机器人或全自动脚本执行的操作
代码变动:103d1a56 - feat: rename (#594) by U:AnnAngela, co-authored-by: GH:github-actions[bot]
标签由机器人或全自动脚本执行的操作
第8行: 第8行:
/* <pre> */
/* <pre> */


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


/* </pre> */
/* </pre> */

2025年7月26日 (六) 00:30的版本

/**
 * -------------------------------------------------------------------------
 * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 * -------------------------------------------------------------------------
 */
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/rollback-summary/Gadget-rollback-summary.js|user=[[U:AnnAngela]]|co-authors=GH:github-actions[bot]|longId=103d1a563ea4ccc8ff29fb55c9bcd88329a56eb5|shortId=103d1a56|summary=feat: rename (#594)|body=<nowiki>Co-authored-by: github-actions[bot] <41898282+github-actions[bot]📧users.noreply.github.com></nowiki>}}'; 

/* <pre> */

"use strict";$(()=>{const o=mw.config.get("wgUserGroups",[]);if(!o.includes("sysop")&&!o.includes("patroller"))return;mw.config.set({wgRollbacking:!1,wgRollbackTool:"inited"});const e={alreadyrolled:wgULS("已被回退","已被還原"),onlyauthor:wgULS("该页面只有一位编辑者参与编辑,无法回退","該頁面只有一位編輯者參與編輯,無法還原"),missingparams:wgULS('必须要有参数"title"或参数"pageid"之一','必須存在參數"title"或參數"pageid"之一'),notitle:wgULS('参数"title"必须被设置','參數"title"必須被設置'),notoken:wgULS('参数"token"必须被设置','參數"token"必須被設置'),nouser:wgULS('参数"user"必须被设置','參數"user"必須被設置')},loop=(o,e)=>{const n=$(e);n.data("href",n.attr("href")).removeAttr("href").attr("title",`${e.title}(启用自定义摘要)`).css("cursor","pointer").append("<sup>+</sup>"),$(".ns-special")[0]&&n.text().includes("10")&&n.parent().text(wgULS("[超过10次的编辑]","[超過10次的編輯]")).attr("title","超过10次的编辑请使用撤销功能,以便检查差异(自定义摘要小工具)"),e.onmouseover=$.noop,e.onmouseout=$.noop,e.onmousedown=$.noop};$(".mw-rollback-link a").each(loop);const n=new mw.Api;$(document.body).on("click",async o=>{const t=o.target;if(!$(t).is(".mw-rollback-link a"))return!0;const i=$(t),l=i.parent();if(i.data("href")||loop(0,t),!l.find(i)[0])return!1;if(mw.config.get("wgRollbacking"))return!1;const r=await oouiDialog.prompt(`<ul><li>${wgULS("回退操作的编辑摘要","還原操作的編輯摘要")}:<code>xxx//Rollback</code></li><li>${wgULS("空白则使用默认回退摘要","留空則使用默認的還原摘要")}${wgULS("取消则不进行回退","取消則不進行還原")}</li></ul><hr>${wgULS("请输入回退摘要","請輸入還原摘要")}:`,{title:"回退小工具",size:"medium",required:!1});if(null!==r){const o=new mw.Uri(i.data("href"));i.replaceWith(`<span id="rbing"><img src="https://img.moegirl.org.cn/common/d/d1/Windows_10_loading.gif" style="height: 1em; margin-top: -.25em;">${wgULS("正在回退中","正在還原")}……</span>`);const t=$("#rbing");$(".mw-rollback-link a").not(t).css({color:"#aaa","text-decoration":"none"}),mw.config.set("wgRollbacking",!0);const l=r?`${r} //Rollback`:"//Rollback";if(o.query.from)try{await n.post({action:"rollback",assertuser:mw.config.get("wgUserName"),title:o.query.title,user:o.query.from,summary:l,token:o.query.token,format:"json"}),t.css("color","green").html(`成功!${wgULS("将在","將在")}<span id="rbcount">3</span>秒${wgULS("内刷新","內重新整理")}`)}catch(o){const n=o instanceof Error?`${o} ${o.stack.split("\n")[1].trim()}`:$.isPlainObject(o)?JSON.stringify(o):"string"==typeof o&&Reflect.has(e,o)?e[o]:`${o}`;t.css("color","red").html(`${wgULS("错误","錯誤")}${n}${wgULS("将在","將在")}<span id="rbcount">3</span>${wgULS("秒内刷新","秒內重新整理")}`)}finally{(()=>{const o=$("#rbcount");let e=3;setInterval(()=>{0===--e&&window.location.reload(),o.text(e>0?e:"0")},1e3)})()}else o.query.summary=l,window.open(o.toString(),"_self")}return!1}),(new Image).src="https://img.moegirl.org.cn/common/d/d1/Windows_10_loading.gif"}); 

/* </pre> */