MediaWiki:Common.js:修订间差异

添加4,685字节 、​ 2022年11月20日 (星期日)
fix
imported>=海豚=
无编辑摘要
(fix)
 
(未显示3个用户的46个中间版本)
第1行: 第1行:
/* eslint-disable no-var */
/* 这里的任何JavaScript将在全站加载 */
/* eslint-disable no-magic-numbers */
/* global OO, mediaWiki, jQuery */
// <nowiki>
// <nowiki>
/* 这里的任何JavaScript将在全站加载
*  loader模块 写法参见 https://www.mediawiki.org/wiki/ResourceLoader/Modules#mw.loader.load
*/
"use strict";
"use strict";
(function($, mw) { //使用匿名函数防止污染顶级变量
(function($, mw) { //使用匿名函数防止污染顶级变量
   /* capture支持检测 */
   var captureSupported = false;
   try {
     var options = Object.defineProperty({}, "capture", {
       get: function () {
         captureSupported = true;
         return true;
       },
     });
     window.addEventListener("test", null, options);
   } catch (err) { /* */ }
   /* 检查是否为维护组成员 */
   var wgUserGroups = mw.config.get("wgUserGroups");
   var isMGPMGUser = wgUserGroups.includes("patroller") || wgUserGroups.includes("sysop");
   //滚动公告
   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;
       },
     });
   }
     autoScroll("#scrollDiv");
    /* MediaViewer#populateStatsFromXhr 错误屏蔽 */
    /* MediaViewer#populateStatsFromXhr 错误屏蔽 */
    (function() {
    (function() {
第47行: 第87行:
            $(".mw-mmv-image").off("click")[0].addEventListener("click", function(e) {
            $(".mw-mmv-image").off("click")[0].addEventListener("click", function(e) {
              if ($(e.target).is("img")) {
              if ($(e.target).is("img")) {
                window.open($(e.target).attr("src").replace(/(img\.moegirl\.org\/common\/)thumb\/([a-z\d]+\/[a-z\d]+\/)([^/]+)\/\d+px-\3/i, "$1$2$3"), "_blank").focus();
                window.open($(e.target).attr("src").replace(/(www\.hmoegirl\.info\/common\/)thumb\/([a-z\d]+\/[a-z\d]+\/)([^/]+)\/\d+px-\3/i, "$1$2$3"), "_blank").focus();
                e.preventDefault();
                e.preventDefault();
                e.stopPropagation();
                e.stopPropagation();
第64行: 第104行:
      }, 137);
      }, 137);
    }
    }
     //修复代码编辑器$.ucFirst引用错误
     $.extend({
       ucFirst: function (_s) {
         var s = _s + "";
         return s.charAt(0).toUpperCase() + s.substring(1);
       },
     });
    //子页面页顶链接
    //子页面页顶链接
    function subpage_links() {
    function subpage_links() {
第96行: 第143行:
    //重复文件列表函数
    //重复文件列表函数
    function duplicatedFileList() {
    function duplicatedFileList() {
      if (window.location.href.indexOf("title") === -1) { window.location.replace("http://www.hmoegirl.com/index.php?title=Special:ListDuplicatedFiles&limit=500&offset=0"); }
      if (window.location.href.indexOf("title") === -1) { window.location.replace("http://www.hmoegirl.info/index.php?title=Special:ListDuplicatedFiles&limit=500&offset=0"); }
      $("#mw-content-text .mw-spcontent ol").attr("id",
      $("#mw-content-text .mw-spcontent ol").attr("id",
        "picOl");
        "picOl");
第106行: 第153行:
      $(".mw-spcontent > p:nth-child(1), .mw-spcontent > p:nth-child(2), .mw-spcontent > p:nth-child(7)").hide();
      $(".mw-spcontent > p:nth-child(1), .mw-spcontent > p:nth-child(2), .mw-spcontent > p:nth-child(7)").hide();
    }
    }
     //关键词警告
   function antiAbuseListener(textarea, event) {
     var filters = [
       "{{即将删除",
       "{{挂删",
       "{{模板:即将删除",
       "{{template:即将删除",
       "[[分类:即将删除的页面]]",
       "[[category:即将删除的页面]]",
       "开发票",
       "支那",
       "zhina",
     ];
     var text1 = textarea.value;
     text1 = text1.replace(/<\/?(?:nowiki|noinclude)>/g, "");
     text1 = text1.replace(/<(onlyinclude|includeonly)>.*?<\/\1>/g, "");
     var text2 = textarea.value;
     text2 = text2.replace(/<\/?(?:onlyinclude|includeonly)>/g, "");
     text2 = text2.replace(/<(nowiki|noinclude)>.*?<\/\1>/g, "");
     var results = [];
     for (var i = 0, l = filters.length; i < l; i++) {
       var regExp = new RegExp(filters[i].replace(/\[/g, "\\["), "i");
       if (regExp.test(text1) || regExp.test(text2)) { results.push(filters[i]); }
     }
     if (results.length > 0) {
       var messageDialog = new OO.ui.MessageDialog();
       var windowManager = new OO.ui.WindowManager();
       $("body").append(windowManager.$element);
       windowManager.addWindows([messageDialog]);
       messageDialog.title.$label.html("H萌娘提醒您");
       messageDialog.message.$label.html("<br>您提交的内容包含以下违规内容,被禁止提交:<br><br><ul>" + results.map(function (result) {
         return "<li>" + result + "</li>";
       }).join("") + '</ul><br>如果您认为您的编辑无误,请在自行保存编辑内容后到讨论版提问!');
       windowManager.openWindow(messageDialog, {
         actions: [{
           action: "accept",
           label: "我知道了",
           flags: "primary",
         }],
       });
       event.preventDefault();
       event.stopImmediatePropagation();
       event.stopPropagation();
       return false;
     }
   }
   function antiAbuse(textarea, submitButton, form) {
     mw.loader.using(["oojs-ui"]).then(function () {
       if (submitButton) {
         submitButton.addEventListener("click", function (e) {
           antiAbuseListener(textarea, e);
         }, captureSupported ? {
           capture: true,
         } : true);
       }
       if (form) {
         form.addEventListener("submit", function (e) {
           antiAbuseListener(textarea, e);
         }, captureSupported ? {
           capture: true,
         } : true);
       }
     });
   }
    //防滥用即将删除
     if (!isMGPMGUser) {
       setInterval(function () {
         if ($(".Wikiplus-InterBox")[0]) {
           var targetBox = $(".Wikiplus-InterBox");
           var textarea = $("#Wikiplus-Quickedit")[0];
           var submitButton = $("#Wikiplus-Quickedit-Submit");
           if (textarea && targetBox.data("isTrusted") !== true) {
             targetBox.data("isTrusted", true);
             targetBox.css("z-index", 100);
             antiAbuse(textarea, submitButton[0], undefined);
             var events = $._data(textarea, "events");
             if (events && events.keydown) {
               events.keydown.sort(function (a, b) {
                 return a.guid - b.guid;
               });
               events.keydown[0].handler = function (e) {
                 if (e.ctrlKey && e.which === 83) {
                   if (e.shiftKey) {
                     $("#Wikiplus-Quickedit-MinorEdit").click();
                   }
                   if (antiAbuseListener(textarea, e) !== false) {
                     submitButton.click();
                     e.preventDefault();
                     e.stopPropagation();
                   }
                 }
               };
             }
           }
         }
         if ($("form#editform")[0]) {
           var targetForm = $("form#editform");
           if (targetForm.data("isTrusted") !== true) {
             targetForm.data("isTrusted", true);
             antiAbuse($("#wpTextbox1")[0], $("#wpSave")[0], targetForm[0]);
           }
         }
       }, 1000);
     }
    //编辑请求
    //编辑请求
    function editRequest() {
    function editRequest() {
第128行: 第279行:
      container.append("您虽然无权编辑本页面,但您可以点击右侧按钮在本页的讨论页提出编辑请求,让可以编辑的人代为编辑:");
      container.append("您虽然无权编辑本页面,但您可以点击右侧按钮在本页的讨论页提出编辑请求,让可以编辑的人代为编辑:");
      $("<span/>").addClass("newComment").text("提出编辑请求").on("click", function() {
      $("<span/>").addClass("newComment").text("提出编辑请求").on("click", function() {
        window.open("https://www.hmoegirl.com/index.php?action=edit&preload=Template:编辑请求/comment&preloadtitle=编辑请求 - " + mw.config.get("wgUserName") + "&section=new&title=" + talkpage, "_blank");
        window.open("https://www.hmoegirl.info/index.php?action=edit&preload=Template:编辑请求/comment&preloadtitle=编辑请求 - " + mw.config.get("wgUserName") + "&section=new&title=" + talkpage, "_blank");
      }).appendTo(container);
      }).appendTo(container);
      $("#mw-content-text").children(".wikiEditor-ui:first, textarea[readonly]:first").before("<hr>").before(container);
      $("#mw-content-text").children(".wikiEditor-ui:first, textarea[readonly]:first").before("<hr>").before(container);
第189行: 第340行:
        });
        });
      }
      }
   //R18警告
   function r18Warning() {
     var content = $('<div id="x18"><div id="x18Context"><div id="x18Title"><div id="x18Icon"></div></div><div class="x18Button"></div></div></div>');
     if (!window.localStorage.getItem('x18')) { //如果没有x18记录
       $('body').css('overflow', 'hidden'); //禁止滚屏
       $('#mw-content-text').css({
         'opacity': 0
       });
   //禁止偷看
       content.prependTo('body').find('.x18Button').append('<div id="x18Yes">是</div><div id="x18No" class="x18Button">否</div>')
         .end().find('#x18Title').append('你是否已年满十八岁?')
         .end().delay(400).queue(function() {
           $(this).css({
             'opacity': 1
           }); //显示警告信息
           $(this).dequeue();
         });
       $('#x18Yes').on('click', function() {
         window.localStorage.setItem('x18', true); //记录x18
         $('#mw-content-text').css('opacity', 1).removeAttr('style'); //显示内容
         $("#x18").remove(); //移除警告信息
         $('body').removeAttr('style'); //允许滚屏
       });
       $('#x18No').on('click', function() {
         window.location.replace(window.location.origin + '/' + mw.config.get('wgMainPageTitle')); //不给你看
       });
     } else $("#x18").remove(); //如果有x18记录
   }
   $(function() {
     r18Warning();
    });
    });
})();
})(jQuery, mediaWiki); //立即执行匿名函数并传递原始变量以防止冲突
})(jQuery, mediaWiki); //立即执行匿名函数并传递原始变量以防止冲突
// </nowiki>
// </nowiki>