User:Killr833/getattack.js

/* *

$(document).ready(function {	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; var tplData = new Array; for (var k in params) { var t = params[k].split('='); var name = null; var value = null; if (t.length == 1) { name = (j++) + ''; value = t[0]; } else { name = t[0]; value = t[1]; }				tplData[$.trim(name)] = $.trim(value); }			data.push(tplData); }

return data; }

var n = YAHOO.util.Dom.getElementsByClassName('attack', 'span', document.getElementById('bodyContent')); $.ajax({		data: {			'action': 'query',			'prop': 'revisions',			'titles': n,			'rvprop': 'content',			'redirects': '',			'format': 'json'		},		dataType: 'json',		success: function(response) {			var pages = response.query.pages;			var pageId = null;

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

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

for ( var x in n ) { n[x].innerHTML = (data[0]['attack']); }		},		url: wgScriptPath + '/api.php', timeout: 10000 }); });