lpbrh

By pabst Last update Dec 22, 2008 — Installed 26,951 times. Daily Installs: 7, 13, 14, 15, 7, 7, 5, 3, 11, 4, 8, 7, 7, 1, 10, 4, 8, 5, 6, 15, 5, 5, 8, 7, 4, 3, 2, 3, 4, 5, 1

There are 6 previous versions of this script.

// ==UserScript==
// @name           pbr Highlight
// @description    Provides automatic highlighting of players in replays, play-by-plays, & on the league leaders lists.
// @namespace      pbr
// @include        http://goallineblitz.com/game/replay.pl?game_id=*&pbp_id=*
// @include        http://goallineblitz.com/game/home.pl
// @include        http://goallineblitz.com/game/game.pl?game_id=*&mode=pbp*
// @include        http://goallineblitz.com/game/league.pl?league_id=*
// @include        http://goallineblitz.com/game/stats.pl?*
// @include        http://goallineblitz.com/game/team.pl?*
// @version        08.12.22
// @require        http://userscripts.org/scripts/source/31567.user.js
// ==/UserScript==

/* 
 * 
 * pabst did this 08/06/26+
 *
 * 
 */

window.setTimeout( function() {
	pbr_replay_highlight_main();
}, 100);


function getColor(idx) {			
	var color;
	var b = "00"+(idx%8).toString(2);
	b = b.slice(b.length-3);

	var color = "#";
	for each (ch in b) {
		if (ch == "0") {
			color += "00";
		}
		else {
			color += "D0";
		}
	}
	return color;
}

function Player() {
	this.id = -1;
	this.name = "unnamed";

	this.toString = function() {
		return this.id+" - '"+this.name+"'";
	};
}


function readCookieDate() {
	var data = getCookie(cookieName);
	if (data == null) {
		return null;
	}

	var str = data.slice(0,data.indexOf("\t"));
	var date = new Date(str);
	return date;
}

function readCookieData() {
	var data = getCookie(cookieName);
	if (data == null) {
		return null;
	}

	var str = data.split("\t");
	var arr = new Array();
	for (var i=1; i<str.length; i+=2) {
		var p = new Player();
		p.id = parseFloat(str[i]);
		p.name = str[i+1];
		arr.push(p);
	}
	return arr;
}

function writeCookie(arr) {
	var d = new Date();
	var data = d;
	for each (p in arr) {
		data += "\t" + p;
	}
	data += ";";
	setCookie(cookieName,data);
}

function parsePlayers(address, page) {
    var text = page.responseText;
    parsePage(text);
}
function parsePage(text) {
	var searchString = "/game/player.pl?player_id=";
	var sslen = searchString.length;
	var playerArray = [];

	while (text.indexOf(searchString) != -1) {
		var start = text.indexOf(searchString)+sslen;
		text = text.slice(start);

		var end = text.indexOf('"');
		var t = text.slice(0,end);

		text = text.slice(end+2);
		end = text.indexOf("</a>");
		var name = text.slice(text.indexOf(">")+1,end);

		playerArray.push(parseInt(t));
		playerArray.push(name);

		text = text.slice(end);
	}

	//console.log("writing cookie : "+playerArray);
	writeCookie(playerArray);
}


var cookieName;
var myPlayers;
var cookieDate;
var cookieData;

function pbr_replay_highlight_main() {
	cookieName = "glb-greasemonkey: player list";
	cookieDate = readCookieDate(cookieName);
	cookieData = readCookieData(cookieName);
	myPlayers = null;
	
	var currentDate = new Date();
	var inetAddress = window.location+"";

	//console.log("DATE="+cookieDate);
	//console.log("CD="+cookieData);
	if ((window.location+"").indexOf("home.pl") == -1) {
		if ((cookieData == null) || (currentDate > cookieDate + 1000*60*60*6)) {
			getInetPage("http://goallineblitz.com/game/home.pl", parsePlayers);
			myPlayers = [];
		}
		else {
			myPlayers = cookieData;
		}
	}
	
	if (inetAddress.match("replay.pl") != null) {
		// ----- on a replay page --------	
		for (var i=0; i<myPlayers.length; i++) {
			var p = myPlayers[i].id;
			if (document.getElementById(p+"")) {
				var color = getColor(i);
				document.getElementById(p+"").style.backgroundColor = color;
				for each (var l in document.links) {
					if (l.href.match("player_id="+p) != null) {
						l.setAttribute("style","color:"+color+";font-weight:bold");
//document.getElementById(p+"").innerHTML = '<img src="http://www.maploco.com/maps/dots/red-circle.png">';
					}
				}
			}
		}
	}
	else if (inetAddress.match("game.pl") != null) {
		// ------- on a pbp page ----------
		var pbpTable = document.getElementById("play_by_play_table");
		var pages = pbpTable.rows.length;
		for each (htmlTableRowElement in pbpTable.rows) {
			var className = htmlTableRowElement.className;
			if (className == null) continue;
	
			if (className.match("pbp_play_row") != null) {
				var coll = htmlTableRowElement.cells;
				for each (node in coll) {
					var cName = node.className;
					if (cName.match("pbp_play") != null) {
						var playText = node.firstChild.data;
						if (playText.match("penalty committed by") != null) {
							node.parentNode.setAttribute("style","color:orange;font-weight:bold");
						}
						for each (p in cookieData) {
							var name = p.name;
							if ((playText.match(p.name) != null) &&
									(playText.indexOf(p.name+" pitch to") != 0)) {
								node.parentNode.setAttribute("style","color:green;font-weight:bold");
							}
						}
					}
				}
			}
		}
	}
	else if ((inetAddress.match("league.pl") != null) ||
			(inetAddress.match("stats.pl") != null) ||
			(inetAddress.match("team.pl") != null)) {
		// ------- on a stats page or team home page--------
		for each (var l in document.links) {
			for each (var p in myPlayers) {
				if (l.href.match("player_id="+p.id) != null) {
					l.setAttribute("style","color:green;font-weight:bold");
				}
			}
		}
	}
	else {
		// -------- on the home page ---------
		parsePage(document.getElementById("players").innerHTML);
	}
}