LLWiki正在建设中,欢迎加入我们!
“MediaWiki:Gadget-MobileCategories.js”的版本间差异
跳转到导航
跳转到搜索
小 标签:移动版网页编辑 移动版编辑 |
小 |
||
第1行: | 第1行: | ||
// 引自[[wikipedia:mediawiki:gadget-MobileCategories.js]] |
// 引自[[wikipedia:mediawiki:gadget-MobileCategories.js]] |
||
$(function() { |
$(function() { |
||
if( mw.config.get('skin') == 'vector' || |
if ( mw.config.get('skin') == 'vector' || |
||
!["view","submit"].includes(mw.config.get('wgAction')) ) { |
!["view","submit"].includes(mw.config.get('wgAction')) ) { |
||
window.MobileCategoriesComplete = true; |
window.MobileCategoriesComplete = true; |
||
第19行: | 第19行: | ||
allCats = response1Data.query.pages[0].categories || []; |
allCats = response1Data.query.pages[0].categories || []; |
||
if( allCats.length === 0 ) { |
if ( allCats.length === 0 ) { |
||
window.MobileCategoriesComplete = true; |
window.MobileCategoriesComplete = true; |
||
return; |
return; |
||
} |
} |
||
mw.config.set('wgCategories', allCats.map(function(ele) { return ele.title.slice(9); })); |
|||
api.get({ action:'parse', text:JSON.stringify(allCats), contentmodel:'wikitext', variant:mw.config.get('wgUserVariant'), formatversion:2, prop:'text' }) |
api.get({ action:'parse', text:JSON.stringify(allCats), contentmodel:'wikitext', variant:mw.config.get('wgUserVariant'), formatversion:2, prop:'text' }) |
||
第30行: | 第31行: | ||
function categoryHtmlGenerator(element, index, array) { |
function categoryHtmlGenerator(element, index, array) { |
||
if( !element.hidden ) { |
if ( !element.hidden ) { |
||
categories.push( $('<li>').append( |
categories.push( $('<li>').append( |
||
$( '<a>' ).attr( 'href', mw.util.getUrl( element.title ) ) |
$( '<a>' ).attr( 'href', mw.util.getUrl( element.title ) ) |
||
第38行: | 第39行: | ||
); |
); |
||
} |
} |
||
else if(showhiddencats) { |
else if (showhiddencats) { |
||
hiddenCats.push( $('<li>').append( |
hiddenCats.push( $('<li>').append( |
||
$( '<a>' ).attr( 'href', mw.util.getUrl( element.title ) ) |
$( '<a>' ).attr( 'href', mw.util.getUrl( element.title ) ) |
||
第50行: | 第51行: | ||
allCats.forEach( categoryHtmlGenerator ); |
allCats.forEach( categoryHtmlGenerator ); |
||
if( categories.length === 0 && hiddenCats.length === 0 ) { |
if ( categories.length === 0 && hiddenCats.length === 0 ) { |
||
window.MobileCategoriesComplete = true; |
window.MobileCategoriesComplete = true; |
||
return; |
return; |
||
第56行: | 第57行: | ||
var normalCatlinks, hiddenCatlinks; |
var normalCatlinks, hiddenCatlinks; |
||
if(categories.length) { |
if (categories.length) { |
||
normalCatlinks = $( '<div>' ) |
normalCatlinks = $( '<div>' ) |
||
.attr( 'id', 'mw-normal-catlinks' ) |
.attr( 'id', 'mw-normal-catlinks' ) |
||
第63行: | 第64行: | ||
.prepend( '<a href="/zh/Special:Categories" title="Special:页面分类">' + mw.message( 'pagecategories' ).escaped() + '</a>' + mw.message( 'colon-separator' ).escaped() ); |
.prepend( '<a href="/zh/Special:Categories" title="Special:页面分类">' + mw.message( 'pagecategories' ).escaped() + '</a>' + mw.message( 'colon-separator' ).escaped() ); |
||
} |
} |
||
if(hiddenCats.length) { |
if (hiddenCats.length) { |
||
hiddenCatlinks = $( '<div>' ) |
hiddenCatlinks = $( '<div>' ) |
||
.attr( 'id', 'mw-hidden-catlinks' ) |
.attr( 'id', 'mw-hidden-catlinks' ) |
||
第74行: | 第75行: | ||
.attr( 'id', 'catlinks' ) |
.attr( 'id', 'catlinks' ) |
||
.data( 'mw', 'interface' ); |
.data( 'mw', 'interface' ); |
||
if(normalCatlinks) { catlinks.append(normalCatlinks); } |
if (normalCatlinks) { catlinks.append(normalCatlinks); } |
||
if(hiddenCatlinks) { catlinks.append(hiddenCatlinks); } |
if (hiddenCatlinks) { catlinks.append(hiddenCatlinks); } |
||
$('.printfooter').after(catlinks); |
$('.printfooter').after(catlinks); |
||
window.MobileCategoriesComplete = true; |
window.MobileCategoriesComplete = true; |
2020年11月10日 (二) 22:31的版本
// 引自[[wikipedia:mediawiki:gadget-MobileCategories.js]] $(function() { if ( mw.config.get('skin') == 'vector' || !["view","submit"].includes(mw.config.get('wgAction')) ) { window.MobileCategoriesComplete = true; return; } var showhiddencats = mw.user.options.get('showhiddencats'), api = new mw.Api(), apiRequest = api.get( {action:'query', titles: mw.config.get('wgPageName'), prop: 'categories', clprop: 'hidden', cllimit: 50, formatversion: 2 } ), apiRequest2 = api.loadMessagesIfMissing( [ 'pagecategories', 'colon-separator' ] ); $.when( apiRequest, apiRequest2 ).done( function( data ) { var categories = [], hiddenCats = [], response1Data = data[0], response2Data = data[1], allCats = response1Data.query.pages[0].categories || []; if ( allCats.length === 0 ) { window.MobileCategoriesComplete = true; return; } mw.config.set('wgCategories', allCats.map(function(ele) { return ele.title.slice(9); })); api.get({ action:'parse', text:JSON.stringify(allCats), contentmodel:'wikitext', variant:mw.config.get('wgUserVariant'), formatversion:2, prop:'text' }) .then(function(data2) { const allCatsVar = data2.parse.text.match(/<p>(.*)\n<\/p>/)[1], contentCats = JSON.parse(allCatsVar); function categoryHtmlGenerator(element, index, array) { if ( !element.hidden ) { categories.push( $('<li>').append( $( '<a>' ).attr( 'href', mw.util.getUrl( element.title ) ) .attr( 'title', element.title ) .append( document.createTextNode( contentCats[index].title.substring(9) ) ) ).get( 0 ) ); } else if (showhiddencats) { hiddenCats.push( $('<li>').append( $( '<a>' ).attr( 'href', mw.util.getUrl( element.title ) ) .attr( 'title', element.title ) .append( document.createTextNode( contentCats[index].title.substring(9) ) ) ).get( 0 ) ); } } allCats.forEach( categoryHtmlGenerator ); if ( categories.length === 0 && hiddenCats.length === 0 ) { window.MobileCategoriesComplete = true; return; } var normalCatlinks, hiddenCatlinks; if (categories.length) { normalCatlinks = $( '<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() ); } if (hiddenCats.length) { hiddenCatlinks = $( '<div>' ) .attr( 'id', 'mw-hidden-catlinks' ) .addClass(['mw-hidden-catlinks', 'mw-hidden-cats-user-shown']) .append( $( '<ul>' ).append( hiddenCats ) ) .prepend( wgULS("隐藏分类", "隱藏分類") + mw.message( 'colon-separator' ).escaped() ); } var catlinks = $( '<div>' ) .addClass( 'catlinks' ) .attr( 'id', 'catlinks' ) .data( 'mw', 'interface' ); if (normalCatlinks) { catlinks.append(normalCatlinks); } if (hiddenCatlinks) { catlinks.append(hiddenCatlinks); } $('.printfooter').after(catlinks); window.MobileCategoriesComplete = true; }); } ); } );