LLWiki正在建设中,欢迎加入我们!
“MediaWiki:Gadget-MobileCategories.js”的版本间差异
跳转到导航
跳转到搜索
小 标签:移动版网页编辑 移动版编辑 |
标签:撤销 |
||
(未显示2个用户的6个中间版本) | |||
第12行: | 第12行: | ||
const showhiddencats = mw.user.options.get( 'showhiddencats' ), |
const showhiddencats = mw.user.options.get( 'showhiddencats' ), |
||
pageName = mw.config.get( 'wgPageName' ), |
|||
pageViewLang = mw.config.get( 'wgPageContentLanguage' ); // This variable was misnamed |
|||
⚫ | |||
if ( pageViewLang == 'en' ) { return; } |
|||
hidden = showhiddencats ? categories.hidden : []; |
|||
⚫ | |||
function trimNamespace( title ) { |
|||
return title.slice( title.indexOf( ':' ) + 1 ); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
if (normal.length) { |
|||
const specialCategories = 'Special:' + mw.msg( 'categories' ); |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
} |
||
new mw.Api().get( { |
|||
"action": "query", |
|||
⚫ | |||
"format": "json", |
|||
⚫ | |||
"formatversion": "2", |
|||
⚫ | |||
"generator": "categories", |
|||
⚫ | |||
"gcllimit": "max", |
|||
} |
|||
"prop": "info|categoryinfo", |
|||
⚫ | |||
"inprop": "varianttitles", |
|||
"titles": pageName, |
|||
} ).then( function ( res ) { |
|||
const categories = { 'normal': [], 'hidden': [] }, convertedCats = {}; |
|||
if ( !res.query ) { return; } |
|||
res.query.pages.forEach( function ( ele ) { |
|||
const type = ele.categoryinfo.hidden ? 'hidden' : 'normal', |
|||
title = trimNamespace( ele.title ); |
|||
categories[ type ].push( title ); |
|||
convertedCats[ title ] = trimNamespace( ele.varianttitles[ pageViewLang ] ); |
|||
}); |
|||
mw.config.set( 'wgCategories', [].concat( categories.normal, categories.hidden ) ); |
|||
⚫ | |||
⚫ | |||
const cats = categories[ type ]; |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
if (categories.hidden.length && showhiddencats) { |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
⚫ | |||
} ); |
|||
}); |
}); |
||
//</nowiki> |
//</nowiki> |
2023年3月30日 (四) 23:41的最新版本
//<nowiki> // 由ResourceLoader直接调用,不可使用ES6语法 /** * @Function: 移动版渲染分类栏 * @Dependencies: mediawiki.util, user.options * @OriginalVersion: [[wikipedia:mediawiki:gadget-MobileCategories.js]] * @EditedBy: [[User:Bhsd]] */ "use strict"; $(function() { if (mw.config.get( 'wgAction' ) != 'view' || mw.config.get( 'wgArticleId' ) === 0) { return; } const showhiddencats = mw.user.options.get( 'showhiddencats' ), pageName = mw.config.get( 'wgPageName' ), pageViewLang = mw.config.get( 'wgPageContentLanguage' ); // This variable was misnamed if ( pageViewLang == 'en' ) { return; } function trimNamespace( title ) { return title.slice( title.indexOf( ':' ) + 1 ); } new mw.Api().get( { "action": "query", "format": "json", "formatversion": "2", "generator": "categories", "gcllimit": "max", "prop": "info|categoryinfo", "inprop": "varianttitles", "titles": pageName, } ).then( function ( res ) { const categories = { 'normal': [], 'hidden': [] }, convertedCats = {}; if ( !res.query ) { return; } res.query.pages.forEach( function ( ele ) { const type = ele.categoryinfo.hidden ? 'hidden' : 'normal', title = trimNamespace( ele.title ); categories[ type ].push( title ); convertedCats[ title ] = trimNamespace( ele.varianttitles[ pageViewLang ] ); }); mw.config.set( 'wgCategories', [].concat( categories.normal, categories.hidden ) ); if (!categories.normal.length && !categories.hidden.length) { return; } const categoryHtmlGenerator = function(type) { const cats = categories[ type ]; return $('<ul>', {html: cats.map(function(cat) { const page = 'Category:' + cat; return $('<a>', {href: mw.util.getUrl( page ), title: page, text: convertedCats[cat]}).wrap( '<li>' ).parent(); })}); }, $catlinks = $('<div>', {class: 'catlinks', id: 'catlinks'}).insertAfter( '.printfooter' ); if (categories.normal.length) { $('<div>', {id: 'mw-normal-catlinks', class: 'mw-normal-catlinks', html: [ $('<a>', {href: '/zh/Special:页面分类', title: 'Special:页面分类', text: mw.msg( 'pagecategories' )}), mw.msg( 'colon-separator' ), categoryHtmlGenerator( 'normal' ) ]}).appendTo( $catlinks ); } if (categories.hidden.length && showhiddencats) { $('<div>', {id: 'mw-hidden-catlinks', class: 'mw-hidden-catlinks mw-hidden-cats-user-shown', html: [ mw.msg( 'hidden-categories' ) + mw.msg( 'colon-separator' ), categoryHtmlGenerator( 'hidden' ) ]}).appendTo( $catlinks ); } mw.hook( 'wikipage.categories' ).fire( $catlinks ); } ); }); //</nowiki> // [[category:手机版小工具]] [[category:分类工具]] [[category:作为模块的小工具]] // {{DEFAULTSORT:MobileCategories.js}}