Gadget:avatar.js:修订间差异
小 (// Edit via Wikiplus) |
(// Edit via Wikiplus) |
||
| (未显示同一用户的14个中间版本) | |||
| 第1行: | 第1行: | ||
$( function () { | |||
if ( !mw.user.isAnon() ) { | |||
const $img = $( '<img>' ).attr( | |||
'src', | |||
mw.config.get( 'wgScriptPath' ) + | |||
); | '/index.php?title=Special:Avatar&wpUsername=' + | ||
mw.user.id() | |||
).attr( 'width', 28 ).attr( 'height', 28 ); | |||
const $link = $( '<a>' ) | |||
if (!document.body.classList.contains( | .attr( 'href', mw.util.getUrl( 'Special:UploadAvatar' ) ) | ||
.append( $img ); | |||
} else { | if ( !document.body.classList.contains( 'skin-vector-legacy' ) ) { | ||
$( '#pt-userpage-2' ).before( $( '<li>' ).attr( 'id', 'pt-avatar' ).append( $link ) ); | |||
} | } else { | ||
$( | $( '#pt-userpage' ).before( $( '<li>' ).attr( 'id', 'pt-avatar' ).append( $link ) ); | ||
} | |||
} | |||
function setAvatar() { | |||
$( 'a.mw-userlink:not(.mw-anonuserlink)' ).each( function ( _, item ) { | |||
item.prepend( | |||
$( '<img>' ) | |||
.addClass( 'userlink-avatar' ) | |||
.attr( 'src', mw.config.get( 'wgScriptPath' ) + '/index.php?title=Special:Avatar&wpUsername=' + item.textContent )[ 0 ] | |||
); | |||
} ); | |||
} | |||
}); | mw.hook( 'wikipage.content' ).add( function ( e ) { | ||
if ( e.attr( 'id' ) === 'mw-content-text' ) { | |||
setAvatar(); | |||
return; | |||
} | |||
if ( e.hasClass( 'mw-changeslist' ) ) { | |||
setAvatar(); | |||
} | |||
} ); | |||
} ); | |||
2023年7月24日 (一) 09:25的最新版本
$( function () {
if ( !mw.user.isAnon() ) {
const $img = $( '<img>' ).attr(
'src',
mw.config.get( 'wgScriptPath' ) +
'/index.php?title=Special:Avatar&wpUsername=' +
mw.user.id()
).attr( 'width', 28 ).attr( 'height', 28 );
const $link = $( '<a>' )
.attr( 'href', mw.util.getUrl( 'Special:UploadAvatar' ) )
.append( $img );
if ( !document.body.classList.contains( 'skin-vector-legacy' ) ) {
$( '#pt-userpage-2' ).before( $( '<li>' ).attr( 'id', 'pt-avatar' ).append( $link ) );
} else {
$( '#pt-userpage' ).before( $( '<li>' ).attr( 'id', 'pt-avatar' ).append( $link ) );
}
}
function setAvatar() {
$( 'a.mw-userlink:not(.mw-anonuserlink)' ).each( function ( _, item ) {
item.prepend(
$( '<img>' )
.addClass( 'userlink-avatar' )
.attr( 'src', mw.config.get( 'wgScriptPath' ) + '/index.php?title=Special:Avatar&wpUsername=' + item.textContent )[ 0 ]
);
} );
}
mw.hook( 'wikipage.content' ).add( function ( e ) {
if ( e.attr( 'id' ) === 'mw-content-text' ) {
setAvatar();
return;
}
if ( e.hasClass( 'mw-changeslist' ) ) {
setAvatar();
}
} );
} );