您似乎还未注册一个账号?我们强烈推荐您点击此处创建一个账户。|如果您在H萌娘上发现某些内容错误/空缺/不中立,请勇于按右上角编辑按钮!
MediaWiki:Mobile.js:修订间差异
跳转到导航
跳转到搜索
imported>=海豚= 无编辑摘要 |
imported>=海豚= 无编辑摘要 |
||
| 第171行: | 第171行: | ||
}).appendTo(commonBoxContainer).hide(); | }).appendTo(commonBoxContainer).hide(); | ||
} | } | ||
//链接提示 | |||
function linkConfirm() { | |||
mw.loader.using('mediawiki.Uri').then(function () { | |||
if ($('body').css('position') === 'static') $('body').css('position', 'relative'); | |||
var prompt = $('<div/>').attr('class', 'linkConfirmprompt'); | |||
prompt.css('max-width', $('#mw-content-text').width() - 4); | |||
var textnode = $('<div/>').attr('class', 'linkConfirmpromptTextnode'); | |||
var text = $('<span/>'); | |||
textnode.append(text); | |||
var check = window.CSS && CSS.supports && CSS.supports('-webkit-line-clamp', '2') ? (function () { | |||
text.css({ | |||
display: '-webkit-box', | |||
'-webkit-line-clamp': '2', | |||
'-webkit-box-orient': 'vertical', | |||
'word-break': 'break-all', | |||
'text-overflow': 'ellipsis', | |||
overflow: 'hidden', | |||
}); | |||
return $.noop; | |||
})() : function (text) { | |||
if (text.height() > 44.8) { | |||
text.text(text.text() + '……'); | |||
while (text.height() > 44.8) { | |||
text.text(text.text().slice(0, -3) + '……'); | |||
} | |||
} | |||
}; | |||
prompt.append('您点击了一个链接,地址为:') | |||
.append(textnode) | |||
.append($('<div/>').attr('class', 'linkConfirmpromptAlert').append('此网页不属于本网站,不保证其安全性').hide()); | |||
prompt.append($('<a/>').text('继续访问').on('click', function () { | |||
window.open(prompt.data('href'), '_blank'); | |||
})) | |||
.append($('<a/>').text('取消')) | |||
.on('click', function (e) { | |||
if (!$(e.target).is('a')) return false; | |||
prompt.fadeOut(137); | |||
}); | |||
prompt.appendTo('body'); | |||
$('#mw-content-text').on('click', function (e) { | |||
var self = $(e.target); | |||
if (!self.is("a")) return; | |||
if (!e.target.href || /^javascript:/.test(e.target.href) || $(e.target).is('.image')) return true; | |||
if (!e.target.dataset.linkid) e.target.dataset.linkid = (Math.random() + '').replace(/\D/g, ''); | |||
if (prompt.is(':visible') && prompt.data('linkid') === e.target.dataset.linkid) return false; | |||
$('.linkConfirmprompt a:last').click(); | |||
var uri = new mw.Uri(e.target.href); | |||
if (/\.moegirl\.org$/.test(uri.host)) { | |||
if (!self.closest('.heimu')[0]) return true; | |||
text.text(decodeURI(self.attr('href'))); | |||
$('.linkConfirmpromptAlert').hide(); | |||
} else { | |||
text.text(uri); | |||
$('.linkConfirmpromptAlert').show(); | |||
} | |||
var promptTop = 0, | |||
promptLeft = 0; | |||
var offsetParent = self; | |||
do { | |||
promptTop += offsetParent.offset().top; | |||
promptLeft += offsetParent.offset().left; | |||
offsetParent = offsetParent.offsetParent(); | |||
} while (!offsetParent.is("html, body")); | |||
promptTop += self.outerHeight() + 3; | |||
promptLeft += self.outerWidth() / 2 - prompt.outerWidth() / 2; | |||
if (promptTop + prompt.outerHeight() > $(document).height() - 3) promptTop = $(document).height() - prompt.outerHeight() - 3; | |||
if (promptLeft + prompt.outerWidth() > $(window).width() - 3) promptLeft = $(window).width() - prompt.outerWidth() - 3; | |||
if (promptLeft < 0) promptLeft = 3; | |||
prompt.css({ | |||
top: promptTop + 'px', | |||
left: promptLeft + 'px', | |||
}); | |||
window.setTimeout(check, 0, text); | |||
prompt.data({ | |||
href: uri, | |||
linkid: self[0].dataset.linkid, | |||
}); | |||
prompt.fadeIn(137); | |||
return false; | |||
}); | |||
}); | |||
} | |||
function antiAbuseListener(textarea, event) { | |||
var filters = [ | |||
"{{即将删除", | |||
"{{即將刪除", | |||
"{{挂删", | |||
"{{模板:即将删除", | |||
"{{模板:即將刪除", | |||
"{{template:即将删除", | |||
"{{template:即將刪除", | |||
"[[分类:即将删除的页面", | |||
"[[分類:即將刪除的頁面", | |||
"[[category:即将删除的页面", | |||
"[[category:即將刪除的頁面", | |||
"{{文件转移到萌娘共享", | |||
"{{文件轉移到萌娘共享", | |||
"{{模板:文件转移到萌娘共享", | |||
"{{模板:文件轉移到萌娘共享", | |||
"{{template:文件转移到萌娘共享", | |||
"{{template:文件轉移到萌娘共享", | |||
"[[分类:需要删除执行员删除的页面", | |||
"[[分類:需要刪除執行員刪除的頁面", | |||
"[[category:需要删除执行员删除的页面", | |||
"[[category:需要刪除執行員刪除的頁面", | |||
]; | |||
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萌娘提醒您<br>您的编辑包含禁止内容!"); | |||
messageDialog.message.$label.html("<br>您提交的内容包含以下部分,被禁止提交:<br><br><ul>" + results.map(function (result) { | |||
return "<li>" + result + "</li>"; | |||
}).join("") + '</ul><br><br>如果您认为您的编辑无误,请在自行保存编辑内容后到<a target="_blank" rel="nofollow noreferrer noopener" class="external text" href="https://www.hmoegirl.com/Talk:讨论版">提问求助区</a>提问。'); | |||
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 () { | |||
var captureSupported = false; | |||
try { | |||
var options = Object.defineProperty({}, "capture", { | |||
get: function () { | |||
captureSupported = true; | |||
}, | |||
}); | |||
window.addEventListener("test", null, options); | |||
} catch (err) { /* */ } | |||
if (submitButton) { | |||
submitButton.addEventListener("click", function (e) { | |||
antiAbuseListener(textarea, e); | |||
}, captureSupported ? { | |||
capture: true, | |||
} : undefined); | |||
} | |||
if (form) { | |||
form.addEventListener("submit", function (e) { | |||
antiAbuseListener(textarea, e); | |||
}, captureSupported ? { | |||
capture: true, | |||
} : undefined); | |||
} | |||
}); | |||
} | |||
/* 函数执行体 */ | |||
$(function () { | |||
//tabs | |||
tabs(); | |||
//页顶提示模板相关 | //页顶提示模板相关 | ||
commonBoxs(); | commonBoxs(); | ||
//用户资料页 | //用户资料页 | ||
if (isUserProfile()) { | if (isUserProfile()) { | ||
2020年3月18日 (三) 10:45的版本
// <pre>
/* 这里的任何JavaScript将只在移动端加载
* 请尊重萌娘百科版权,以下代码复制需要注明原自萌娘百科,并且附上URL地址http://zh.moegirl.org/MediaWiki:Common.js
* 版权协定:知识共享 署名-非商业性使用-相同方式共享 3.0
*/
(function ($, mw) { //使用匿名函数以避免污染顶级变量
/* 函数定义体 */
//Tabs
function tabs() {
var defaultStyle = {
purple: {
labelColor: " ", //anti check
labelBackgroundColor: "#9070c0",
labelBorderColor: "#b090e0 #7050a0 #9070c0 #b090e0",
labelPadding: ".2em .3em .2em .3em",
textBorderColor: "#9070c0",
textBackgroundColor: "#f0edf5",
textPadding: "1em",
},
green: {
labelColor: " ",
labelBackgroundColor: "#75c045",
labelBorderColor: "#90d060 #60b030 #75c045 #90d060",
labelPadding: ".2em .3em .2em .3em",
textBorderColor: "#75c045 #60b030 #60b030 #75c045",
textBackgroundColor: "#f5fffa",
textPadding: "1em",
},
red: {
labelColor: " ",
labelBackgroundColor: "#FF0000",
labelBorderColor: "#FF8888 #CC0000 #FF0000 #FF8888",
labelPadding: ".2em .3em .2em .3em",
textBorderColor: "#FF0000 #CC0000 #CC0000 #FF0000",
textBackgroundColor: "#fffafa",
textPadding: "1em",
},
blue: {
labelColor: " ",
labelBackgroundColor: "#5b8dd6",
labelBorderColor: "#88abde #3379de #5b8dd6 #88abde",
labelPadding: ".2em .3em .2em .3em",
textBackgroundColor: "#f0f8ff",
textBorderColor: "#5b8dd6 #3379de #3379de #5b8dd6",
textPadding: "1em",
},
yellow: {
labelColor: " ",
labelBackgroundColor: "#ffe147",
labelBorderColor: "#ffe977 #ffd813 #ffe147 #ffe977",
labelPadding: ".2em .3em .2em .3em",
textBackgroundColor: "#fffce8",
textBorderColor: "#ffe147 #ffd813 #ffd813 #ffe147",
textPadding: "1em",
},
orange: {
labelColor: " ",
labelBackgroundColor: "#ff9d42",
labelBorderColor: "#ffac5d #ff820e #ff9d42 #ffac5d",
labelPadding: ".2em .3em .2em .3em",
textBackgroundColor: "#ffeedd",
textBorderColor: "#ff9d42 #ff820e #ff820e #ff9d42",
textPadding: "1em",
},
black: {
labelColor: " ",
labelBackgroundColor: "#7f7f7f",
labelBorderColor: "#999999 #4c4c4c #7f7f7f #999999",
labelPadding: ".2em .3em .2em .3em",
textBackgroundColor: "#e5e5e5",
textBorderColor: "#7f7f7f #4c4c4c #4c4c4c #7f7f7f",
textPadding: "1em",
},
};
$("body").addClass("tab");
// A Class
function StyleSheet() {}
StyleSheet.prototype.getOwnPropertyNamesLength = function getOwnPropertyNamesLength() {
return Object.getOwnPropertyNames(this).length;
};
String.prototype.toLowerFirstCase = function toLowerFirstCase() {
return this[0].toLowerCase() + this.substring(1);
};
$(".Tabs").each(function() {
if ($(this).children(".TabLabel")[0]) { return true; }
var self = $(this),
classList = Array.from(this.classList).filter(function(n) { return n in defaultStyle; }),
data = $.extend({
labelPadding: null,
labelBorderColor: null,
labelColor: null,
labelBackgroundColor: $("#content").css("background-color"),
textPadding: null,
textBorderColor: null,
textBackgroundColor: null,
defaultTab: 1,
}, classList[0] ? defaultStyle[classList[0]] || {} : {}, this.dataset || {}),
tabLabel = self.append('<div class="TabLabel"></div>').children(".TabLabel"),
tabContent = self.append('<div class="TabContent"></div>').children(".TabContent"),
labelPadding = data.labelPadding,
labelColor = data.labelColor,
styleSheet = {
label: new StyleSheet(),
text: new StyleSheet(),
},
defaultTab = parseInt(data.defaultTab);
self.children(".Tab").each(function() {
if ($(this).children(".TabLabelText").text().replace(/\s/g, "").length || $(this).children(".TabLabelText").children().length) {
$(this).children(".TabLabelText").appendTo(tabLabel);
$(this).children(".TabContentText").appendTo(self.children(".TabContent"));
}
$(this).remove();
});
if (isNaN(defaultTab) || defaultTab <= 0 || defaultTab > tabLabel.children(".TabLabelText").length) { defaultTab = 1; }
tabLabel.children(".TabLabelText").on("click", function() {
var label = $(this);
label.addClass("selected").siblings().removeClass("selected").css({
"border-color": "transparent",
"background-color": "inherit",
});
tabContent.children(".TabContentText").eq(tabLabel.children(".TabLabelText").index(label)).addClass("selected").siblings().removeClass("selected").removeAttr("style");
if (styleSheet.label.getOwnPropertyNamesLength()) { label.css(styleSheet.label); }
}).eq(defaultTab - 1).click();
if (labelPadding) { tabLabel.children(".TabLabelText").css("padding", labelPadding); }
["labelBorderColor", "labelBackgroundColor", "textPadding", "textBorderColor", "textBackgroundColor"].forEach(function(n) {
var target = /^label/.test(n) ? "label" : "text",
key = n.replace(target, "").toLowerFirstCase();
styleSheet[target][key] = data[n];
});
if (labelColor) {
styleSheet.label.borderTopColor = labelColor;
} else if (styleSheet.label.borderColor) {
styleSheet.label.borderTopColor = "green";
}
tabLabel.find(".selected").click();
if (styleSheet.text.getOwnPropertyNamesLength()) { tabContent.css(styleSheet.text); }
if (data.autoWidth === "yes") { self.css("display", "inline-block"); }
});
}
//用户资料页相关
function isUserProfile() {
return mw.config.get('wgCanonicalSpecialPageName') === "UserProfile" && mw.config.get('wgArticleId') === "0";
}
//页顶提示模板相关
function commonBoxs() {
if (window.mw && !!mw.config.get('wgNamespaceNumber')) return;
var contentParent = $('#mw-content-text')[0] ? $('#mw-content-text') : $('#content'),
commonBoxes = contentParent.find('.common-box');
if (!commonBoxes[0]) return;
var commonBoxContainer = $('<div id="commonBoxContainer"><div id="commonBoxInfo"></div></div>').prependTo(contentParent),
commonBoxList = $('<div id="commonBoxList"></div>').appendTo('#commonBoxInfo');
commonBoxes.each(function () {
var commonBoxButton = $('<div class="commonBoxButton"></div>').appendTo(commonBoxList),
commonBox = $(this);
commonBoxButton.data('element', commonBox).css({
'border-color': commonBox.css('border-left-color'),
'background-image': 'url(' + commonBox.find('tbody > tr > td:first-child img').prop('src') + ')',
}).on('click', function () {
if (commonBox.is(':visible')[0]) {
commonBoxes.hide();
$(this).add($(this).siblings()).removeClass('current');
commonBoxList.removeClass('open');
} else {
commonBoxes.filter(':visible').not(commonBox).hide();
commonBox.show();
$(this).toggleClass('current', commonBox.is(':visible')).siblings().removeClass('current');
commonBoxList.toggleClass('open', commonBox.is(':visible'));
}
});
}).appendTo(commonBoxContainer).hide();
}
//链接提示
function linkConfirm() {
mw.loader.using('mediawiki.Uri').then(function () {
if ($('body').css('position') === 'static') $('body').css('position', 'relative');
var prompt = $('<div/>').attr('class', 'linkConfirmprompt');
prompt.css('max-width', $('#mw-content-text').width() - 4);
var textnode = $('<div/>').attr('class', 'linkConfirmpromptTextnode');
var text = $('<span/>');
textnode.append(text);
var check = window.CSS && CSS.supports && CSS.supports('-webkit-line-clamp', '2') ? (function () {
text.css({
display: '-webkit-box',
'-webkit-line-clamp': '2',
'-webkit-box-orient': 'vertical',
'word-break': 'break-all',
'text-overflow': 'ellipsis',
overflow: 'hidden',
});
return $.noop;
})() : function (text) {
if (text.height() > 44.8) {
text.text(text.text() + '……');
while (text.height() > 44.8) {
text.text(text.text().slice(0, -3) + '……');
}
}
};
prompt.append('您点击了一个链接,地址为:')
.append(textnode)
.append($('<div/>').attr('class', 'linkConfirmpromptAlert').append('此网页不属于本网站,不保证其安全性').hide());
prompt.append($('<a/>').text('继续访问').on('click', function () {
window.open(prompt.data('href'), '_blank');
}))
.append($('<a/>').text('取消'))
.on('click', function (e) {
if (!$(e.target).is('a')) return false;
prompt.fadeOut(137);
});
prompt.appendTo('body');
$('#mw-content-text').on('click', function (e) {
var self = $(e.target);
if (!self.is("a")) return;
if (!e.target.href || /^javascript:/.test(e.target.href) || $(e.target).is('.image')) return true;
if (!e.target.dataset.linkid) e.target.dataset.linkid = (Math.random() + '').replace(/\D/g, '');
if (prompt.is(':visible') && prompt.data('linkid') === e.target.dataset.linkid) return false;
$('.linkConfirmprompt a:last').click();
var uri = new mw.Uri(e.target.href);
if (/\.moegirl\.org$/.test(uri.host)) {
if (!self.closest('.heimu')[0]) return true;
text.text(decodeURI(self.attr('href')));
$('.linkConfirmpromptAlert').hide();
} else {
text.text(uri);
$('.linkConfirmpromptAlert').show();
}
var promptTop = 0,
promptLeft = 0;
var offsetParent = self;
do {
promptTop += offsetParent.offset().top;
promptLeft += offsetParent.offset().left;
offsetParent = offsetParent.offsetParent();
} while (!offsetParent.is("html, body"));
promptTop += self.outerHeight() + 3;
promptLeft += self.outerWidth() / 2 - prompt.outerWidth() / 2;
if (promptTop + prompt.outerHeight() > $(document).height() - 3) promptTop = $(document).height() - prompt.outerHeight() - 3;
if (promptLeft + prompt.outerWidth() > $(window).width() - 3) promptLeft = $(window).width() - prompt.outerWidth() - 3;
if (promptLeft < 0) promptLeft = 3;
prompt.css({
top: promptTop + 'px',
left: promptLeft + 'px',
});
window.setTimeout(check, 0, text);
prompt.data({
href: uri,
linkid: self[0].dataset.linkid,
});
prompt.fadeIn(137);
return false;
});
});
}
function antiAbuseListener(textarea, event) {
var filters = [
"{{即将删除",
"{{即將刪除",
"{{挂删",
"{{模板:即将删除",
"{{模板:即將刪除",
"{{template:即将删除",
"{{template:即將刪除",
"[[分类:即将删除的页面",
"[[分類:即將刪除的頁面",
"[[category:即将删除的页面",
"[[category:即將刪除的頁面",
"{{文件转移到萌娘共享",
"{{文件轉移到萌娘共享",
"{{模板:文件转移到萌娘共享",
"{{模板:文件轉移到萌娘共享",
"{{template:文件转移到萌娘共享",
"{{template:文件轉移到萌娘共享",
"[[分类:需要删除执行员删除的页面",
"[[分類:需要刪除執行員刪除的頁面",
"[[category:需要删除执行员删除的页面",
"[[category:需要刪除執行員刪除的頁面",
];
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萌娘提醒您<br>您的编辑包含禁止内容!");
messageDialog.message.$label.html("<br>您提交的内容包含以下部分,被禁止提交:<br><br><ul>" + results.map(function (result) {
return "<li>" + result + "</li>";
}).join("") + '</ul><br><br>如果您认为您的编辑无误,请在自行保存编辑内容后到<a target="_blank" rel="nofollow noreferrer noopener" class="external text" href="https://www.hmoegirl.com/Talk:讨论版">提问求助区</a>提问。');
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 () {
var captureSupported = false;
try {
var options = Object.defineProperty({}, "capture", {
get: function () {
captureSupported = true;
},
});
window.addEventListener("test", null, options);
} catch (err) { /* */ }
if (submitButton) {
submitButton.addEventListener("click", function (e) {
antiAbuseListener(textarea, e);
}, captureSupported ? {
capture: true,
} : undefined);
}
if (form) {
form.addEventListener("submit", function (e) {
antiAbuseListener(textarea, e);
}, captureSupported ? {
capture: true,
} : undefined);
}
});
}
/* 函数执行体 */
$(function () {
//tabs
tabs();
//页顶提示模板相关
commonBoxs();
//用户资料页
if (isUserProfile()) {
var cardContainer = $('.card-container'),
containerImage = cardContainer.find('.card'),
containerImageFile = containerImage.find('a.image'),
containerImageCaption = containerImage.find('.caption');
containerImageCaption.css("padding", "0 8px");
containerImageFile.before('<div id="#containerImage" class="listThumb list-thumb-placeholder" style="text-align: center;"><img src="http://static.mengniang.org/common/a/a4/Placeholder-upload.png" style="height:32px" /></div>');
}
//黑幕
$('.heimu a').on("click", function () {
if (!$(this).closest('.heimu').is(':active, :focus')) return false;
});
//Template:hide
if ($('.mw-collapsible')[0]) mw.loader.using('jquery.makeCollapsible').then(function () {
//console.debug('jquery.makeCollapsible is loaded.');
$('.mw-collapsible').makeCollapsible();
});
//链接提示
linkConfirm();
//防滥用即将删除
if (!mw.config.get('wgUserGroups').includes('sysop') && !mw.config.get('wgUserGroups').includes('patroller')) {
setInterval(function () {
if ($('#wikitext-editor')[0]) {
var target = $('#wikitext-editor');
if (target.data('isTrusted') !== true) {
target.data('isTrusted', true);
$('.editor-overlay').css('z-index', 3);
antiAbuse(target[0], $('.editor-overlay .header .header-action button.continue')[0], undefined);
}
}
}, 1000);
}
});
})(jQuery, mediaWiki); //立即执行匿名函数并传递原始变量
// </pre>