2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

MediaWiki:Common.js

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索

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

  • Firefox/Safari:按住“Shift”的同时单击“刷新”,或按“Ctrl-F5”或“Ctrl-R”(Mac为“⌘-R”)
  • Google Chrome:按“Ctrl-Shift-R”(Mac为“⌘-Shift-R”)
  • Internet Explorer:按住“Ctrl”的同时单击“刷新”,或按“Ctrl-F5”
  • Opera:在“工具→首选项”中清除缓存
如果您已登录但该页面出现未登录状态,请尝试在地址栏的地址最后添加代码?_=1来访问最新页面。
添加代码后的本页地址如下:-{R|https://moegirl.icu/MediaWiki:Common.js?_=1}-
引用api时用mw.loader.using(["mediawiki.api"]),引用uri时用mw.loader.using(["mediawiki.Uri"])
萌娘百科界面管理员团队提醒您
大萌字-InterfaceAdmin.png
本页面由萌娘百科界面管理员团队在其 GitHub 库内进行维护,通过机器人自动生成可被 MediaWiki Gadget 扩展接受的版本并保存到此处。 如果您有任何意见或建议,建议您到技术实现版提出。
/**
 * -------------------------------------------------------------------------
 * !!! DON'T MODIFY THIS PAGE MANUALLY, YOUR CHANGES WILL BE OVERWRITTEN !!!
 * -------------------------------------------------------------------------
 */
var _addText = '{{GHIACode|page=GHIA:MoegirlPediaInterfaceCodes/blob/master/src/global/zh/MediaWiki:Common.js|user=[[U:机智的小鱼君]]|co-authors=|longId=c8b2faccc18904d97da04aa1ba61868da2e0f29f|shortId=c8b2facc|summary=chore: compatibility}}'; 

/* <pre> */

"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 (g && (g = 0, op[0] && (_ = 0)), _) 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 () { return __awaiter(void 0, void 0, void 0, function () {
    var _a, wgUserGroups, wgServer, wgServerName, wgScriptPath, wgPageName, wgAction, skin, wgNamespaceNumber, wgMainPageTitle, copyRightsNameSpaces, allowedGroups, allowedInGroup, getResponseHeader, multimediaViewer, crossDomainLink, crossDomainLinkMoeskin, copyRights, noticeActivityClose, parseLocalStorageItemAsArray, topNoticeScroll, crossDomainDetect, leftPanelAvatarLink, hashJump;
    return __generator(this, function (_b) {
        switch (_b.label) {
            case 0:
                _a = mw.config.get(), wgUserGroups = _a.wgUserGroups, wgServer = _a.wgServer, wgServerName = _a.wgServerName, wgScriptPath = _a.wgScriptPath, wgPageName = _a.wgPageName, wgAction = _a.wgAction, skin = _a.skin, wgNamespaceNumber = _a.wgNamespaceNumber, wgMainPageTitle = _a.wgMainPageTitle;
                copyRightsNameSpaces = [
                    0,
                    4,
                    8,
                    10,
                    12,
                    274,
                    828,
                ];
                allowedGroups = ["sysop", "patroller", "staff"];
                allowedInGroup = wgUserGroups.filter(function (group) { return allowedGroups.includes(group); }).length > 0;
                getResponseHeader = XMLHttpRequest.prototype.getResponseHeader;
                XMLHttpRequest.prototype.getResponseHeader = function (name) {
                    return "\n".concat(this.getAllResponseHeaders().toLowerCase()).includes("\n".concat(name.toLowerCase(), ": ")) ? getResponseHeader.bind(this)(name) : (console.info("Refused to get unsafe header \"".concat(name, "\"\n"), this, "\n", new Error().stack), null);
                };
                multimediaViewer = function () {
                    var _scrollTo = window.scrollTo;
                    var flag = location.hash.startsWith("#/media/");
                    window.scrollTo = function (xORoption, y) {
                        if (flag) {
                            console.info("Prevent multimediaViewer called");
                        }
                        else if (y === undefined) {
                            _scrollTo(xORoption);
                        }
                        else {
                            _scrollTo(xORoption, y);
                        }
                    };
                    setInterval(function () {
                        $("a.image img[data-file-width], a.image img[data-file-height], .mw-mmv-filepage-buttons a.mw-mmv-view-expanded").not(".multimediaViewerScrollSet").each(function (_, ele) {
                            ele.addEventListener("click", function (e) {
                                if ($(e.target).closest(".TabLabelText")[0] || $(e.target).closest("a").closest(".mw-customtoggle")[0]) {
                                    e.preventDefault();
                                    e.stopPropagation();
                                    e.stopImmediatePropagation();
                                    $($(e.target).closest(".TabLabelText")[0] || $(e.target).closest("a").closest(".mw-customtoggle")[0]).trigger("click");
                                    return false;
                                }
                                flag = true;
                            }, {
                                capture: true
                            });
                            $(ele).addClass("multimediaViewerScrollSet");
                        });
                        if (document.querySelector(".mw-mmv-close")) {
                            if (mw.config.get("wgMultimediaViewerInjected") !== "on") {
                                mw.config.set("wgMultimediaViewerInjected", "on");
                                $(".mw-mmv-image").off("click")[0].addEventListener("click", function (e) {
                                    if ($(e.target).is("img")) {
                                        window.open($(e.target).attr("src").replace(/(img\.moegirl\.org\.cn\/common\/)thumb\/([a-z\d]+\/[a-z\d]+\/)([^/]+)\/\d+px-\3/i, "$1$2$3"), "_blank").focus();
                                        e.preventDefault();
                                        e.stopPropagation();
                                        e.stopImmediatePropagation();
                                        return false;
                                    }
                                    else if ($(e.target).closest(".error-box")[0]) {
                                        return;
                                    }
                                    $(".mw-mmv-close").trigger("click");
                                }, {
                                    capture: true
                                });
                            }
                        }
                        else if (mw.config.get("wgMultimediaViewerInjected") === "on") {
                            flag = false;
                            mw.config.set("wgMultimediaViewerInjected", "off");
                        }
                    }, 137);
                };
                crossDomainLink = function (url) {
                    var link = url.query.title;
                    var domain = url.host;
                    var crossDomain = $("<div/>");
                    var anchor = $("<a/>");
                    crossDomain.text("<");
                    anchor.attr("href", "".concat(url)).text("".concat(link, " \u3010\u6765\u81EA ").concat(domain, " \u7684\u8DE8\u7AD9\u91CD\u5B9A\u5411\u3011"));
                    crossDomain.append(anchor);
                    $("#contentSub").prepend(crossDomain);
                };
                crossDomainLinkMoeskin = function (url) {
                    var link = url.query.title;
                    var domain = url.host;
                    var crossDomain = $("<div/>");
                    var anchor = $("<a/>");
                    crossDomain.html('<span class="moe-icon"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 256 512"><path d="M31.7 239l136-136c9.4-9.4 24.6-9.4 33.9 0l22.6 22.6c9.4 9.4 9.4 24.6 0 33.9L127.9 256l96.4 96.4c9.4 9.4 9.4 24.6 0 33.9L201.7 409c-9.4 9.4-24.6 9.4-33.9 0l-136-136c-9.5-9.4-9.5-24.6-.1-34z" fill="currentColor"></path></svg></span>');
                    anchor.attr("href", "".concat(url)).text("".concat(link, " \u3010\u6765\u81EA ").concat(domain, " \u7684\u8DE8\u7AD9\u91CD\u5B9A\u5411\u3011"));
                    crossDomain.append(anchor);
                    $("#tagline").after(crossDomain);
                };
                copyRights = function () { return __awaiter(void 0, void 0, void 0, function () {
                    var div, valueNode;
                    return __generator(this, function (_a) {
                        switch (_a.label) {
                            case 0: return [4, mw.loader.using("mediawiki.util")];
                            case 1:
                                _a.sent();
                                div = $("<div>", {
                                    css: {
                                        position: "absolute",
                                        left: "-99999px",
                                        "z-index": "-99999"
                                    },
                                    html: "<pre></pre><br>\n\u9605\u8BFB\u66F4\u591A\uFF1A".concat(/%/.test(mw.util.wikiUrlencode(wgPageName)) ? "".concat(wgPageName, "\uFF08").concat(wgServer).concat(wgScriptPath, "/").concat(encodeURIComponent(wgPageName), " \uFF09") : "".concat(wgServer).concat(wgScriptPath, "/").concat(wgPageName), "<br>\n\u672C\u6587\u5F15\u81EA\u840C\u5A18\u767E\u79D1(").concat(wgServer.replace(/^\/\//, "https://"), " )\uFF0C\u6587\u5B57\u5185\u5BB9\u9ED8\u8BA4\u4F7F\u7528\u300A\u77E5\u8BC6\u5171\u4EAB \u7F72\u540D-\u975E\u5546\u4E1A\u6027\u4F7F\u7528-\u76F8\u540C\u65B9\u5F0F\u5171\u4EAB 3.0 \u4E2D\u56FD\u5927\u9646\u300B\u534F\u8BAE\u3002")
                                }).appendTo("body"), valueNode = div.find("pre");
                                $("#mw-content-text").on("copy", function () {
                                    var selection = window.getSelection(), value = selection.toString(), range = selection.getRangeAt(0);
                                    if (!value.length || value.length < 128
                                        || $(selection.anchorNode).add(selection.basenode).add(selection.focusNode).closest(".Wikiplus-InterBox")[0]) {
                                        return;
                                    }
                                    valueNode.text(value);
                                    selection.selectAllChildren(div[0]);
                                    window.setTimeout(function () {
                                        selection.removeAllRanges();
                                        selection.addRange(range);
                                        valueNode.empty();
                                    }, 0);
                                });
                                return [2];
                        }
                    });
                }); };
                noticeActivityClose = function () { return __awaiter(void 0, void 0, void 0, function () {
                    var noticeActivity, isMoeskin, styles, topNoticeId_1, container_1, children_1, button_1, link_1, status_1, localStorageValue;
                    return __generator(this, function (_a) {
                        switch (_a.label) {
                            case 0:
                                noticeActivity = $("body").children("#content, #app").find("#notice-activity");
                                isMoeskin = skin === "moeskin";
                                styles = skin === "moeskin"
                                    ? {
                                        visible: {
                                            "user-select": "none",
                                            "text-align": "center",
                                            "box-sizing": "inherit",
                                            background: "none",
                                            margin: "0",
                                            border: "0",
                                            font: "inherit",
                                            "vertical-align": "baseline",
                                            "text-decoration": "none",
                                            position: "absolute",
                                            top: ".2rem",
                                            color: "#fff",
                                            "background-color": "#00000080",
                                            "border-radius": "99em",
                                            padding: ".1rem .5rem",
                                            "line-height": "1.5",
                                            right: ".2rem",
                                            "z-index": "999999",
                                            cursor: "pointer"
                                        },
                                        hidden: {
                                            top: "-0.8rem"
                                        }
                                    }
                                    : {
                                        visible: {
                                            position: "absolute",
                                            right: "1rem",
                                            top: "50%",
                                            transform: "translate(0,-50%)",
                                            fontSize: "1rem"
                                        },
                                        hidden: {
                                            transform: "translate(0,0)"
                                        }
                                    };
                                if (!(noticeActivity.length > 0)) return [3, 2];
                                return [4, mw.loader.using(["user.options"])];
                            case 1:
                                _a.sent();
                                if (+mw.user.options.get("gadget-noticeActivity") === 1) {
                                }
                                topNoticeId_1 = noticeActivity.data("topNoticeId");
                                container_1 = isMoeskin ? noticeActivity.parent() : noticeActivity;
                                container_1.css("position", "relative");
                                children_1 = container_1.children();
                                button_1 = $("<span>");
                                button_1.css(styles.visible);
                                link_1 = $("<a>");
                                link_1.attr({
                                    href: "javascript:void(0);"
                                }).text("隐藏活动通知");
                                button_1.append(link_1);
                                if (!isMoeskin) {
                                    button_1.prepend("[").append(link_1).append("]");
                                }
                                else {
                                    link_1.css({
                                        color: "white"
                                    });
                                }
                                container_1.append(button_1);
                                status_1 = true;
                                link_1.on("click", function () {
                                    if (status_1) {
                                        status_1 = false;
                                        children_1.hide();
                                        noticeActivity.css({
                                            height: "0px"
                                        });
                                        container_1.css({
                                            overflow: "visible",
                                            "background-color": "transparent"
                                        });
                                        button_1.css(styles.hidden);
                                        localStorage.setItem("AnnTools-notice-activity", topNoticeId_1);
                                        link_1.text("显示活动通知");
                                    }
                                    else {
                                        status_1 = true;
                                        children_1.show();
                                        noticeActivity.css({
                                            height: "auto"
                                        });
                                        container_1.css({
                                            overflow: "visible",
                                            "background-color": isMoeskin ? "var(--theme-card-background-color)" : "transparent"
                                        });
                                        button_1.css(styles.visible);
                                        localStorage.removeItem("AnnTools-notice-activity");
                                        link_1.text("隐藏活动通知");
                                    }
                                });
                                localStorageValue = localStorage.getItem("AnnTools-notice-activity");
                                if (localStorageValue === topNoticeId_1) {
                                    link_1.trigger("click");
                                }
                                _a.label = 2;
                            case 2: return [2];
                        }
                    });
                }); };
                parseLocalStorageItemAsArray = function (key) {
                    try {
                        var result = JSON.parse(localStorage.getItem(key));
                        return Array.isArray(result) ? result : [];
                    }
                    catch (_a) {
                        return [];
                    }
                };
                topNoticeScroll = function () { return __awaiter(void 0, void 0, void 0, function () {
                    var siteNotice, noticeType, newNotices, notification_1;
                    return __generator(this, function (_a) {
                        switch (_a.label) {
                            case 0:
                                siteNotice = $("body.skin-vector > #content > #siteNotice, body.skin-moeskin > #app > #moe-full-container > #moe-main-container > main > #moe-global-sidenav #moe-sidenav-sitenotice");
                                noticeType = {
                                    pinnedAnnouncement: "置顶公告",
                                    newAnnouncement: "7日内新公告",
                                    discussing: "新的讨论中提案、申请",
                                    voting: "新的投票中提案、申请",
                                    voted: "新的已投票结束提案、申请"
                                };
                                newNotices = [];
                                Object.keys(noticeType).forEach(function (type) {
                                    var id = type;
                                    var links = siteNotice.find("#topNotice-".concat(type)).find("a");
                                    var existLinks = parseLocalStorageItemAsArray("AnnTools-top-notice-exist-".concat(id));
                                    var currentLinks = [];
                                    var newLinks = [];
                                    links.each(function (_, link) {
                                        var href = link.href;
                                        var text = link.text.trim();
                                        currentLinks.push(href);
                                        if (!existLinks.includes(href)) {
                                            newLinks.push({
                                                href: href,
                                                text: text
                                            });
                                        }
                                    });
                                    localStorage.setItem("AnnTools-top-notice-exist-".concat(id), JSON.stringify(currentLinks));
                                    if (newLinks.length > 0) {
                                        newNotices.push({
                                            type: noticeType[id],
                                            links: newLinks
                                        });
                                    }
                                });
                                if (!(newNotices.length > 0)) return [3, 2];
                                $("#mw-notification-area").appendTo("body");
                                notification_1 = $("<dl>");
                                newNotices.forEach(function (newNotice) {
                                    notification_1.append("<dt class=\"mw-parser-output\" style=\"font-weight: 400;\">".concat(newNotice.type, "\uFF1A</dt>"));
                                    var dd = $("<dd>");
                                    var ul = $("<ul>");
                                    dd.css("marginLeft", ".9em");
                                    newNotice.links.forEach(function (link) {
                                        var li = $("<li>");
                                        var a = $("<a>");
                                        a.attr({
                                            href: link.href,
                                            target: "_blank",
                                            "class": "external"
                                        }).text(link.text);
                                        a.appendTo(li);
                                        li.appendTo(ul);
                                    });
                                    ul.appendTo(dd);
                                    dd.appendTo(notification_1);
                                });
                                notification_1.find("a").on("click", function (e) {
                                    e.stopImmediatePropagation();
                                    e.stopPropagation();
                                });
                                return [4, mw.loader.using(["mediawiki.notification", "mediawiki.notify"])];
                            case 1:
                                _a.sent();
                                mw.notify(notification_1, {
                                    autoHide: false,
                                    title: "有新的站务通知(点击通知空白处关闭)"
                                });
                                _a.label = 2;
                            case 2: return [2];
                        }
                    });
                }); };
                crossDomainDetect = function () { return __awaiter(void 0, void 0, void 0, function () {
                    var rdfrom, rdfromUri, query;
                    return __generator(this, function (_a) {
                        switch (_a.label) {
                            case 0: return [4, mw.loader.using(["mediawiki.Uri"])];
                            case 1:
                                _a.sent();
                                rdfrom = new mw.Uri().query.rdfrom;
                                if (rdfrom) {
                                    rdfromUri = new mw.Uri(rdfrom);
                                    if (!rdfromUri.host.includes([104, 109, 111, 101].map(function (n) { return String.fromCharCode(n); }).join(""))) {
                                        query = rdfromUri.query;
                                        if (query.title && query.redirect === "no") {
                                            if (skin === "moeskin") {
                                                crossDomainLinkMoeskin(rdfromUri);
                                            }
                                            else {
                                                crossDomainLink(rdfromUri);
                                            }
                                        }
                                    }
                                }
                                return [2];
                        }
                    });
                }); };
                leftPanelAvatarLink = function () { return __awaiter(void 0, void 0, void 0, function () {
                    return __generator(this, function (_a) {
                        switch (_a.label) {
                            case 0: return [4, mw.loader.using(["mediawiki.Uri"])];
                            case 1:
                                _a.sent();
                                $("#t-viewavatar > a").each(function (_, ele) {
                                    var uri = new mw.Uri(ele.href);
                                    uri.host = uri.host.replace("zh.moegirl", "commons.moegirl");
                                    ele.href = uri;
                                });
                                return [2];
                        }
                    });
                }); };
                hashJump = function () { return __awaiter(void 0, void 0, void 0, function () {
                    var hash;
                    return __generator(this, function (_a) {
                        switch (_a.label) {
                            case 0: return [4, mw.loader.using(["jquery.makeCollapsible"])];
                            case 1:
                                _a.sent();
                                $(".mw-collapsible").makeCollapsible();
                                hash = location.hash;
                                location.hash = "";
                                location.hash = hash;
                                return [2];
                        }
                    });
                }); };
                return [4, $.ready];
            case 1:
                _b.sent();
                multimediaViewer();
                if (wgMainPageTitle === wgPageName && wgAction === "view") {
                    $("body").addClass("mainpage");
                }
                if (window.getSelection && !allowedInGroup && !["edit", "submit"].includes(wgAction) && copyRightsNameSpaces.includes(wgNamespaceNumber)) {
                    copyRights();
                }
                $.extend({
                    ucFirst: function (_s) {
                        var s = "".concat(_s);
                        return s.charAt(0).toUpperCase() + s.substring(1);
                    }
                });
                $(".reference-text > ul,.reference-text > ol").each(function (_, ele) {
                    if (ele.parentElement.childNodes[0] === ele) {
                        $(ele).addClass("listInRef");
                    }
                });
                if ($(".mw-collapsible")[0] && location.hash !== "") {
                    hashJump();
                }
                noticeActivityClose();
                crossDomainDetect();
                leftPanelAvatarLink();
                if (wgUserGroups.includes("user")) {
                    topNoticeScroll();
                }
                if (!allowedInGroup && $(".will2Be2Deleted")[0]) {
                    $("#ca-move").remove();
                }
                if (["mzh.moegirl.org.cn", "zh.moegirl.org.cn"].includes(wgServerName)) {
                    $('a.external.text[href$="&action=edit"], .plainlinks.userlink .external').each(function (_, ele) {
                        var $ele = $(ele);
                        $ele.attr("href", $ele.attr("href").replace(/(?:mobile|mzh|zh)\.moegirl\.org\.cn/, wgServerName));
                    });
                }
                $(window).on("load", function () {
                    $(".mw-helplink").each(function (_, ele) {
                        if (!ele.href.endsWith("/zh")) {
                            ele.href += "/zh";
                        }
                    });
                });
                return [2];
        }
    });
}); })(); 

/* </pre> */