MediaWiki:Gadget-cs.js: Difference between revisions

From Tardis Wiki, the free Doctor Who reference
No edit summary
No edit summary
Line 10: Line 10:
var api = new mw.Api();
var api = new mw.Api();
api.get(params).done(function(data) {
api.get(params).done(function(data) {
response = data.parse.text['*'];
response = $(data.parse.text['*']);
citationText = response;
citationText = $($(response).children()[0]).children()[0].innerHTML;
currentEl.innerHTML = citationText;
currentEl.innerHTML = citationText;
});
});
});
});
} );
} );

Revision as of 17:52, 9 April 2024

mw.hook( 'wikipage.content' ).add( function ( $content ) {
	$('.cs-l').each(function(){ /* 'this' means the element */
		/* adapted from https://www.mediawiki.org/wiki/API%3aParsing_wikitext#MediaWiki_JS under MIT license */
		var currentEl = this;
	    var params = {
			action: 'parse',
			text: '{{#invoke:cite source|generateCollapsibleTextFromJSON|' + $(currentEl).children(".cs-d")[0].innerHTML + ' }}',
			format: 'json'
		};
		var api = new mw.Api();
		api.get(params).done(function(data) {
			response = $(data.parse.text['*']);
			citationText = $($(response).children()[0]).children()[0].innerHTML;
			currentEl.innerHTML = citationText;
		});
	});
} );