2023年政策修订增补工作正在进行中,欢迎参与!
  • Moegirl.ICU:萌娘百科流亡社群 581077156(QQ),欢迎对萌娘百科运营感到失望的编辑者加入
  • Moegirl.ICU:账号认领正在试运行,有意者请参照账号认领流程

User:D41D8CD98F/minerva.js

萌娘百科,万物皆可萌的百科全书!转载请标注来源页面的网页链接,并声明引自萌娘百科。内容不可商用。
跳转到导航 跳转到搜索

注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox/Safari:按住“Shift”的同时单击“刷新”,或按“Ctrl-F5”或“Ctrl-R”(Mac为“⌘-R”)
  • Google Chrome:按“Ctrl-Shift-R”(Mac为“⌘-Shift-R”)
  • Internet Explorer:按住“Ctrl”的同时单击“刷新”,或按“Ctrl-F5”
  • Opera:在“工具→首选项”中清除缓存
如果您已登录但该页面出现未登录状态,请尝试在地址栏的地址最后添加代码?_=1来访问最新页面。
添加代码后的本页地址如下:-{R|https://moegirl.icu/User:D41D8CD98F/minerva.js?_=1}-
(function() {
// 来自百度的访问默认跳转zh版
// 不需要在所有东西加载完毕后再执行,因此不放在 $(function(){...}) 里面
if(document.referrer.includes('//www.bai' + 'du.com/'))
	location = 'https://zh.moegirl.org.cn' + location.pathname + location.search;

mw.loader.using('mobile.site').then(function() {$(function() {mw.loader.using('mediawiki.Uri').then(function() {$('body').off('click')})})});

function withElem(s) {
	return new Promise(function(r) {
		if ($(s).length) r($(s));
		new MutationObserver(function(rec,self) {
			$.each(rec, function(i,v) {
				var t = $(v.addedNodes).filter(s);
				if (t.length) self.disconnect(), r(t)
			})
        	}).observe(document.body, {childList: true, subtree: true})
	})
}
if ((mw.config.get('wgCanonicalSpecialPageName') === 'MobileEditor' || location.hash === '#/editor/0') && location.search.includes('&redlink=1'))
	location = '/' + mw.config.get('wgPageName').replace('Special:移动版编辑器/', '');

// 避免使用 MobileFrontend 的编辑器
if (mw.config.get('wgAction') === 'view') $.when($.ready, mw.loader.using('skins.minerva.editor')).always(function() {
	var editlink = '/index.php?action=edit&title='+encodeURIComponent(mw.config.get('wgPageName'))+'&oldid='+mw.config.get('wgRevisionId');
	$('a.edit-page').each(function() { $(this).off('click').prop('href', editlink + '&section=' + $(this).data('section')) });
	$('#ca-edit').off('click').empty().append($('<a>').prop('href', editlink));
});

if (mw.config.get('wgAction') === 'edit') {
	withElem('#wpMinoredit').then(function(e) { e.prop('checked', true) });
	return;
}

$(document).on('click.D4.customized.heimu', '.heimu', function() {
	$(this).removeClass('heimu').addClass('heimu-off');
	return false;
});

// “页顶提示模板相关”,利用了[[MediaWiki:Mobile.css]]中的样式
$(function($) {
	var infoBoxes = [],
	    cont = $('<div id="commonBoxContainer"><div id="commonBoxInfo"><div id="commonBoxList"></div></div></div>'),
	    list = cont.find('#commonBoxList');
	$('.mf-section-0').children().each(function() {
		var self = $(this);
		if (!self.is('.infoBox')) return;
		infoBoxes.push(this);
		var btn = $('<div class="commonBoxButton">').appendTo(list);
		btn.append(self.find('.infoBoxIcon')).find('img').css({
			'width': 'auto',
			'max-height': '45px',
		});
		btn.css({
			'width': 'auto',
			'height': '50px',
			'vertical-align': 'bottom',
			'border-color': self.css('border-left-color'),
		}).on('click touchend', function() {
			$(infoBoxes).not(self).hide();
			self.toggle();
			btn.toggleClass('current', self.css('display') !== 'none');
			btn.siblings().removeClass('current');
			list.toggleClass('open', btn.hasClass('current'));
			return false;
		});
	});
	cont.prependTo($('.mf-section-0'));
	$(infoBoxes).appendTo(cont).hide();
});

if (mw.config.get('wgCanonicalSpecialPageName') === 'MobileDiff') {
// 在[[special:移动版差异/xxx]]页面加一个指向[[special:固定链接/xxx]]的链接
// 以及增加切换至桌面版差异显示方式的功能
withElem('.revision-history-links').then(function(a) {
	var pageName = mw.config.get('wgPageName');
	var revs = /\/(\d+)(?:\.\.\.(\d+))?/.exec(mw.config.get('wgTitle'));
	var link = $('<a>固定链接</a>').attr('href', '/' + pageName.replace('移动版差异', '固定链接'));
	var desktopdiff = $('<a id="D4-show-desktop-diff" href>桌面版差异</a>');
	$(document).on('click.D4.customized.showdesktopdiff', '#D4-show-desktop-diff', function(e) {
		if (!$('table.diff')[0]) $.get('/api.php', $.extend(
			{ format: 'json', formatversion: 2, action: 'compare', fromrev: revs[1] },
			revs[2] ? { torev: revs[2] } : { torelative: 'prev' }
		)).then(function(data) {
			$('#mw-mf-minidiff').css('display', 'none').before($('<table class="diff">').append($(data.compare.body)));
			mw.hook('wikipage.diff').fire($('table.diff'))
		});
		return false
	});
	a.prepend(a.children('.revision-history-prev'), $('<li>').append(link), $('<li>').append(desktopdiff))
});

// 处理中文wiki在生成差异时错误增加的空格(桌面版差异也有此问题,对此的处理在[[User:D41D8CD98F/common.js]])
// 另外移动版差异还有段落间隔莫名消失问题,这里也顺便补救
withElem('#mw-mf-minidiff').then(function(t) {
	t.children('.mw-diff-inline-changed').contents().each(function() {
		if (this.nextSibling) {
			if (this.nextSibling.textContent.match(/^[^\x00-\x7f]/))
				this.textContent = this.textContent.replace(/ $/, '');
			if (this.tagName === this.nextSibling.tagName)
				$(this).after('<br>')
		}
	});
});
}

// [[Template:专题导航]]简化为图标,点击图标时展开
withElem('.ztdh:has(img)').then(function(t) {
	var img = t.find('img').first();
	var next = t.nextUntil(':not(style,p:not(:has(:not(style,script))))').next('div');
	if (next.css('border-top-width') === '1px' && next.css('border-top-style') === 'solid')
		t = t.add(next);
	{mw.loader.addStyleTag('\
.D4-ztdh-img {\
	visibility: visible;\
	position: fixed;\
	top: 8px;\
	right: 8px;\
	z-index: 3;\
	box-shadow: 0 3px 15px silver;\
	width: auto;\
	max-height: 100px;\
	border-radius: 5px;\
	background: #FFFC;\
}\
	')}
	img.addClass('D4-ztdh-img').one('click', function() {
		img.removeClass('D4-ztdh-img');
        	t.css({ position: '', visibility: '' })[0].scrollIntoView();
		return false;
	});
	t.css({ position: 'absolute', visibility: 'hidden' });
});

if (mw.config.get('wgPageName') === 'Talk:提问求助区') {
	$('h2.section-heading')
		.next('div:has(.saveNotice:only-child, .MarkAsResolved:last-child)')
		.prev()
		.css({ textDecoration: 'line-through', color: 'grey', fontStyle: 'italic' })
}
})()