$( 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();
}
} );
} );