nickchild / FPL get player info

// ==UserScript==
// @name        FPL get player info
// @namespace   nickchild
// @include     http://fantasy.premierleague.com/entry*
// @include     http://fantasy.premierleague.com/my-team*
// @version     1.4.3
// @grant       none
// ==/UserScript==

function stateChanged()
{ 
	if (this.readyState==4)
	{
		retval = this.responseText;
		eval('playerInfo = ' +retval);
		playerid = playerInfo["id"];
		fixlen = playerInfo["fixture_history"]["all"].length;
		homePlayed = 0;
		homePoints = 0;
		awayPlayed = 0;
		awayPoints = 0;
		totalGames = 0;
		totalMins = 0;
		totalScore = 0;
		for(i=0; i<fixlen; i++) {
			fixname = playerInfo["fixture_history"]["all"][i][2];
			arr1 = fixname.split('(');
			arr2 = arr1[1].split(')');
			loc = arr2[0];
			minsplayed = playerInfo["fixture_history"]["all"][i][3];
			totalMins = totalMins + minsplayed;
			points = playerInfo["fixture_history"]["all"][i][19];
			totalScore = totalScore + points;
			if(loc == "H") {
				if(minsplayed > 0) {
					totalGames++;
					homePlayed++;
					homePoints = homePoints + points;
				}
			} else {
				if(minsplayed > 0) {
					totalGames++;
					awayPlayed++;
					awayPoints = awayPoints + points;
				}
			}
		}
		homeAve = homePoints / homePlayed;
		if(homePlayed > 0) {
			homeAve = homeAve.toFixed(2);
		} else {
			homeAve = "-";
		}
		awayAve = awayPoints / awayPlayed;
		if(awayPlayed > 0) {
			awayAve = awayAve.toFixed(2);
		} else {
			awayAve = "-";
		}
		pp90 = (totalScore / totalMins)*90;
		if(totalMins > 0) {
			pp90 = pp90.toFixed(2);
		} else {
			pp90 = "-";
		}
		ppg = totalScore / totalGames;
		if(totalGames > 0) {
			ppg = ppg.toFixed(2);
		} else {
			ppg = "-";
		}
		
		playerrow = document.getElementById("ismData"+playerid);
		playerrow.innerHTML = playerrow.innerHTML + "<td>" + ppg + "</td><td>" + pp90 + "</td><td>" + homeAve + "</td><td>" + awayAve + "</td>";

	}
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
	    {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e)
	    {
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	  }
	return xmlHttp;
}

playerTable = document.getElementById("ismTeamDisplayData");
trs = playerTable.getElementsByTagName("tr");
trs[0].innerHTML = trs[0].innerHTML + "<th><abbr title='Points per game'>PPG</abbr></th><th><abbr title='Points per 90 minutes'>PP90</abbr></th><th><abbr title='Points per home game'>PPH</abbr></th><th><abbr title='Points per away game'>PPA</abbr></th>";
for(i=0; i<trs.length; i++) {
	rowid = trs[i].id;
	arr1 = rowid.split("Data");
	playerid = arr1[1];
	url = "http://fantasy.premierleague.com/web/api/elements/"+playerid+"/";
	var xmlHttp=GetXmlHttpObject();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}
	
//	document.getElementById("body").style.width = "1180px";
	document.getElementById("ism").style.width = "950px";
	if(document.getElementById("ismTeamDisplayGraphical")) {
		document.getElementById("ismTeamDisplayGraphical").style.width = "490px";
		document.getElementById("ismTeamDisplayGraphical").style.paddingLeft = "100px";
	}
	var cols = document.getElementsByClassName('ismPrimaryNarrow');
	for(i=0; i<cols.length; i++) {
		cols[i].style.width = '690px';
	}
	var cols = document.getElementsByClassName('ismWrapper');
	for(i=0; i<cols.length; i++) {
		cols[i].style.width = '1140px';
	}