MediaWiki:Common.js:修订间差异

imported>=海豚=
无编辑摘要
imported>=海豚=
与萌百同步
第10行: 第10行:
"use strict";
"use strict";
(function($, mw) { //使用匿名函数防止污染顶级变量
(function($, mw) { //使用匿名函数防止污染顶级变量
    /* 反嵌入反反代 */
    try {
        var substHost;
        try {
            substHost = top.location.host;
        } catch (_) {
            substHost = "";
        }
        var currentHostFlag = !/\.moegirl\.org$/i.test(location.host);
        if (top !== window || currentHostFlag) {
            var reverseProxyhostAlerted = [];
            if (sessionStorage.getItem("reverse proxy alerted") !== null) {
                try {
                    reverseProxyhostAlerted = JSON.parse(sessionStorage.getItem("reverse proxy alerted"));
                    if (!Array.isArray(reverseProxyhostAlerted)) { reverseProxyhostAlerted = []; }
                } catch (e) {
                    reverseProxyhostAlerted = [];
                }
            }
            var detectHost = currentHostFlag ? location.host : substHost;
            if (!reverseProxyhostAlerted.includes(detectHost)) {
                reverseProxyhostAlerted.push(detectHost);
                mw.loader.using(["oojs-ui"]).then(function() {
                    var messageDialog = new OO.ui.MessageDialog();
                    var windowManager = new OO.ui.WindowManager();
                    $("body").append(windowManager.$element);
                    windowManager.addWindows([messageDialog]);
                    messageDialog.title.$label.html("萌娘百科提醒您<br>您当前是在" + (currentHostFlag ? "非萌百域名" : "嵌套窗口") + "访问");
                    messageDialog.message.$label.html("<p>请注意不要在此域名下输入您的用户名或密码,以策安全!</p><p>" + (detectHost ? (currentHostFlag ? "当前" : "顶层窗口") + "域名为 " + location.host + ",<br>" : "") + "萌百域名是以 .moegirl.org 结尾的。</p>");
                    windowManager.openWindow(messageDialog, {
                        actions: [{
                            action: 'accept',
                            label: '我知道了',
                            flags: 'primary'
                        }]
                    });
                });
            }
            sessionStorage.setItem("reverse proxy alerted", JSON.stringify(reverseProxyhostAlerted));
        }
    } catch (e) {
        console.debug(e);
    }
    /* capture支持检测 */
    var captureSupported = false;
    try {
        var options = Object.defineProperty({}, "capture", {
            get: function() {
                captureSupported = true;
                return true;
            },
        });
        window.addEventListener("test", null, options);
    } catch (err) { /* */ }
    /* 函数定义体 */
    //滚动公告
    function autoScroll(obj) {
        $(obj).animate({
            height: "show",
            paddingTop: "show",
            marginTop: "show",
            paddingBottom: "show",
            marginBottom: "show",
        });
        var isFrozen = false;
        setInterval(function() {
            if (!isFrozen) {
                $(obj).find("ul:first").animate({
                    marginTop: "-25px",
                }, 500, function() {
                    $(this).css({
                        marginTop: "0px",
                    }).find("li:first").appendTo(this);
                });
            }
        }, 5000);
        $(window).on({
            blur: function() {
                isFrozen = true;
            },
            focus: function() {
                isFrozen = false;
            },
        });
    }
     /* MediaViewer#populateStatsFromXhr 错误屏蔽 */
     /* MediaViewer#populateStatsFromXhr 错误屏蔽 */
     (function() {
     (function() {