LLWiki正在建设中,欢迎加入我们!
“MediaWiki:Gadget-MobileCategories.js”的版本间差异
跳转到导航
跳转到搜索
小 |
|||
第12行: | 第12行: | ||
const showhiddencats = mw.user.options.get( 'showhiddencats' ), |
const showhiddencats = mw.user.options.get( 'showhiddencats' ), |
||
categories = mw.config.get( ' |
categories = mw.config.get( 'wgCategories' ), |
||
convertedCategories = mw.config.get( 'wgConvertedCategories' ), |
|||
normal = categories.normal, |
normal = categories.normal, |
||
hidden = showhiddencats ? categories.hidden : []; |
hidden = showhiddencats ? categories.hidden : []; |
||
第18行: | 第19行: | ||
const categoryHtmlGenerator = function(array) { |
const categoryHtmlGenerator = function(array) { |
||
const cats = categories[ array ], |
|||
⚫ | |||
convertedCats = convertedCategories[ array ]; |
|||
⚫ | |||
const page = 'Category:' + cat; |
const page = 'Category:' + cat; |
||
return $('<a>', {href: mw.util.getUrl( page ), title: page, text: |
return $('<a>', {href: mw.util.getUrl( page ), title: page, text: convertedCats[i]}).wrap( '<li>' ).parent(); |
||
})}); |
})}); |
||
}, |
}, |
||
第28行: | 第31行: | ||
$('<a>', {href: '/zh/Special:页面分类', title: 'Special:页面分类', text: mw.msg( 'pagecategories' )}), |
$('<a>', {href: '/zh/Special:页面分类', title: 'Special:页面分类', text: mw.msg( 'pagecategories' )}), |
||
mw.msg( 'colon-separator' ), |
mw.msg( 'colon-separator' ), |
||
categoryHtmlGenerator( normal ) |
categoryHtmlGenerator( 'normal' ) |
||
]}).appendTo( $catlinks ); |
]}).appendTo( $catlinks ); |
||
} |
} |
||
第34行: | 第37行: | ||
$('<div>', {id: 'mw-hidden-catlinks', class: 'mw-hidden-catlinks mw-hidden-cats-user-shown', html: [ |
$('<div>', {id: 'mw-hidden-catlinks', class: 'mw-hidden-catlinks mw-hidden-cats-user-shown', html: [ |
||
mw.msg( 'hidden-categories' ) + mw.msg( 'colon-separator' ), |
mw.msg( 'hidden-categories' ) + mw.msg( 'colon-separator' ), |
||
categoryHtmlGenerator( hidden ) |
categoryHtmlGenerator( 'hidden' ) |
||
]}).appendTo( $catlinks ); |
]}).appendTo( $catlinks ); |
||
} |
} |
2021年10月13日 (三) 05:39的版本
//<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' ), categories = mw.config.get( 'wgCategories' ), convertedCategories = mw.config.get( 'wgConvertedCategories' ), normal = categories.normal, hidden = showhiddencats ? categories.hidden : []; if (normal.length === 0 && hidden.length === 0) { return; } const categoryHtmlGenerator = function(array) { const cats = categories[ array ], convertedCats = convertedCategories[ array ]; return $('<ul>', {html: cats.map(function(cat, i) { const page = 'Category:' + cat; return $('<a>', {href: mw.util.getUrl( page ), title: page, text: convertedCats[i]}).wrap( '<li>' ).parent(); })}); }, $catlinks = $('<div>', {class: 'catlinks', id: 'catlinks'}).insertAfter( '.printfooter' ); if (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 (hidden.length) { $('<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}}