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

来自Vocawiki
跳转到导航 跳转到搜索
SaoMikoto留言 | 贡献
导入1个版本:​来源于萌娘百科,依CC BY-NC-SA 3.0 CN导入,原贡献者请参见来源页面历史
SaoMikoto留言 | 贡献
// Edit via InPageEdit
第8行: 第8行:
/* <pre> */
/* <pre> */


"use strict";$(()=>{const{wgArticleId:i=-1,wgCurRevisionId:t=-1,wgRevisionId:e=-1,wgDiffOldId:d=-1,wgDiffNewId:a=-1,wgServer:s,wgScriptPath:r,skin:l}=mw.config.get(["wgArticleId","wgCurRevisionId","wgRevisionId","wgDiffOldId","wgDiffNewId","wgServer","wgScriptPath","skin"]);if(i<=0)return;const w=[{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?w.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&&w.push({id:"currev",href:`diff=${t}`,title:wgULS("本页面最新版本与前一版本的差异的链接(版本ID)","本頁面最新修訂與前一修訂差異的短網址(版本ID)"),text:wgULS("最新版本差异","與最新修訂差異"),wikitext:`[[Special:差异/${t}]]`})),a>0&&d>0&&w.push({id:"diff",href:`diff=${a}&oldid=${d}`,title:wgULS("当前比较的差异的短链接(版本ID)","當前比較的差異的短網址(版本ID)"),text:wgULS("当前比较的差异","當前比較的差異"),wikitext:`[[Special:差异/${d}/${a}]]`});const c=wgULS("复制","複製"),g=wgULS("成功","成功"),o=wgULS("失败","失敗"),markStatus=(i,t,e)=>{i.innerText=t?`${i.dataset.type}${c}${e?g:o}`:`${c}${i.dataset.type}`};switch(l){default:case"moeskin":{$("body").css("height","auto");const i=$(`<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(i),$("#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>');for(const i of w){const t=$(`<li id="sl-${i.id}"></li>`);t.append(`<a href="${s}${r}/?${i.href}">${i.text}</a>`),t.append(`<div>(<a href="javascript:void(0)" data-copy-content="${i.wikitext}" data-type="wikitext"></a><wbr>丨<a href="javascript:void(0)" data-copy-content="${s}${r}/_?${i.href}" data-type="${wgULS("短链接","短網址")}"></a>)</div>`),$("#p-sl-list").append(t)}$("#p-sl-list a[data-type]").each((i,t)=>{markStatus(t,!1)}),$("#p-sl-list a[data-type]").on("click",async function(){try{await navigator.clipboard.writeText(this.dataset.copyContent),markStatus(this,!0,!0)}catch{markStatus(this,!0,!1)}finally{setTimeout(()=>{markStatus(this,!1)},3e3)}});break}case"vector-2022":{const i=mw.util.addPortletLink("p-cactions","javascript:void(0)",wgULS("短链接","短網址"),"ca-shortlink",wgULS("复制本页面的短链接","複製本頁面的短網址"));i&&i.querySelector("a").addEventListener("click",i=>{i.preventDefault();const t=$("<div>");w.forEach(i=>{t.append($("<div>").css({"font-weight":"bold",margin:"0.6em 0 0.2em"}).text(i.title)),[i.wikitext,`${s}${r}/_?${i.href}`].forEach(i=>{t.append(new mw.widgets.CopyTextLayout({align:"top",copyText:i}).$element)})}),OO.ui.alert(t,{size:"medium"})});break}}});  
"use strict";
$(() => {
    const {
        wgArticleId = -1,
        wgCurRevisionId = -1,
        wgRevisionId = -1,
        wgDiffOldId = -1,
        wgDiffNewId = -1,
        wgServer,
        wgScriptPath,
    } = mw.config.get([
        "wgArticleId",
        "wgCurRevisionId",
        "wgRevisionId",
        "wgDiffOldId",
        "wgDiffNewId",
        "wgServer",
        "wgScriptPath",
        "skin",
    ]);
    if (wgArticleId <= 0) {
        return;
    }
 
    // 链接信息
    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 portletLink = mw.util.addPortletLink(
        "p-tb",
        "javascript:void(0)",
        wgULS("短链接", "短網址"),
        "ca-shortlink",
        wgULS("复制本页面的短链接", "複製本頁面的短網址")
    );
    if (portletLink) {
        portletLink.querySelector("a").addEventListener("click", (e) => {
            e.preventDefault();
            const $element = $("<div>");
            links.forEach((shortlink) => {
                $element.append(
                    $("<div>")
                        .css({ "font-weight": "bold", margin: "0.6em 0 0.2em" })
                        .text(shortlink.title),
                );
                [shortlink.wikitext, `${wgServer}${wgScriptPath}/_?${shortlink.href}`].forEach((value) => {
                    $element.append(
                        new mw.widgets.CopyTextLayout({ align: "top", copyText: value }).$element,
                    );
                });
            });
            OO.ui.alert($element, { size: "medium" });
        });
    }
});
 


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

2025年9月14日 (日) 14:18的版本

/**
 * -------------------------------------------------------------------------
 * !!! 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:BearBin]]|co-authors=|longId=48ac3eed0d3ed8944a9fb6a1aceb858c61247d89|shortId=48ac3eed|summary=fix: #698}}'; 

/* <pre> */

"use strict";
$(() => {
    const {
        wgArticleId = -1,
        wgCurRevisionId = -1,
        wgRevisionId = -1,
        wgDiffOldId = -1,
        wgDiffNewId = -1,
        wgServer,
        wgScriptPath,
    } = mw.config.get([
        "wgArticleId",
        "wgCurRevisionId",
        "wgRevisionId",
        "wgDiffOldId",
        "wgDiffNewId",
        "wgServer",
        "wgScriptPath",
        "skin",
    ]);
    if (wgArticleId <= 0) {
        return;
    }

    // 链接信息
    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 portletLink = mw.util.addPortletLink(
        "p-tb",
        "javascript:void(0)",
        wgULS("短链接", "短網址"),
        "ca-shortlink",
        wgULS("复制本页面的短链接", "複製本頁面的短網址")
    );
    if (portletLink) {
        portletLink.querySelector("a").addEventListener("click", (e) => {
            e.preventDefault();
            const $element = $("<div>");
            links.forEach((shortlink) => {
                $element.append(
                    $("<div>")
                        .css({ "font-weight": "bold", margin: "0.6em 0 0.2em" })
                        .text(shortlink.title),
                );
                [shortlink.wikitext, `${wgServer}${wgScriptPath}/_?${shortlink.href}`].forEach((value) => {
                    $element.append(
                        new mw.widgets.CopyTextLayout({ align: "top", copyText: value }).$element,
                    );
                });
            });
            OO.ui.alert($element, { size: "medium" });
        });
    }
});


/* </pre> */