LLWiki正在建设中,欢迎加入我们!
MediaWiki:Gadget-MobileCategories.js
跳转到导航
跳转到搜索
注意:在保存之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。
- Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5或Ctrl-R(Mac为⌘-R)
- Google Chrome:按Ctrl-Shift-R(Mac为⌘-Shift-R)
- Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
- Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
//<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}}