无编辑摘要
imported>=海豚= 无编辑摘要 |
imported>=海豚= 无编辑摘要 |
||
第2行: | 第2行: | ||
/* 这里的任何JavaScript将只在移动端加载 */ | /* 这里的任何JavaScript将只在移动端加载 */ | ||
(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) { /* */ } | |||
/* 函数定义体 */ | /* 函数定义体 */ | ||
//用户资料页相关 | //用户资料页相关 | ||
第63行: | 第74行: | ||
}; | }; | ||
$(function(){mfSidebar();}); | $(function(){mfSidebar();}); | ||
//链接提示 | |||
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', "noopener,noreferrer"); | |||
window.open("javascript:window.name;", '<script>location.replace("' + prompt.data("href") + '");/* ' + Math.random() + " */</script>"); | |||
})).append($("<a/>").text("取消")).on("click", function (e) { | |||
if (!$(e.target).is("a")) { return false; } | |||
prompt.fadeOut(137); | |||
}); | |||
prompt.appendTo("body"); | |||
$("body").on("click", function (e) { | |||
var self = $(e.target); | |||
if (!self.is("#mw-content-text a, .comment-text 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 = uuidv4(); } | |||
if (prompt.is(":visible") && prompt.data("linkid") === e.target.dataset.linkid) { return false; } | |||
prompt.fadeOut(137); | |||
var uri = new mw.Uri(e.target.href); | |||
if (/\.hmoegirl\.com?$/.test(uri.host)) { | |||
if (!self.closest(".heimu")[0] && !self.find(".heimu")[0] || self.parent().is(".reference")) { return true; } | |||
text.text(decodeURI(e.target.href)); | |||
$(".linkConfirmpromptAlert").hide(); | |||
} else { | |||
text.text(decodeURI(e.target.href)); | |||
$(".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: e.target.href, | |||
linkid: self[0].dataset.linkid, | |||
}); | |||
prompt.fadeIn(137); | |||
return false; | |||
}); | |||
}); | |||
} | |||
/* 函数执行体 */ | /* 函数执行体 */ | ||
$(function() { | $(function() { |