MediaWiki:Gadget-blueUsers.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 → 选项),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件。
mw.loader.using( [ 'mediawiki.api', 'mediawiki.util' ] ).then( function () {
const namespaceIds = mw.config.get('wgNamespaceIds');
const namespaces = Object.keys( namespaceIds ).filter( ns => namespaceIds[ns] === 2 );
const selector = namespaces.map( ns => mw.config.get('wgArticlePath').replace('$1', ns + ':').toLowerCase() );
// User cache to not check them multiple times.
var blueUsers = [];
var missingUsers = [];
if ( mw.config.get('wgUserName') ) {
blueUsers.push( mw.util.wikiUrlencode( mw.config.get('wgUserName') ) );
}
var api = new mw.Api( {parameters: {
action: 'query',
list: 'users',
formatversion: 2
} } );
// Run every time content is added
mw.hook( 'wikipage.content' ).add( makeUsersBlue );
// Catch links outside the content area
makeUsersBlue( $('a.new').not('#mw-content-text a.new').parent() );
function makeUsersBlue( $content ) {
var users = [];
var userlinks = $content.find('a.new').filter( function () {
var pathname = decodeURIComponent( this.pathname ).toLowerCase();
return selector.some( ns => pathname.startsWith( ns ) );
} ).each( function () {
var encodedUsername = this.pathname.split(':')[1];
if ( missingUsers.includes( encodedUsername ) ) return;
if ( blueUsers.includes( encodedUsername ) ) {
this.href = this.pathname;
this.classList.remove( 'new' );
this.classList.add( 'mw-newuserlink' );
return;
}
var username = decodeURIComponent( encodedUsername );
if ( users.includes( username ) || username.includes( '/' ) ) return;
users.push( username );
} );
if ( !users.length ) return;
var apiRequests = [];
while ( users.length ) {
apiRequests.push( api.get( {
ususers: users.splice(0, 50)
} ).done( function ( data ) {
data.query.users.forEach( function ( user ) {
if ( user.missing || user.invalid ) {
missingUsers.push( mw.util.wikiUrlencode( user.name ) );
return;
}
blueUsers.push( mw.util.wikiUrlencode( user.name ) );
} );
} ) );
}
Promise.all( apiRequests ).then( function () {
userlinks.each( function () {
if ( !blueUsers.includes( this.pathname.split(':')[1] ) ) return;
this.href = this.pathname;
this.classList.remove( 'new' );
this.classList.add( 'mw-newuserlink' );
} );
} );
}
} );