LLWiki正在建设中,欢迎加入我们!
“MediaWiki:Gadget-MobileCategories.js”的版本间差异
跳转到导航
跳转到搜索
小 |
小 |
||
第8行: | 第8行: | ||
'titles': mw.config.get('wgPageName'), |
'titles': mw.config.get('wgPageName'), |
||
'prop': 'categories', |
'prop': 'categories', |
||
' |
'clshow': '!hidden', |
||
'cllimit': 50, |
'cllimit': 50, |
||
'indexpageids': true, |
'indexpageids': true, |
||
第24行: | 第24行: | ||
function categoryHtmlGenerator(element, index, array) { |
function categoryHtmlGenerator(element, index, array) { |
||
var title = new mw.Title( element.title, mw.config.get( 'wgNamespaceIds' ).file ); |
var title = new mw.Title( element.title, mw.config.get( 'wgNamespaceIds' ).file ); |
||
categories.push( $('<li>').append( |
|||
$( '<a>' ).attr( 'href', mw.util.getUrl( element.title ) ) |
|||
.attr( 'title', title ) |
|||
.append( document.createTextNode( title.getMainText() ) ) |
|||
).get( 0 ) |
|||
); |
|||
); |
|||
} |
|||
} |
} |
||
2020年8月14日 (五) 06:40的版本
// 引自[[wikipedia:mediawiki:gadget-MobileCategories.js]] mw.hook( 'wikipage.content' ).add( function() { if(mw.config.get('skin') == 'vector') { return; } var api = new mw.Api(), apiRequest = api.get( { 'action':'query', 'titles': mw.config.get('wgPageName'), 'prop': 'categories', 'clshow': '!hidden', 'cllimit': 50, 'indexpageids': true, 'formatversion': 2 } ), apiRequest2 = api.loadMessagesIfMissing( [ 'pagecategories', 'colon-separator' ] ); $.when( apiRequest, apiRequest2 ).done( function( data ) { var categories = [], response1Data = data[0], response2Data = data[1]; if( !response1Data.query.pages[0].categories ) { return; } function categoryHtmlGenerator(element, index, array) { var title = new mw.Title( element.title, mw.config.get( 'wgNamespaceIds' ).file ); categories.push( $('<li>').append( $( '<a>' ).attr( 'href', mw.util.getUrl( element.title ) ) .attr( 'title', title ) .append( document.createTextNode( title.getMainText() ) ) ).get( 0 ) ); } response1Data.query.pages[0].categories.forEach( categoryHtmlGenerator ); if( categories.length === 0 ) { return; } var catlinks = $( '<div>' ) .attr( 'id', 'mw-normal-catlinks' ) .addClass('mw-normal-catlinks') .append( $( '<ul>' ).append( categories ) ) .prepend( '<a href="/zh/Special:Categories" title="Special:页面分类">' + mw.message( 'pagecategories' ).escaped() + '</a>' + mw.message( 'colon-separator' ).escaped() ); $('.printfooter') .after( $( '<div>' ) .addClass( 'catlinks' ) .attr( 'id', 'catlinks' ) .data( 'mw', 'interface' ) .append( catlinks ) ); } ); } );