User:Killr833/gemw.js

// Wait for DOM to be ready $(document).ready(function {	/** Parse the parameters in a given template; from compare.js */	function parseTemplate(text, tpl) {		tpl = tpl.replace(/[_ ]/g, '[_ ]');		var re = new RegExp('', 'gi');

var data = []; var match;

while (match = re.exec(text)) { var params = match[2].split('|'); var j = 1; // Unnamed parameter index var tplData = new Array; for (var k in params) { var t = params[k].split('='); var name = null; var value = null; if (t.length == 1) { // Unnamed params name = (j++) + ''; // Cast to string value = t[0]; } else { name = t[0]; value = t[1]; }				tplData[$.trim(name)] = $.trim(value); }			data.push(tplData); }

return data; }

// Request the raw wikitext of a page. $.ajax({		data: {			'action': 'query',			'prop': 'revisions',			'titles': itemName, // This is the page that will be loaded			'rvprop': 'content',			'redirects': '',			'format': 'json'		},		dataType: 'json',		success: function(response) { // Call this function when the page is loaded			var pages = response.query.pages;			var pageId = null;

for (var i in pages) { pageId = pages[i].pageid; }

data = parseTemplate(pages[pageId].revisions[0]['*'], '');

alert(data[0][param]); // Do something with the parameter. },		url: wgScriptPath + '/api.php', timeout: 10000 // millisec }); });