/* 这里的任何JavaScript将为使用移动版网站的用户加载 */
//<nowiki>
// 经测试由ResourceLoader直接调用,不可使用ES6语法
/**
// 出於安全考慮,請盡可能使用jQuery代替htmlString
* @Description: 手机版全局JS
* @Author: 如无特殊说明,均为[[User:Bhsd]]
*/
"use strict";
/* global mw, $, wgULS */
mw.hook( 'wikipage.content' ).add(function( $content ) {
// tabs-dropdown解析错误
const collapsibleContent = $content.find( '.mw-collapsible:not(.mw-made-collapsible)' ),
$('.tabs-dropdown .tabs-content').append(function() { return $(this).next(); });
sortableContent = $content.find( 'table.sortable' );
// 折叠
/* 引自[[moegirl:mediawiki:mobile.js]] */
if (collapsibleContent.length) {
console.log('Hook: wikipage.content,开始执行折叠');
mw.loader.using( 'jquery.makeCollapsible' ).then(function() { collapsibleContent.makeCollapsible(); });
}
// 表格排序
if (sortableContent.length) {
console.log('Hook: wikipage.content,开始执行表格排序');
mw.loader.using( 'jquery.tablesorter' ).then(function() { sortableContent.tablesorter(); });
}
});
if ( ['Recentchanges', 'Watchlist'].includes( mw.config.get( 'wgCanonicalSpecialPageName' ) == "Recentchanges")) { ▼
// 快速编辑工具
mw.hook( 'structuredChangeFilters.ui.initialized' ).add(function() { ▼
if (['edit', 'submit'].includes( mw.config.get('wgAction') )) {
console.log('Hook: structuredChangeFilters.ui.initialized,开始修改filter'); ▼
$( '.mw-editTools' ).insertBefore( '#wpTextbox1' );
mw.loader.using( ['mediawiki.Uri', 'ext.gadget.site-lib'] ).then(function() { ▼
}
const var uri = new mw.Uri(), ▼
invert = uri.query.invert || 0 ,;▼
const node = $( '.mw-rcfilters-ui-itemMenuOptionWidget-view-namespaces' ).first().clone() ▼
▲if (mw.config.get( 'wgCanonicalSpecialPageName' ) == "Recentchanges") {
.insertAfter( $( '.mw-rcfilters-ui-filterMenuSectionOptionWidget' ).first() ) ▼
.attr('id', 'ooui-invert').removeClass( 'oo-ui-element-hidden' ) ▼
▲ mw.hook( 'structuredChangeFilters.ui.initialized' ).add(function() {
▲$ .on( 'click', function() {
▲ console.log('Hook: structuredChangeFilters.ui.initialized,开始修改filter');
uri = new mw.Uri();
▲ mw.loader.using( ['mediawiki.Uri', 'ext.gadget.site-lib'] ).then(function() {
invert = uri.query.invert || 0;
▲ const uri = new mw.Uri(),
location.replace( uri.extend({ invert: 1 - invert }) );
▲ invert = uri.query.invert || 0,
});
▲ node = $( '.mw-rcfilters-ui-itemMenuOptionWidget-view-namespaces' ).first().clone()
node.find( 'span.oo-ui-labelElement-label' ).text( wgULS("排除选项", "排除所選") ); ▼
▲ .insertAfter( $( '.mw-rcfilters-ui-filterMenuSectionOptionWidget' ).first() )
node.find( 'input' ).prop('checked', invert > 0) ▼
▲ .attr('id', 'ooui-invert').removeClass( 'oo-ui-element-hidden' )
.next().addClass( 'oo-ui-image-invert' ); ▼
.on('click', function() { window.location.href = uri.extend({ invert: 1 - invert }); });
});
▲ node.find( 'span.oo-ui-labelElement-label' ).text( wgULS("排除选项", "排除所選") );
▲ node.find( 'input' ).prop('checked', invert > 0)
▲ .next().addClass( 'oo-ui-image-invert' );
});
}
console.log( 'setInterval: 等待移动版菜单加载完毕' );
const timerStart = mw.now(),
timer = setInterval(function() {
if ($('.menu ul').length === 0) { return; }
clearInterval(timer);
mw.hook( 'mobile.menu' ).fire( $('.menu') );
console.log('End setInterval: 移动版菜单加载完毕,用时 ' + (mw.now() - timerStart) + ' ms');
}, 200);
/* Mobile Navmenu by GFwiki */
$.when($.ready, mw.loader.using( ['mediawiki.util', 'ext.gadget.site-lib'] )).then(function() {
const script = mw.config.get( 'wgScript' ),
pagename = mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ),
pageid = mw.config.get( 'wgArticleId' ),
nsid = mw.config.get( 'wgNamespaceNumber' ),
title = mw.util.wikiUrlencode( mw.config.get( 'wgTitle' ) ),
lang = mw.config.get( 'wgUserLanguage' );
$('<div>').load(script + '?title=MediaWiki:MFSidebar&variant=' + lang + ' #mw-content-text ul', function() {
const nav = $(this).children();
if (pageid > 0) {
nav.append( $('<li>').append( $('<a>', {href: script + '/Special:链入页面/' + pagename,
html: '<i class="fa fa-quote-right"></i><span>' + wgULS("链入页面", "連結至此的頁面") + '</span>'
}) ) ).append( $('<li>').append( $('<a>', {href: script + '/Special:链出更改/' + pagename,
html: '<i class="fa fa-share-alt"></i><span>' + wgULS("相关更改", "相關變更") + '</span>'
}) ) ).append( $('<li>').append( $('<a>', {
href: script + '?title=Special:前缀索引&prefix=' + title + '/&namespace=' + nsid + '&stripprefix=1',
html: '<i class="fa fa-folder-open"></i><span>' + wgULS("子页面", "子頁面") + '</span>'
}) ) );
}
mw.hook( 'mobile.menu' ).add(function($menu) {
console.log('Hook: mobile.menu,开始添加移动版菜单项');
$menu.children( 'ul' ).first().after(nav);
});
});
//</nowiki>
// [[category:作为模块的小工具]] [[category:不可关闭的小工具]] [[category:手机版小工具]]
|