User:AzaToth/embedded.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.
function embedded() {
	mw.util.addPortletLink( 'p-cactions', "javascript:embedded.callback()", "e?", "embedded", "Is the page embedded?", "");
}

$(embedded);

embedded.callback = function() {
	var query = {
		'action': 'query',
		'list': 'embeddedin',
		'eititle': wgPageName,
		'eilimit': 1
	}
	var wikipedia_api = new Wikipedia.api( 'Checking for embeddness', query, function( self ) {
		var xmlDoc = self.responseXML;
		var embedded = xmlDoc.evaluate( '//embeddedin/ei', xmlDoc, null, XPathResult.BOOLEAN_TYPE, null ).booleanValue;
		alert( embedded ? 'yes' : 'no' );
		});
	wikipedia_api.post();
}