MediaWiki:Gadget-shortlink.js

来自萌娘文库
跳转至: 导航搜索

注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件
/* <pre> */
/**
 * -------------------------------------------------------------------------
 * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 * -------------------------------------------------------------------------
 */
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/gadgets/shortlink/MediaWiki:Gadget-shortlink.js|user=[[U:星海子]]|longId=a86ddb4cca7b0659e3282a6bbd51dd43f02e9c9e|shortId=a86ddb4|message=fix(shortlink): duplicate id}}';

"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 wgArticleId = mw.config.get("wgArticleId") || -1;
    var wgCurRevisionId = mw.config.get("wgCurRevisionId") || -1;
    var wgRevisionId = mw.config.get("wgRevisionId") || -1;
    var wgDiffOldId = mw.config.get("wgDiffOldId") || -1;
    var wgDiffNewId = mw.config.get("wgDiffNewId") || -1;
    if (wgArticleId <= 0 && wgRevisionId <= 0 && wgCurRevisionId <= 0 && wgDiffOldId <= 0 && wgDiffNewId <= 0) {
        return;
    }
    var $body = $("body");
    var $mwPanel = $("#mw-panel");
    $body.css("height", "auto");
    var links = [{
            id: "page",
            href: "curid=".concat(wgArticleId),
            title: wgULS("本页面的短链接(页面ID)", "本頁面的短網址(頁面ID)"),
            text: wgULS("本页短链", "本頁短網址"),
            wikitext: "[[Special:\u91CD\u5B9A\u5411/page/".concat(wgArticleId, "]]")
        }, {
            id: "newrev",
            href: "oldid=".concat(wgCurRevisionId),
            title: wgULS("本页面最新版本的短链接(版本ID)", "本頁面最新修訂的短網址(版本ID)"),
            text: wgULS("最新版本", "最新修訂"),
            wikitext: "[[Special:\u56FA\u5B9A\u94FE\u63A5/".concat(wgCurRevisionId, "]]")
        }];
    if (wgRevisionId > 0) {
        if (wgCurRevisionId !== wgRevisionId) {
            links.push({
                id: "rev",
                href: "oldid=".concat(wgRevisionId),
                title: wgULS("本页面当前版本的短链接(版本ID)", "本頁面當前修訂的短網址(版本ID)"),
                text: wgULS("当前版本", "當前修訂"),
                wikitext: "[[Special:\u56FA\u5B9A\u94FE\u63A5/".concat(wgRevisionId, "]]")
            }, {
                id: "currev",
                href: "diff=".concat(wgRevisionId),
                title: wgULS("本页面当前版本与前一版本的差异的链接(版本ID)", "本頁面當前修訂與前一修訂的短網址(版本ID)"),
                text: wgULS("当前版本差异", "當前修訂差異"),
                wikitext: "[[Special:\u5DEE\u5F02/".concat(wgRevisionId, "]]")
            }, {
                id: "curdiff",
                href: "diff=".concat(wgCurRevisionId, "&oldid=").concat(wgRevisionId),
                title: wgULS("与本页面最新版本的差异的短链接(版本ID)", "與本頁面最新修訂差異的短網址(版本ID)"),
                text: wgULS("与最新版本差异", "與最新修訂差異"),
                wikitext: "[[Special:\u5DEE\u5F02/".concat(wgRevisionId, "/").concat(wgCurRevisionId, "]]")
            });
        }
        else if (wgDiffNewId !== wgCurRevisionId) {
            links.push({
                id: "currev",
                href: "diff=".concat(wgCurRevisionId),
                title: wgULS("本页面最新版本与前一版本的差异的链接(版本ID)", "本頁面最新修訂與前一修訂差異的短網址(版本ID)"),
                text: wgULS("最新版本差异", "與最新修訂差異"),
                wikitext: "[[Special:\u5DEE\u5F02/".concat(wgCurRevisionId, "]]")
            });
        }
    }
    if (wgDiffNewId > 0 && wgDiffOldId > 0) {
        links.push({
            id: "diff",
            href: "diff=".concat(wgDiffNewId, "&oldid=").concat(wgDiffOldId),
            title: wgULS("当前比较的差异的短链接(版本ID)", "當前比較的差異的短網址(版本ID)"),
            text: wgULS("当前比较的差异", "當前比較的差異"),
            wikitext: "[[Special:\u5DEE\u5F02/".concat(wgDiffOldId, "/").concat(wgDiffNewId, "]]")
        });
    }
    $mwPanel.append("<div class=\"portal\" role=\"navigation\" id=\"p-sl\" aria-labelledby=\"p-sl-label\" style=\"position: sticky; top: 0;\"><h3 lang=\"zh-CN\" dir=\"ltr\" id=\"p-sl-label\">".concat(wgULS("短链接", "短網址"), "</h3><div class=\"body\"><ul>").concat(links.map(function (l) { return "<li id=\"sl-".concat(l.id, "\"><a href=\"").concat(mw.config.get("wgServer")).concat(mw.config.get("wgScriptPath"), "/_?").concat(l.href, "\" title=\"").concat(l.title, "\">").concat(l.text, "</a><br><span>\uFF08<a data-copy-content=\"").concat(l.wikitext, "\" data-type=\"wikitext\" href=\"javascript:void(0);\"></a>\uFF09</span><br><span>\uFF08<a data-copy-content=\"").concat(mw.config.get("wgServer")).concat(mw.config.get("wgScriptPath"), "/_?").concat(l.href, "\" data-type=\"").concat(wgULS("短链接", "短網址"), "\" href=\"javascript:void(0);\"></a>\uFF09</span></li>"); }).join("\n"), "</ul></div></div>"));
    var markStatus = function (ele, status) { return ele.innerText = status ? "".concat(ele.dataset.type).concat(wgULS("复制成功", "複製成功")) : "".concat(wgULS("复制", "複製")).concat(ele.dataset.type); };
    $("#mw-panel a[data-type]").each(function (_, ele) {
        markStatus(ele, false);
    });
    var valueNode = $("<pre/>", {
        css: {
            position: "absolute",
            left: "-99999px",
            "z-index": "-99999"
        }
    }).appendTo("body");
    $("#mw-panel a[data-copy-content]").on("click", function () {
        var _a;
        return __awaiter(this, void 0, void 0, function () {
            var self, selection_1, rangeCount_1, range_1;
            return __generator(this, function (_b) {
                switch (_b.label) {
                    case 0:
                        self = $(this);
                        if (!(typeof ((_a = navigator.clipboard) === null || _a === void 0 ? void 0 : _a.writeText) === "function")) return [3, 2];
                        return [4, navigator.clipboard.writeText(this.dataset.copyContent)];
                    case 1:
                        _b.sent();
                        return [3, 3];
                    case 2:
                        selection_1 = window.getSelection();
                        rangeCount_1 = selection_1.rangeCount;
                        if (rangeCount_1 > 0) {
                            range_1 = selection_1.getRangeAt(0);
                        }
                        valueNode.text(this.dataset.copyContent);
                        selection_1.selectAllChildren(valueNode[0]);
                        document.execCommand("copy");
                        window.setTimeout(function () {
                            selection_1.removeAllRanges();
                            if (rangeCount_1 > 0) {
                                selection_1.addRange(range_1);
                            }
                            valueNode.empty();
                        }, 7);
                        _b.label = 3;
                    case 3:
                        markStatus(this, true);
                        self.data("last-time", new Date().getTime()).addClass("text-modified");
                        return [2, false];
                }
            });
        });
    });
    setInterval(function () {
        $("#mw-panel a[data-copy-content].text-modified").each(function () {
            var self = $(this);
            if (self.data("last-time") < new Date().getTime() - 3000) {
                markStatus(this, false);
                self.removeClass("text-modified");
            }
        });
    }, 1000);
    $(window).on("resize", function () {
        $mwPanel.height($body.height());
    });
});

/* </pre> */