|
|
| 第1行: |
第1行: |
| /* eslint-disable no-var */
| |
| /* eslint-disable no-magic-numbers */
| |
| /* global OO, mediaWiki, jQuery */
| |
| // <nowiki>
| |
| /* 这里的任何JavaScript将在全站加载
| |
| * loader模块 写法参见 https://www.mediawiki.org/wiki/ResourceLoader/Modules#mw.loader.load
| |
| */
| |
| "use strict";
| |
| (function($, mw) { //使用匿名函数防止污染顶级变量
| |
| /* MediaViewer#populateStatsFromXhr 错误屏蔽 */
| |
| (function() {
| |
| var getResponseHeader = XMLHttpRequest.prototype.getResponseHeader;
| |
| XMLHttpRequest.prototype.getResponseHeader = function(name) {
| |
| return ("\n" + this.getAllResponseHeaders().toLowerCase()).includes("\n" + name.toLowerCase() + ": ") ? getResponseHeader.call(this, name) : (console.debug('Refused to get unsafe header "' + name + '"\n', this, "\n", new Error().stack), null);
| |
| };
| |
| })();
| |
| //Extension:MultimediaViewer的半透明化修改。
| |
| function multimediaViewer() {
| |
| var _scrollTo = window.scrollTo;
| |
| var flag = location.hash !== "";
| |
| window.scrollTo = function scrollTo(x_option, y) {
| |
| if (flag) {
| |
| console.info("Prevent multimediaViewer called");
| |
| } else {
| |
| if (y === undefined) { _scrollTo(x_option); } else { _scrollTo(x_option, 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() {
| |
| this.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]).click();
| |
| return false;
| |
| }
| |
| flag = true;
| |
| }, captureSupported ? {
| |
| capture: true,
| |
| } : true);
| |
| $(this).addClass("multimediaViewerScrollSet");
| |
| });
| |
| if ($(".mw-mmv-close")[0]) {
| |
| 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\/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").click();
| |
| }, captureSupported ? {
| |
| capture: true,
| |
| } : true);
| |
| }
| |
| } else if (mw.config.get("wgMultimediaViewerInjected") === "on") {
| |
| flag = false;
| |
| mw.config.set("wgMultimediaViewerInjected", "off");
| |
| }
| |
| }, 137);
| |
| }
| |
| //子页面页顶链接
| |
| function subpage_links() {
| |
| var links = mw.config.get("wgPageName").split("/"),
| |
| link = "",
| |
| subpages = $(".subpages")[0] ? $(".subpages").remove().empty().text("<") : $('<span class="subpages"/>').text("<"),
| |
| length = links.length - 1,
| |
| index;
| |
| if (mw.config.get("wgPageName").indexOf("Special:移动页面") !== -1) { links.splice(0, 1); }
| |
| for (index = 0; index < length; index++) {
| |
| link += "/" + links[index];
| |
| subpages.append($("<a/>", {
| |
| text: " " + links[index],
| |
| href: link,
| |
| }));
| |
| if (length - index > 1) { subpages.append(" |"); }
| |
| }
| |
| if (subpages.find("a")[0]) { $("#contentSub").prepend(subpages); }
| |
| }
| |
| //跨站重定向页顶链接
| |
| function crossDomain_link() {
| |
| var url = new mw.Uri(new mw.Uri().query.rdfrom);
| |
| var link = url.query.title;
| |
| var domain = url.host;
| |
| var crossDomain = $("<div/>");
| |
| var anchor = $("<a/>");
| |
| crossDomain.text("<");
| |
| anchor.attr("href", url + "").text(link + "【来自 " + domain + "】");
| |
| crossDomain.append(anchor);
| |
| $("#contentSub").prepend(crossDomain);
| |
| }
| |
| //重复文件列表函数
| |
| 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"); }
| |
| $("#mw-content-text .mw-spcontent ol").attr("id",
| |
| "picOl");
| |
| $("#picOl").before('<p id="picOlTitle">图片列表:</p>').after('<p id="MP3OlTitle">MP3列表:</p><ol start="1" id="MP3Ol"></ol>');
| |
| $("#picOlTitle, #MP3OlTitle").hide();
| |
| $("#picOl").find("[href$='.mp3'], [href$='.ogg']").parent().appendTo("#MP3Ol");
| |
| if ($("#picOl").find("li").length) { $("#picOlTitle").show(); }
| |
| if ($("#MP3Ol").find("li").length) { $("#MP3OlTitle").show(); }
| |
| $(".mw-spcontent > p:nth-child(1), .mw-spcontent > p:nth-child(2), .mw-spcontent > p:nth-child(7)").hide();
| |
| }
| |
| //编辑请求
| |
| function editRequest() {
| |
| var nsIds = mw.config.get("wgNamespaceIds"),
| |
| nsId = mw.config.get("wgNamespaceNumber"),
| |
| ns = [];
| |
| for (var i in nsIds) {
| |
| if (nsIds[i] === nsId) { ns.push(i); }
| |
| }
| |
| if (!ns[0]) { return; }
| |
| var page = mw.config.get("wgPageName"),
| |
| talkns;
| |
| for (var j = 0, l = ns.length; j < l; j++) {
| |
| if (/^[A-Za-z0-9]+[ _]talk$/i.test(ns[j])) { return; }
| |
| if (/^[a-zA-Z0-9]+$/.test(ns[j])) { talkns = ns[j] + "_talk:"; }
| |
| page = page.replace(new RegExp("^" + ns[j] + ":", "i"), "");
| |
| }
| |
| var talkpage = talkns + page;
| |
| var container = $("<div/>", {
| |
| "class": "editRequest",
| |
| });
| |
| container.append("您虽然无权编辑本页面,但您可以点击右侧按钮在本页的讨论页提出编辑请求,让可以编辑的人代为编辑:");
| |
| $("<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") + "§ion=new&title=" + talkpage, "_blank");
| |
| }).appendTo(container);
| |
| $("#mw-content-text").children(".wikiEditor-ui:first, textarea[readonly]:first").before("<hr>").before(container);
| |
| }
| |
| /* 函数执行体 */
| |
| $(function() {
| |
| //Template:heimu在safari上的暴力workaround
| |
| mw.loader.using("jquery.client", function() {
| |
| if ($.client.profile().name === "safari") {
| |
| $(".heimu").on("click", function() {
| |
| $(this).toggleClass("off");
| |
| });
| |
| }
| |
| });
| |
| //Extension:MultimediaViewer的半透明化修改
| |
| if ($("img[srcset][data-file-width][data-file-height]")[0]) { multimediaViewer(); }
| |
| // Add "mainpage" class to the body element
| |
| if (mw.config.get("wgMainPageTitle") === mw.config.get("wgPageName") && mw.config.get("wgAction") === "view") { $("body").addClass("mainpage"); }
| |
| //重复文件列表区分图片和音频
| |
| if ($(".mw-special-ListDuplicatedFiles").length && $(".mw-spcontent > p").length > 1) { duplicatedFileList(); }
| |
| //需要时载入对应的 scripts
| |
| if (mw.config.get("wgAction") === "edit" || mw.config.get("wgAction") === "submit" || mw.config.get("wgCanonicalSpecialPageName") === "Search") { mw.loader.load("/index.php?title=MediaWiki:Common.js/edit.js&action=raw&ctype=text/javascript"); }
| |
| //子页面页顶链接
| |
| if (mw.config.get("wgPageName").indexOf("/") !== -1 && (mw.config.get("wgNamespaceIds").special !== mw.config.get("wgNamespaceNumber") || mw.config.get("wgPageName").indexOf("Special:移动页面") !== -1) && !window._unsubpage) { subpage_links(); }
| |
| //跨站重定向页顶链接
| |
| mw.loader.using("mediawiki.Uri").then(function() {
| |
| if (new mw.Uri().query.rdfrom && new mw.Uri(new mw.Uri().query.rdfrom).query.title && new mw.Uri(new mw.Uri().query.rdfrom).query.redirect === "no") { crossDomain_link(); }
| |
| });
| |
| //编辑请求
| |
| if (["edit", "submit"].indexOf(mw.config.get("wgAction")) !== -1 && !!$(".permissions-errors, #wpTextbox1[readonly]")[1] && mw.config.get("wgUserName")) { editRequest(); }
| |
| //修复代码编辑器$.ucFirst引用错误
| |
| $.extend({
| |
| ucFirst: function(_s) {
| |
| var s = _s + "";
| |
| return s.charAt(0).toUpperCase() + s.substring(1);
| |
| },
| |
| });
| |
| //注释内列表
| |
| $(".reference-text > ul,.reference-text > ol").each(function() {
| |
| if (this.parentElement.childNodes[0] === this) { $(this).addClass("listInRef"); }
| |
| });
| |
| //修正hash跳转错误
| |
| if ($(".mw-collapsible")[0]) {
| |
| mw.loader.using("jquery.makeCollapsible", function() {
| |
| $(".mw-collapsible").makeCollapsible();
| |
| var hash = location.hash;
| |
| location.hash = "";
| |
| location.hash = hash;
| |
| });
| |
| }
| |
|
| |
|
| //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); //立即执行匿名函数并传递原始变量以防止冲突
| |
| // </nowiki>
| |