User:Ricordisamoa/GeneaWiki.js

From Wikidata
Jump to navigation Jump to search

Note: After saving, 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: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* <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 () {
	if ( mw.config.exists( 'wbEntityId' ) && mw.config.exists( 'wbEntity' ) ) {// only on entities
		var properties = [
			'P45',// grandparent
			'P22',// father
			'P25',// mother
			'P40',// child
			'P7', // brother
			'P9', // sister
			'P26',// spouse
			'P29' // uncle
		],
		data = JSON.parse( mw.config.get( 'wbEntity' ) );
		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( $( '.wb-claims' ).first() );
					return false;
				}
			} );
		}
	}
} );