Gadget:avatar.js

Litwak913留言 | 贡献2023年7月24日 (一) 09:22的版本 (// 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.hook( 'wikipage.content' ).add( function (e) {
		$( '.mw-userlink' ).each( function ( _, item ) {
			item.prepend(
				$( '<img>' )
					.addClass( 'userlink-avatar' )
					.attr( 'src', mw.config.get( 'wgScriptPath' ) + '/index.php?title=Special:Avatar&wpUsername=' + item.textContent )[ 0 ]
			);
		} );
	} );
} );