跳转到内容

MediaWiki:Gadget-shortlink.js:修订间差异

来自萌娘共享
标签由机器人或全自动脚本执行的操作
标签由机器人或全自动脚本执行的操作
第8行: 第8行:
/* <pre> */
/* <pre> */


"use strict";
"use strict";$(()=>{const{wgArticleId:i=-1,wgCurRevisionId:t=-1,wgRevisionId:e=-1,wgDiffOldId:d=-1,wgDiffNewId:a=-1,wgServer:l,wgScriptPath:s,skin:o}=mw.config.get(["wgArticleId","wgCurRevisionId","wgRevisionId","wgDiffOldId","wgDiffNewId","wgServer","wgScriptPath","skin"]);if(i<=0)return;let w;switch($("body").css("height","auto"),o){case"moeskin":default:w=$(`<div class="moe-card" id="p-sl"><div class="mw-parser-output"><h3 style="margin-top: 0px;">${wgULS("短链接","短網址")}</h3></div></div>`),$(".moe-siderail-sticky").append(w),$("#p-sl h3").after('<div style="display:flex"><div style="width:0.25rem;border-radius:99em;background:rgba(0,0,0,0.102);margin-right:1rem"></div><ul id="p-sl-list" style="list-style:none"></ul></div>');break;case"vector":$("#mw-panel").append(`<div class="portal" id="p-sl" aria-labelledby="p-sl-label" style="position:sticky;top:0;"><h3 lang="zh-CN" dir="ltr" id="p-sl-label">${wgULS("短链接","短網址")}</h3></div>`),$("#p-sl h3").after('<div class="body"><ul id="p-sl-list"></ul></div>')}const r=$("#p-sl-list"),c=[{id:"page",href:`curid=${i}`,title:wgULS("本页面的短链接(页面ID)","本頁面的短網址(頁面ID)"),text:wgULS("本页短链","本頁短網址"),wikitext:`[[Special:重定向/page/${i}]]`},{id:"newrev",href:`oldid=${t}`,title:wgULS("本页面最新版本的短链接(版本ID)","本頁面最新修訂的短網址(版本ID)"),text:wgULS("最新版本","最新修訂"),wikitext:`[[Special:固定链接/${t}]]`}];e>0&&(t!==e?c.push({id:"rev",href:`oldid=${e}`,title:wgULS("本页面当前版本的短链接(版本ID)","本頁面當前修訂的短網址(版本ID)"),text:wgULS("当前版本","當前修訂"),wikitext:`[[Special:固定链接/${e}]]`},{id:"currev",href:`diff=${e}`,title:wgULS("本页面当前版本与前一版本的差异的链接(版本ID)","本頁面當前修訂與前一修訂的短網址(版本ID)"),text:wgULS("当前版本差异","當前修訂差異"),wikitext:`[[Special:差异/${e}]]`},{id:"curdiff",href:`diff=${t}&oldid=${e}`,title:wgULS("与本页面最新版本的差异的短链接(版本ID)","與本頁面最新修訂差異的短網址(版本ID)"),text:wgULS("与最新版本差异","與最新修訂差異"),wikitext:`[[Special:差异/${e}/${t}]]`}):a!==t&&c.push({id:"currev",href:`diff=${t}`,title:wgULS("本页面最新版本与前一版本的差异的链接(版本ID)","本頁面最新修訂與前一修訂差異的短網址(版本ID)"),text:wgULS("最新版本差异","與最新修訂差異"),wikitext:`[[Special:差异/${t}]]`})),a>0&&d>0&&c.push({id:"diff",href:`diff=${a}&oldid=${d}`,title:wgULS("当前比较的差异的短链接(版本ID)","當前比較的差異的短網址(版本ID)"),text:wgULS("当前比较的差异","當前比較的差異"),wikitext:`[[Special:差异/${d}/${a}]]`});const addItem=i=>{const t=$(`<li id="sl-${i.id}"></li>`);switch(t.append(`<a href="${l}${s}/?${i.href}">${i.text}</a>`),o){case"moeskin":default:t.append(`<div>(<a data-copy-content="${i.wikitext}" data-type="wikitext"></a><wbr>丨<a data-copy-content="${l}${s}/_?${i.href}" data-type="${wgULS("短链接","短網址")}"></a>)</div>`);break;case"vector":t.append(`<div>(<a data-copy-content="${i.wikitext}" data-type="wikitext"></a>)</div>`),t.append(`<div>(<a data-copy-content="${l}${s}/_?${i.href}" data-type="${wgULS("短链接","短網址")}"></a>)</div>`)}r.append(t)},markStatus=(i,t)=>{i.innerText=t?`${i.dataset.type}${wgULS("复制成功","複製成功")}`:`${wgULS("复制","複製")}${i.dataset.type}`};for(const i of c)addItem(i);$("#p-sl-list a[data-type]").each((i,t)=>{markStatus(t,!1)}),$("#p-sl-list a[data-type]").on("click",async function(){if("function"==typeof navigator.clipboard?.writeText)await navigator.clipboard.writeText(this.dataset.copyContent);else{const i=$("<pre/>",{css:{position:"absolute",left:"-99999px","z-index":"-99999",opacity:0}}).appendTo("body"),t=window.getSelection(),{rangeCount:e}=t;let d;e>0&&(d=t.getRangeAt(0)),i.text(this.dataset.copyContent),t.selectAllChildren(i[0]),document.execCommand("copy"),window.setTimeout(()=>{t.removeAllRanges(),e>0&&t.addRange(d),i.empty()},7)}markStatus(this,!0),setTimeout(()=>{markStatus(this,!1)},3e3)}),"vector"===o&&$(window).on("resize",()=>{$("#mw-panel").height($("body").height())})});  
$(() => {
    const { wgArticleId = -1, wgCurRevisionId = -1, wgRevisionId = -1, wgDiffOldId = -1, wgDiffNewId = -1, wgServer, wgScriptPath, skin, } = mw.config.get([
        "wgArticleId",
        "wgCurRevisionId",
        "wgRevisionId",
        "wgDiffOldId",
        "wgDiffNewId",
        "wgServer",
        "wgScriptPath",
        "skin",
    ]);
    if (wgArticleId <= 0) {
        return;
    }
    $("body").css("height", "auto");
    let $slCard;
    switch (skin) {
        case "moeskin":
        default:
            $slCard = $(`<div class="moe-card" id="p-sl"><div class="mw-parser-output"><h3 style="margin-top: 0px;">${wgULS("短链接", "短網址")}</h3></div></div>`);
            $(".moe-siderail-sticky").append($slCard);
            $("#p-sl h3").after('<div style="display:flex"><div style="width:0.25rem;border-radius:99em;background:rgba(0,0,0,0.102);margin-right:1rem"></div><ul id="p-sl-list" style="list-style:none"></ul></div>');
            break;
        case "vector":
            $("#mw-panel").append(`<div class="portal" id="p-sl" aria-labelledby="p-sl-label" style="position:sticky;top:0;"><h3 lang="zh-CN" dir="ltr" id="p-sl-label">${wgULS("短链接", "短網址")}</h3></div>`);
            $("#p-sl h3").after('<div class="body"><ul id="p-sl-list"></ul></div>');
            break;
    }
    const $list = $("#p-sl-list");
    const links = [{
            id: "page",
            href: `curid=${wgArticleId}`,
            title: wgULS("本页面的短链接(页面ID)", "本頁面的短網址(頁面ID)"),
            text: wgULS("本页短链", "本頁短網址"),
            wikitext: `[[Special:重定向/page/${wgArticleId}]]`,
        }, {
            id: "newrev",
            href: `oldid=${wgCurRevisionId}`,
            title: wgULS("本页面最新版本的短链接(版本ID)", "本頁面最新修訂的短網址(版本ID)"),
            text: wgULS("最新版本", "最新修訂"),
            wikitext: `[[Special:固定链接/${wgCurRevisionId}]]`,
        }];
    if (wgRevisionId > 0) {
        if (wgCurRevisionId !== wgRevisionId) {
            links.push({
                id: "rev",
                href: `oldid=${wgRevisionId}`,
                title: wgULS("本页面当前版本的短链接(版本ID)", "本頁面當前修訂的短網址(版本ID)"),
                text: wgULS("当前版本", "當前修訂"),
                wikitext: `[[Special:固定链接/${wgRevisionId}]]`,
            }, {
                id: "currev",
                href: `diff=${wgRevisionId}`,
                title: wgULS("本页面当前版本与前一版本的差异的链接(版本ID)", "本頁面當前修訂與前一修訂的短網址(版本ID)"),
                text: wgULS("当前版本差异", "當前修訂差異"),
                wikitext: `[[Special:差异/${wgRevisionId}]]`,
            }, {
                id: "curdiff",
                href: `diff=${wgCurRevisionId}&oldid=${wgRevisionId}`,
                title: wgULS("与本页面最新版本的差异的短链接(版本ID)", "與本頁面最新修訂差異的短網址(版本ID)"),
                text: wgULS("与最新版本差异", "與最新修訂差異"),
                wikitext: `[[Special:差异/${wgRevisionId}/${wgCurRevisionId}]]`,
            });
        }
        else if (wgDiffNewId !== wgCurRevisionId) {
            links.push({
                id: "currev",
                href: `diff=${wgCurRevisionId}`,
                title: wgULS("本页面最新版本与前一版本的差异的链接(版本ID)", "本頁面最新修訂與前一修訂差異的短網址(版本ID)"),
                text: wgULS("最新版本差异", "與最新修訂差異"),
                wikitext: `[[Special:差异/${wgCurRevisionId}]]`,
            });
        }
    }
    if (wgDiffNewId > 0 && wgDiffOldId > 0) {
        links.push({
            id: "diff",
            href: `diff=${wgDiffNewId}&oldid=${wgDiffOldId}`,
            title: wgULS("当前比较的差异的短链接(版本ID)", "當前比較的差異的短網址(版本ID)"),
            text: wgULS("当前比较的差异", "當前比較的差異"),
            wikitext: `[[Special:差异/${wgDiffOldId}/${wgDiffNewId}]]`,
        });
    }
    const addItem = (link) => {
        const $item = $(`<li id="sl-${link.id}"></li>`);
        $item.append(`<a href="${wgServer}${wgScriptPath}/?${link.href}">${link.text}</a>`);
        switch (skin) {
            case "moeskin":
            default:
                $item.append(`<div>(<a data-copy-content="${link.wikitext}" data-type="wikitext"></a><wbr>丨<a data-copy-content="${wgServer}${wgScriptPath}/_?${link.href}" data-type="${wgULS("短链接", "短網址")}"></a>)</div>`);
                break;
            case "vector":
                $item.append(`<div>(<a data-copy-content="${link.wikitext}" data-type="wikitext"></a>)</div>`);
                $item.append(`<div>(<a data-copy-content="${wgServer}${wgScriptPath}/_?${link.href}" data-type="${wgULS("短链接", "短網址")}"></a>)</div>`);
                break;
        }
        $list.append($item);
    };
    const markStatus = (ele, status) => {
        ele.innerText = status
            ? `${ele.dataset.type}${wgULS("复制成功", "複製成功")}`
            : `${wgULS("复制", "複製")}${ele.dataset.type}`;
    };
    for (const item of links) {
        addItem(item);
    }
    $("#p-sl-list a[data-type]").each((_, ele) => {
        markStatus(ele, false);
    });
    $("#p-sl-list a[data-type]").on("click", async function () {
        var _a;
        if (typeof ((_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText) === "function") {
            await navigator.clipboard.writeText(this.dataset.copyContent);
        }
        else {
            const valueNode = $("<pre/>", {
                css: {
                    position: "absolute",
                    left: "-99999px",
                    "z-index": "-99999",
                    opacity: 0,
                },
            }).appendTo("body");
            const selection = window.getSelection();
            const { rangeCount } = selection;
            let range;
            if (rangeCount > 0) {
                range = selection.getRangeAt(0);
            }
            valueNode.text(this.dataset.copyContent);
            selection.selectAllChildren(valueNode[0]);
            document.execCommand("copy");
            window.setTimeout(() => {
                selection.removeAllRanges();
                if (rangeCount > 0) {
                    selection.addRange(range);
                }
                valueNode.empty();
            }, 7);
        }
        markStatus(this, true);
        setTimeout(() => {
            markStatus(this, false);
        }, 3000);
    });
    if (skin === "vector") {
        $(window).on("resize", () => {
            $("#mw-panel").height($("body").height());
        });
    }
});  


/* </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/shortlink/Gadget-shortlink.js|user=[[U:AnnAngela]]|co-authors=|longId=c33adb813fc51e86c146a535f52b5d695a96dd48|shortId=c33adb81|summary=feat: 这个,不需要了}}'; 

/* <pre> */

"use strict";$(()=>{const{wgArticleId:i=-1,wgCurRevisionId:t=-1,wgRevisionId:e=-1,wgDiffOldId:d=-1,wgDiffNewId:a=-1,wgServer:l,wgScriptPath:s,skin:o}=mw.config.get(["wgArticleId","wgCurRevisionId","wgRevisionId","wgDiffOldId","wgDiffNewId","wgServer","wgScriptPath","skin"]);if(i<=0)return;let w;switch($("body").css("height","auto"),o){case"moeskin":default:w=$(`<div class="moe-card" id="p-sl"><div class="mw-parser-output"><h3 style="margin-top: 0px;">${wgULS("短链接","短網址")}</h3></div></div>`),$(".moe-siderail-sticky").append(w),$("#p-sl h3").after('<div style="display:flex"><div style="width:0.25rem;border-radius:99em;background:rgba(0,0,0,0.102);margin-right:1rem"></div><ul id="p-sl-list" style="list-style:none"></ul></div>');break;case"vector":$("#mw-panel").append(`<div class="portal" id="p-sl" aria-labelledby="p-sl-label" style="position:sticky;top:0;"><h3 lang="zh-CN" dir="ltr" id="p-sl-label">${wgULS("短链接","短網址")}</h3></div>`),$("#p-sl h3").after('<div class="body"><ul id="p-sl-list"></ul></div>')}const r=$("#p-sl-list"),c=[{id:"page",href:`curid=${i}`,title:wgULS("本页面的短链接(页面ID)","本頁面的短網址(頁面ID)"),text:wgULS("本页短链","本頁短網址"),wikitext:`[[Special:重定向/page/${i}]]`},{id:"newrev",href:`oldid=${t}`,title:wgULS("本页面最新版本的短链接(版本ID)","本頁面最新修訂的短網址(版本ID)"),text:wgULS("最新版本","最新修訂"),wikitext:`[[Special:固定链接/${t}]]`}];e>0&&(t!==e?c.push({id:"rev",href:`oldid=${e}`,title:wgULS("本页面当前版本的短链接(版本ID)","本頁面當前修訂的短網址(版本ID)"),text:wgULS("当前版本","當前修訂"),wikitext:`[[Special:固定链接/${e}]]`},{id:"currev",href:`diff=${e}`,title:wgULS("本页面当前版本与前一版本的差异的链接(版本ID)","本頁面當前修訂與前一修訂的短網址(版本ID)"),text:wgULS("当前版本差异","當前修訂差異"),wikitext:`[[Special:差异/${e}]]`},{id:"curdiff",href:`diff=${t}&oldid=${e}`,title:wgULS("与本页面最新版本的差异的短链接(版本ID)","與本頁面最新修訂差異的短網址(版本ID)"),text:wgULS("与最新版本差异","與最新修訂差異"),wikitext:`[[Special:差异/${e}/${t}]]`}):a!==t&&c.push({id:"currev",href:`diff=${t}`,title:wgULS("本页面最新版本与前一版本的差异的链接(版本ID)","本頁面最新修訂與前一修訂差異的短網址(版本ID)"),text:wgULS("最新版本差异","與最新修訂差異"),wikitext:`[[Special:差异/${t}]]`})),a>0&&d>0&&c.push({id:"diff",href:`diff=${a}&oldid=${d}`,title:wgULS("当前比较的差异的短链接(版本ID)","當前比較的差異的短網址(版本ID)"),text:wgULS("当前比较的差异","當前比較的差異"),wikitext:`[[Special:差异/${d}/${a}]]`});const addItem=i=>{const t=$(`<li id="sl-${i.id}"></li>`);switch(t.append(`<a href="${l}${s}/?${i.href}">${i.text}</a>`),o){case"moeskin":default:t.append(`<div>(<a data-copy-content="${i.wikitext}" data-type="wikitext"></a><wbr>丨<a data-copy-content="${l}${s}/_?${i.href}" data-type="${wgULS("短链接","短網址")}"></a>)</div>`);break;case"vector":t.append(`<div>(<a data-copy-content="${i.wikitext}" data-type="wikitext"></a>)</div>`),t.append(`<div>(<a data-copy-content="${l}${s}/_?${i.href}" data-type="${wgULS("短链接","短網址")}"></a>)</div>`)}r.append(t)},markStatus=(i,t)=>{i.innerText=t?`${i.dataset.type}${wgULS("复制成功","複製成功")}`:`${wgULS("复制","複製")}${i.dataset.type}`};for(const i of c)addItem(i);$("#p-sl-list a[data-type]").each((i,t)=>{markStatus(t,!1)}),$("#p-sl-list a[data-type]").on("click",async function(){if("function"==typeof navigator.clipboard?.writeText)await navigator.clipboard.writeText(this.dataset.copyContent);else{const i=$("<pre/>",{css:{position:"absolute",left:"-99999px","z-index":"-99999",opacity:0}}).appendTo("body"),t=window.getSelection(),{rangeCount:e}=t;let d;e>0&&(d=t.getRangeAt(0)),i.text(this.dataset.copyContent),t.selectAllChildren(i[0]),document.execCommand("copy"),window.setTimeout(()=>{t.removeAllRanges(),e>0&&t.addRange(d),i.empty()},7)}markStatus(this,!0),setTimeout(()=>{markStatus(this,!1)},3e3)}),"vector"===o&&$(window).on("resize",()=>{$("#mw-panel").height($("body").height())})}); 

/* </pre> */