Gadget:avatar.js

Litwak913留言 | 贡献2023年7月23日 (日) 18:37的版本 (// Edit via Wikiplus)
$( 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-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 ]
		);
	} );
} );