$( 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 ) );
}
}
mw.hook( 'wikipage.content' ).add( function () {
$( '.mw-userlink' ).each( function ( _, item ) {
item.prepend(
$( '<img>' )
.addClass( 'userlink-avatar' )
.attr( 'src', mw.config.get( 'wgScriptPath' ) + '/index.php?title=Special:Avatar&wpUsername=' + item.text() )[ 0 ]
);
} );
} );
} );