MediaWiki:Mobile.js
注意:这类代码页面在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- 按住
CTRL+SHIFT+DEL 或 ⌘-Shift-R来清除缓存! - 或尝试在地址栏的地址最后添加代码
?_=1来访问最新页面。- 添加代码后的本页地址如下:
-{R|https://hmoegirl.com/MediaWiki:Mobile.js?_=1}-
- 添加代码后的本页地址如下:
- 你还可以在设置中勾选小工具在页面右上角添加清除缓存按钮!
| 1. | 桌面版CSS | MediaWiki:Common.css |
| 2. | 桌面版JS | MediaWiki:Common.js |
| 3. | 移动端CSS | MediaWiki:Mobile.css |
| 4. | 移动端JS | MediaWiki:Mobile.js |
| 5. | 全局共用CSS | MediaWiki:Gadget-site-styles.css |
| 6. | 全局共用JS | MediaWiki:Gadget-site-javascript.js |
| 7. | 管理员CSS | MediaWiki:Group-sysop.css |
| 8. | 管理员JS | MediaWiki:Group-sysop.js |
| 9. | 编辑时载入 | MediaWiki:Common.js/edit.js |
引用api时用
mw.loader.using("mw.Api"),引用uri时用mw.loader.using("mediawiki.Uri")。// <pre>
/* 这里的任何JavaScript将只在移动端加载 */
(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) { /* */ }
/* 函数定义体 */
//用户资料页相关
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();
}
//uuid
function uuidv4() {
var result;
do {
result = ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, function(c) {
return (c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16);
});
} while (document.querySelector('a[data-linkid="' + result + '"]'));
return result;
}
// Mobile Navmenu by GFwiki
function menuadjust(){var a = $("body").height()+"px";document.getElementById("mw-mf-page-left").style.height = a;};
$(function(){menuadjust();});
$(window).resize(function(){menuadjust()});
var navbar = function(data, textStatus, jqxhr) {
var navlist = data.parse.text["*"];
$(navlist).insertBefore(".menu > .hlist")
};
var mfSidebar = function() {
var purl = "/api.php?action=parse&page=MediaWiki:MFSidebar&format=json";
$.ajax({
url: purl,
success: navbar,
error: function () {console.error("can\'t load customized navmenu")},
dataType: "json"
});
};
$(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() {
//页顶提示模板相关
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="https://img.moegirl.org.cn/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();
});
// 桌面版页面外链改为移动端域名
document.body.addEventListener("click", function(e) {
e.path.forEach(function(ele) {
if (ele instanceof HTMLAnchorElement) {
var url = new mw.Uri(ele.href);
if (/www\.hmoegirl\.com?$/.test(url.host) && url.query.mobileaction !== "toggle_view_desktop") {
url.host = mw.config.get("wgServer").replace(/^(?:(?:https?:)?\/\/)?www/, "m");
ele.href = url;
}
}
});
}, captureSupported ? {
capture: true,
} : true);
});
})(jQuery, mediaWiki); //立即执行匿名函数并传递原始变量
// </pre>