MediaWiki:Common.js/edit.js

H萌娘,万物皆可H的百科全书!
跳到导航 跳到搜索

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

1. 桌面版CSS MediaWiki:Common.css
2. 桌面版JS MediaWiki:Common.js
3. 移动端CSS MediaWiki:Mobile.css
4. 移动端JS MediaWiki:Mobile.js
5. 全局共用CSS MediaWiki:Gadget-site-styles.css
6. 全局共用JS MediaWiki:Gadget-site-javascript.js
7. 管理员CSS MediaWiki:Group-sysop.css
8. 管理员JS MediaWiki:Group-sysop.js
9. 编辑时载入 MediaWiki:Common.js/edit.js
引用api时用mw.loader.using("mw.Api"),引用uri时用mw.loader.using("mediawiki.Uri")
/* Any JavaScript here will be loaded for all users on edit page load. */
// <pre>
$(function() {
    if (mw.config.get("wgPageName").startsWith("H萌娘讨论:讨论版")) {
        $(".mw-editnotice + .mw-warning-with-logexcerpt").hide();
    }

    var wpSummary = $('[name="wpSummary"]');
    // $(".mw-summary-preset-item a").closest('.oo-ui-fieldLayout-header').width($('#wpSummary').width());
    $(".mw-summary-preset-item a").on("click", function() {
        wpSummary.val(wpSummary.val() + " " + $(this).text());
        wpSummary.focus();
        return false;
    });

    // .wikiEditor-ui-controls 颜色修正
    $('.wikiEditor-ui-controls').css('background-color', $('#content').css('background-color'));

    //编辑请求
    var prefixNumber = function(num) {
        var result = "" + num;
        if (result.length === 1) {
            result = "0" + result;
        }
        return result;
    };
    if (["edit", "submit"].indexOf(mw.config.get("wgAction")) !== -1 && !!$(".permissions-errors, #wpTextbox1[readonly]")[1] && mw.config.get("wgUserName") && !$(".newComment")[0]) {
        var wgNamespaceIds = Object.entries(mw.config.get("wgNamespaceIds")),
            wgNamespaceNumber = mw.config.get("wgNamespaceNumber"),
            ns = [];
        if (wgNamespaceNumber < 0 || wgNamespaceNumber % 2 === 1) {
            return;
        }
        var talkNamespaceNumber = wgNamespaceNumber + 1;
        var talkns = -1;
        wgNamespaceIds.sort(function(_a, _b) {
            var a = _a[0],
                b = _b[0];
            if (a === "") {
                if (b === "") {
                    return 0;
                }
                return -1;
            }
            if (b === "") {
                return 1;
            }
            return a[0].codePointAt() - b[0].codePointAt();
        });
        wgNamespaceIds.forEach(function(_ns) {
            var i = _ns[0],
                n = _ns[1];
            if (n === wgNamespaceNumber) { ns.push(i); }
            if (talkns === -1 && n === talkNamespaceNumber) { talkns = i; }
        });
        if (!ns[0]) { return; }
        var page = mw.config.get("wgPageName");
        var pageToLowerCase = page.toLowerCase();
        for (var j = 0, l = ns.length; j < l; j++) {
            if (pageToLowerCase.startsWith(ns[j])) {
                page = page.replace(new RegExp("^" + ns[j] + ":", "i"), "");
                break;
            }
        }
        var talkpage = talkns + ":" + page;
        var container = $("<div/>", {
            "class": "editRequest",
        });
        var now = new Date();
        container.append("您虽然无权编辑本页面,但您可以点击右侧按钮在本页的讨论页提出编辑请求,让可以编辑的人代为编辑:");
        $("<span/>").addClass("newComment").text("提出编辑请求").on("click", function() {
            window.open(mw.config.get("wgServer") + mw.config.get("wgScriptPath") + "/index.php?action=edit&preload=Template:编辑请求/comment&preloadtitle=编辑请求 - " + encodeURIComponent(mw.config.get("wgUserName") + " - " + now.getFullYear() + "." + prefixNumber(now.getMonth() + 1) + "." + prefixNumber(now.getDate())) + "&section=new&title=" + encodeURIComponent(talkpage), "_blank");
        }).appendTo(container);
        $("#mw-content-text").children(".wikiEditor-ui:first, textarea[readonly]:first").before("<hr>").before(container);
    }

    const explainconflict = $("#mw-content-text > .mw-explainconflict #explainconflict-info");
    if (explainconflict[0]) {
        $("html, body").animate({
            scrollTop: explainconflict.closest(".infoBox").offset().top - 2,
        }, 137);
    }
});
// </pre>