MediaWiki:Common.js:修订间差异
imported>AnnAngela 无编辑摘要 |
小 fix |
||
| (未显示3个用户的57个中间版本) | |||
| 第1行: | 第1行: | ||
/* | /* 这里的任何JavaScript将在全站加载 */ | ||
// <nowiki> | // <nowiki> | ||
"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(/( | 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. | 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) { | function antiAbuseListener(textarea, event) { | ||
var filters = [ | var filters = [ | ||
"{{即将删除", | "{{即将删除", | ||
"{{挂删", | "{{挂删", | ||
"{{模板:即将删除", | "{{模板:即将删除", | ||
"{{template:即将删除", | "{{template:即将删除", | ||
"[[分类:即将删除的页面]]", | |||
"[[分类:即将删除的页面 | "[[category:即将删除的页面]]", | ||
"开发票", | |||
"[[category:即将删除的页面", | "支那", | ||
" | "zhina", | ||
" | |||
" | |||
]; | ]; | ||
var text1 = textarea.value; | var text1 = textarea.value; | ||
| 第173行: | 第182行: | ||
$("body").append(windowManager.$element); | $("body").append(windowManager.$element); | ||
windowManager.addWindows([messageDialog]); | windowManager.addWindows([messageDialog]); | ||
messageDialog.title.$label.html("H萌娘提醒您 | messageDialog.title.$label.html("H萌娘提醒您"); | ||
messageDialog.message.$label.html("<br> | messageDialog.message.$label.html("<br>您提交的内容包含以下违规内容,被禁止提交:<br><br><ul>" + results.map(function (result) { | ||
return "<li>" + result + "</li>"; | return "<li>" + result + "</li>"; | ||
}).join("") + '</ul><br> | }).join("") + '</ul><br>如果您认为您的编辑无误,请在自行保存编辑内容后到讨论版提问!'); | ||
windowManager.openWindow(messageDialog, { | windowManager.openWindow(messageDialog, { | ||
actions: [{ | actions: [{ | ||
| 第190行: | 第199行: | ||
} | } | ||
} | } | ||
function antiAbuse(textarea, submitButton, form) { | function antiAbuse(textarea, submitButton, form) { | ||
mw.loader.using(["oojs-ui"]).then(function() { | mw.loader.using(["oojs-ui"]).then(function () { | ||
if (submitButton) { | if (submitButton) { | ||
submitButton.addEventListener("click", function(e) { | submitButton.addEventListener("click", function (e) { | ||
antiAbuseListener(textarea, e); | antiAbuseListener(textarea, e); | ||
}, captureSupported ? { | }, captureSupported ? { | ||
| 第201行: | 第209行: | ||
} | } | ||
if (form) { | if (form) { | ||
form.addEventListener("submit", function(e) { | form.addEventListener("submit", function (e) { | ||
antiAbuseListener(textarea, e); | antiAbuseListener(textarea, e); | ||
}, captureSupported ? { | }, captureSupported ? { | ||
| 第208行: | 第216行: | ||
} | } | ||
}); | }); | ||
} | |||
//防滥用即将删除 | |||
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() { | |||
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.info/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); | |||
} | } | ||
/* 函数执行体 */ | /* 函数执行体 */ | ||
| 第221行: | 第295行: | ||
//Extension:MultimediaViewer的半透明化修改 | //Extension:MultimediaViewer的半透明化修改 | ||
if ($("img[srcset][data-file-width][data-file-height]")[0]) { multimediaViewer(); } | if ($("img[srcset][data-file-width][data-file-height]")[0]) { multimediaViewer(); } | ||
//重复文件列表区分图片和音频 | //重复文件列表区分图片和音频 | ||
if ($(".mw-special-ListDuplicatedFiles").length && $(".mw-spcontent > p").length > 1) { duplicatedFileList(); } | if ($(".mw-special-ListDuplicatedFiles").length && $(".mw-spcontent > p").length > 1) { duplicatedFileList(); } | ||
| 第246行: | 第318行: | ||
if (this.parentElement.childNodes[0] === this) { $(this).addClass("listInRef"); } | if (this.parentElement.childNodes[0] === this) { $(this).addClass("listInRef"); } | ||
}); | }); | ||
//列表侧边距 | //列表侧边距 | ||
setInterval(function() { | setInterval(function() { | ||
| 第270行: | 第340行: | ||
}); | }); | ||
} | } | ||
}); | }); | ||
})(jQuery, mediaWiki); //立即执行匿名函数并传递原始变量以防止冲突 | })(jQuery, mediaWiki); //立即执行匿名函数并传递原始变量以防止冲突 | ||
// </nowiki> | // </nowiki> | ||