User:MZMcBride/embeddedin.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/* This is a proof-of-concept 'embeddedin detector' script using AJAX. */

if(mw.config.get('wgNamespaceNumber') == 10) embedded = function() {
	var query = {
		'action': 'query',
		'list': 'embeddedin',
		'eititle': mw.config.get('wgPageName'),
		'eilimit': 1
	}
	var wikipedia_api = new Wikipedia.api( 'Checking for embeddedness', query, function( self ) {
		var xmlDoc = self.responseXML;
		var embedded = xmlDoc.evaluate( '//embeddedin/ei', xmlDoc, null, XPathResult.BOOLEAN_TYPE, null ).booleanValue;
		if(!embedded) {
                  document.getElementById('globalWrapper').style.background = '#FFD089';
		}
		});
	wikipedia_api.post();
}

if(mw.config.get('wgNamespaceNumber') == 10) addOnloadHook(embedded);