User:Ricordisamoa/GeneaWiki.js

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.
/* <nowiki>
 *
 * GeneaWiki.js
 * @author [[User:Ricordisamoa]]
 * Provides a link to 'GeneaWiki' by Magnus Manske
 * http://toolserver.org/~magnus/ts2/geneawiki/
 * for Wikidata elements with 'kinship properties'
*/
$( document ).ready( function () {
	mw.hook( 'wikibase.entityPage.entityLoaded' ).add( function ( data ) {
		// only on entities
		var properties = [
			'P45',// grandparent
			'P22',// father
			'P25',// mother
			'P40',// child
			'P7', // brother
			'P9', // sister
			'P26',// spouse
			'P29' // uncle
		];
		if ( data.claims ) {
			$.each( properties, function ( i, prop ) {
				if ( data.claims[prop] !== undefined ) {
					// there are kinship properties
					var baseUrl = '//tools.wmflabs.org/magnus-toolserver/ts2/geneawiki/',
					params = {
						q: mw.config.get( 'wbEntityId' ),
					};
					$( '<a>' )
					.text( 'GeneaWiki' )
					.css( 'display', 'table-row' )
					.attr( 'href', baseUrl + '?' + $.param( params ) )
					.insertBefore( $( '.wikibase-statements' ).first() );
					return false;
				}
			} );
		}
	} );
} );