User:Kaldari/wikigrok.js

// ( function( $ ) {	var wikidataID = mw.config.get( 'wgWikibaseItemId' ),		idOverride;

// Allow query string override for testing, for example, '?wikidataid=Q508703' if ( !wikidataID ) { idOverride = window.location.search.match( /wikidataid=([^&]*)/ ); if ( idOverride ) { mw.config.set( 'wgWikibaseItemId', idOverride[1] ); wikidataID = idOverride[1]; }	}	if ( !mw.config.get( 'wgIsMainPage' ) &&		mw.config.get( 'wgAction' ) === 'view' &&		wikidataID &&		mw.config.get( 'wgNamespaceNumber' ) === 0	) { // Get existing Wikidata claims about this page so we can decide if it's appropriate // to display the WikiGrok interface. $.ajax( {			type: 'get',			url: 'https://www.wikidata.org/w/api.php',			data: {				'action': 'wbgetentities',				'ids': wikidataID,				'props': 'claims',				'format': 'json'			},			dataType: 'jsonp',			success: function( data ) {				var instanceClaims,					loadWikiGrokDialog = false;				// See if the page has any 'instance of' claims.				if ( data.entities !== undefined && data.entities[wikidataID].claims.P31 !== undefined ) {					instanceClaims = data.entities[wikidataID].claims.P31;					$.each( instanceClaims, function( id, claim ) { // See if any of the claims state that the topic is a human. if ( claim.mainsnak.datavalue.value['numeric-id'] === 5 ) { // Make sure there are no existing occupation claims. if ( data.entities[wikidataID].claims.P106 === undefined ) { loadWikiGrokDialog = true; }							// Break each loop. return false; }					} );					if ( loadWikiGrokDialog ) {						importScript( 'User:Kaldari/wikigrokdialog.js' );					}				}			} // close success		} ); // close ajax call } }( jQuery ) ); //