User:Inductiveload/scripts/ShowQsAndPs.js

From Wikidata
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
( function ( $, mw ) {
	$( function () {
		// eslint-disable-next-line no-jquery/no-global-selector
		$( '.wikibase-statementgroupview' ).each( function ( idx, elem ) {
			$( elem )
				.find( '.wikibase-statementgroupview-property-label' )
				.append( '<br>' )
				.append( $( '<span>' )
					.append( elem.getAttribute( 'data-property-id' ) )
				);

			$( elem )
				.find( '.wikibase-snakview-value a' )
				.each( function ( vidx, val ) {
					const qid = ( val.getAttribute( 'href' ) || '' ).replace( /^.*\//, '' );

					if ( !/^Q\d+$/.test( qid ) ) {
						return;
					}

					$( val )
						.after( $( '<span>' )
							.append( qid )
						)
						.after( ' / ' );
				} );

			$( elem )
				.find( '.wikibase-snakview-property a' )
				.each( function ( vidx, val ) {
					const qid = ( val.getAttribute( 'href' ) || '' ).replace( /^.*:/, '' );

					if ( !/^Q\d+$/.test( qid ) ) {
						return;
					}

					$( val )
						.after( $( '<span>' )
							.append( qid )
						)
						.after( ' / ' );
				} );
		} );
	} );

// eslint-disable-next-line no-undef
}( jQuery, mediaWiki ) );