LLWiki正在建设中,欢迎加入我们!
“User:Bhsd/minerva.js”的版本间差异
跳转到导航
跳转到搜索
小 |
小 |
||
第54行: | 第54行: | ||
console.log('End API request: 已获得最新修订ID,用时 ' + (mw.now() - timerStart) + ' ms'); |
console.log('End API request: 已获得最新修订ID,用时 ' + (mw.now() - timerStart) + ' ms'); |
||
addDiffLink(parseInt( data.query.pages[0].lastrevid )); |
addDiffLink(parseInt( data.query.pages[0].lastrevid )); |
||
}, function(reason) { console.error('Failed API request: 无法获得最新修订ID。错误信息:' + reason); }); |
|||
}); |
|||
}); |
}); |
||
}); |
}); |
2020年12月6日 (日) 01:38的版本
//<nowiki> // 拆分自[[Special:Mypage/common.js]],不可使用ES6语法 "use strict"; /*global mw, $, wgULS*/ mw.loader.using( 'mediawiki.util' ).then(function() { const nsid = mw.config.get( 'wgNamespaceNumber' ), specialPageName = mw.config.get( 'wgCanonicalSpecialPageName' ), pageName = mw.util.wikiUrlencode( mw.config.get( 'wgPageName' ) ), title = mw.util.wikiUrlencode( mw.config.get('wgTitle') ), script = mw.config.get('wgScript'); if (nsid >= 0 && mw.config.get('wgAction') == 'view') { // 移动版强制章节折叠 mw.loader.load(script + '?title=user:bhsd/mobileCollapse.js&action=raw&ctype=text/javascript'); } if (specialPageName == 'Recentchanges') { mw.hook( 'wikipage.content' ).add(function($content) { // 移除多余的符号和空白字符 console.log('Hook: wikipage.content,开始移除多余字符'); $content.find( '.mw-changeslist-line-inner' ).contents().filter(function() { return this.nodeType === 3; }).remove(); }); } if (specialPageName == "History") { /* 移动版历史添加与当前对比链接 */ const addDiffLink = function(lastrevid) { $('.page-summary > a').each(function() { const oldid = parseInt( this.href.match( /\d+$/ ) ); if (oldid < lastrevid) { $(this).children( '.list-thumb' ).append( $('<p>').append( $('<a>', {text: wgULS("当前", "目前"), href: script + '/special:移动版差异/' + oldid + '...' + lastrevid }) ) ); } }); }, href = window.location.href; mw.loader.using( 'mediawiki.api' ).then(function() { mw.hook( 'wikipage.content' ).add(function() { console.log('Hook: wikipage.content,开始添加与当前对比链接'); if ( !mw.util.getParamValue( 'offset' ) ) { const lastrevid = $('.page-summary > a').first().attr( 'href' ).match(/\d+$/); addDiffLink(parseInt( lastrevid )); return; } const timerStart = mw.now(); console.log( 'API request: 查询最新修订ID' ); new mw.Api().get({ action: 'query', prop: 'info', titles: mw.config.get( 'wgRelevantPageName' ), formatversion: 2 }).then(function(data) { console.log('End API request: 已获得最新修订ID,用时 ' + (mw.now() - timerStart) + ' ms'); addDiffLink(parseInt( data.query.pages[0].lastrevid )); }, function(reason) { console.error('Failed API request: 无法获得最新修订ID。错误信息:' + reason); }); }); }); } /* 自定义移动版导航 */ mw.hook( 'mobile.menu' ).add(function($menu) { console.log('Hook: mobile.menu,开始添加自定义导航项目'); $menu.find( '.mw-ui-icon-minerva-contributions' ).parent() .after( $('<li>').append( $('<a>', { href: script + '?title=Special:前缀索引&prefix=' + title + '/&namespace=' + nsid + '&stripprefix=1', html: '<i class="fa fa-folder-open"></i><span>子页面</span>' }) ) ).after( $('<li>').append( $('<a>', { href: script + '?title=Special:展开模板&wpRemoveComments=1&wpGenerateRawHtml=true&wpInput={{:' + pageName + '}}', html: '<i class="fa fa-hourglass-half"></i><span>展开模板</span>' }) ) ).after( $('<li>').append( $('<a>', { href: script + '?title=Special:所有页面&namespace=' + nsid, html: '<i class="fa fa-copy"></i><span>所有页面</span>' }) ) ).after( $('<li>').append( $('<a>', { href: script + '/Special:替换文本', html: '<i class="fa fa-retweet"></i><span>替换文本</span>' }) ) ).after( $('<li>').append( $('<a>', { href: script + '/Special:滥用过滤器', html: '<i class="fa fa-ban"></i><span>滥用过滤器</span>' }) ) ).after( $('<li>').append( $('<a>', { href: script + '?target=http://*&title=Special:链接搜索', html: '<i class="fas fa-external-link-alt"></i><span>链接搜索</span>' }) ) ).after( $('<li>').append( $('<a>', { href: script + '?title=Special:用户列表&creationSort=1&desc=1', html: '<i class="fa fa-users"></i><span>用户列表</span>' }) ) ).after( $('<li>').append( $('<a>', { href: script + '/Special:版本', html: '<i class="fa fa-puzzle-piece"></i><span>版本</span>' }) ) ); }); }); //</nowiki>