◆少前百科是非盈利性、非官方的少女前线维基百科。 ◆如果您发现某些内容错误/空缺,请勇于修正/添加!参与进来其实很容易!点这里 加入少前百科。 ◆有任何意见、建议、纠错,欢迎在 GFwiki:反馈与建议 提出和讨论。编辑事务讨论QQ群:597764980,微博@GFwiki少前百科 ◆To foreigners,You can use twitter to contact us. |
![]() |
MediaWiki:Common.js
Mikumikuer(讨论 | 贡献)2019年2月10日 (日) 19:58的版本
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
/* 这里的任何JavaScript将为所有用户在每次页面载入时加载。 */
/* 功能hack */
RLQ.push(function(){ //template:Purge 无确认清除缓存 (仅注册用户)
var purge = document.querySelector("li#ca-purge > a")
var purge_link = document.getElementsByClassName("purgelink")
if (!purge){return}
for (var i = 0; i < purge_link.length; i++) {
purge_link[i].firstElementChild.onclick=function(){purge.click()};
purge_link[i].firstElementChild.href="javascript:void(0)";
}
})
/* Spine Loader */
mw.loader.load("/index.php?title=MediaWiki:Gadget-chibiAnimation.js&action=raw&ctype=text/javascript");
/* 黑幕 */
var heimu = document.getElementsByClassName("black-black");
function overMouse(){this.style.color="white"}
function leftMouse(){this.style.color="black"}
for(var i=0;i<heimu.length;i++){
heimu[i].addEventListener("mouseover", overMouse);
heimu[i].addEventListener("mouseleave", leftMouse);}
/* 返回顶部按钮 */
$(function() {
var txt = " ",
btn = $('<div/>', {
'text': txt,
'attr': {
'title': txt,
'class': 'backToTop'
},
'css': {
'user-select': 'none'
},
'on': {
'click': function() {
$("html, body").animate({
scrollTop: 0
}, 120);
}
}
}).appendTo(document.body);
$(window).on('scroll', function() {
$(document).scrollTop() > 0 ? btn.fadeIn() : btn.fadeOut();
}).scroll();
});
/* goTop END */
/**
* Dynamic Navigation Bars (experimental)
*
* Description: See [[Wikipedia:NavFrame]].
* Maintainers: UNMAINTAINED
*/
/* set up the words in your language */
var collapseCaption = '隐藏';
var expandCaption = '显示';
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
var indexNavigationBar = 0;
/**
* Shows and hides content and picture (if available) of navigation bars
* Parameters:
* indexNavigationBar: the index of navigation bar to be toggled
**/
window.toggleNavigationBar = function ( indexNavigationBar, event ) {
var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
var NavChild;
if ( !NavFrame || !NavToggle ) {
return false;
}
/* if shown now */
if ( NavToggle.firstChild.data === NavigationBarHide ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
/* if hidden now */
} else if ( NavToggle.firstChild.data === NavigationBarShow ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
event.preventDefault();
};
//collapse 折叠和图标折叠
$(function(){
$(".simpleCollapse").click(function(e){
var dest=$(this).next(),
spen=$(this).children('span'),
i=$(this).children("i");
if(dest.is(":visible")){
dest.slideUp('fast',function(){
spen.html(spen.attr('data-ht'));
i.removeClass("fa-minus-square").addClass("fa-plus-square").html(" 详细");
});
}else {
dest.slideDown('fast',function(){
spen.html(spen.attr('data-st'));
i.removeClass("fa-plus-square").addClass("fa-minus-square").html("");
});
}
});
});
/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton( $content ) {
var NavChild;
/* iterate over all < div >-elements */
var $divs = $content.find( 'div' );
$divs.each( function ( i, NavFrame ) {
/* if found a navigation bar */
if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
indexNavigationBar++;
var NavToggle = document.createElement( 'a' );
NavToggle.className = 'NavToggle';
NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
NavToggle.setAttribute( 'href', '#' );
$( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
/**
* Check if any children are already hidden. This loop is here for backwards compatibility:
* the old way of making NavFrames start out collapsed was to manually add style="display:none"
* to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make
* the content visible without JavaScript support), the new recommended way is to add the class
* "collapsed" to the NavFrame itself, just like with collapsible tables.
*/
for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
if ( NavChild.style.display === 'none' ) {
isCollapsed = true;
}
}
}
if ( isCollapsed ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
NavChild.style.display = 'none';
}
}
}
var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
NavToggle.appendChild( NavToggleText );
/* Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) */
for( var j = 0; j < NavFrame.childNodes.length; j++ ) {
if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
NavToggle.style.color = NavFrame.childNodes[j].style.color;
NavFrame.childNodes[j].appendChild( NavToggle );
}
}
NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
}
} );
}
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
//Hide End
//隐藏内容,该部分代码复制自萌娘百科
//阅读更多:https://zh.moegirl.org/MediaWiki:Common.js
//文字内容遵守【知识共享 署名-非商业性使用-相同方式共享 3.0】协议。
//由于mw的锅导致部分文字可能超出#mw-content-text的范围,为这些文字的{{hide}}补上隐藏效果
function missedHideFun(obj) {
$('<span class="mw-collapsible-toggle"><span class="mw-collapsible-bracket">[</span><a href="javascript:void(0);"/><span class="mw-collapsible-bracket">]</span></span>').appendTo(obj.find('tr:first > :last'));
obj.find('.mw-collapsible-toggle a').text('隐藏').bind('click', function() {
var a = $(this).closest('table.mw-collapsible').find('tr').not(':first');
"none" == a.css("display") ? a.show() && $(this).text("显示") : a.hide() && $(this).text("隐藏");
});
obj.filter('.mw-collapsed').find('.mw-collapsible-toggle a').click();
}