All pastes #252278 Raw Edit

Anonymous

public text v1 · immutable
#252278 ·published 2006-11-19 08:38 UTC
rendered paste body
// ==UserScript==
// @name           MMG Stats Display
// @namespace      saldon's scripts
// @description    Displays MMG stats at the bottom of the MMG page.
// @include        http://*kingdomofloathing.com/bet.php*
// @include        http://127.0.0.1:*/bet.php*
// ==/UserScript==

var statDisplayBegin = "<center><table width=95% cellspacing=0 cellpadding=0>"
							+ "<tr><td style=\"color: white;\" align=center"
							+ " bgcolor=blue><b>MMG Statistics</b></td></tr>"
							+ "<tr><td style=\"padding: 5px; border: 1px solid "
							+ "blue;\"><table><tr><td><table><tr><td>";

var statDisplayEnd = "</td></tr></table></td></tr></table></td>"
						+ "</tr></table></center>";

// the stats variables to track
var betsTaken = GM_getValue("betsTaken", 0); // the number of bets the script has seen you take
var betsWon = GM_getValue("betsWon", 0); // how many of those bets were won
var betsLost = GM_getValue("betsLost", 0); // how many were lost
var betsLostAvg = GM_getValue("betsLostAvg", 0); // average size of bets lost
var betsWonAvg = GM_getValue("betsWonAvg", 0); // average size of bets won
var totalWon = GM_getValue("totalWon", 0); // total amount won
var totalLost = GM_getValue("totalLost", 0); // total lost (hopefully less than totalWon... unless you're me :\)

var currentBet = 0;
var currentWin = 0;

// length == 4 means the page is being loaded for the first time and no
// bet results will be present
var tables = document.getElementsByTagName("table");
if(tables.length != 4)
{
	var betSize = /You bet ((\d|,)*\d*) Meat\./;
	var winSize = /You gain ((\d|,)*\d*) Meat\./;
	//var reg = /You bet ((\d|,)*\d*) Meat\..*[You gain ((\d|,)*\d*) Meat\.]?/

	result = betSize.exec(document.body.innerHTML);
	if(result)
		currentBet = result[1].replace(/,/g, "");
	
	result = winSize.exec(document.body.innerHTML);
	if(result)
		currentWin = result[1].replace(/,/g, "");

	// now update all the stats if needed
	if(currentBet)
	{
		GM_setValue("betsTaken", ++betsTaken);
		
		if(currentWin) // we won the current bet
		{
			GM_setValue("betsWon", ++betsWon);
		
			totalWon += (parseInt(currentWin) - parseInt(currentBet));
			GM_setValue("totalWon", totalWon);	

			if(!betsWonAvg)
				betsWonAvg = parseInt(currentWin);
			else
				betsWonAvg = Math.floor(totalWon / betsWon);
		
			GM_setValue("betsWonAvg", betsWonAvg);
		}
		else // we lost it
		{
			GM_setValue("betsLost", ++betsLost);
			
			totalLost += parseInt(currentBet);
			GM_setValue("totalLost", totalLost);
			
			if(!betsLostAvg)
				betsLostAvg = parseInt(currentBet);
			else
				betsLostAvg = Math.floor(totalLost / betsLost);
		
			GM_setValue("betsLostAvg", betsLostAvg);
			

		}
	}
}

var frag = document.createDocumentFragment();
var div = document.createElement('div');

div.innerHTML = statDisplayBegin + "bet: " + currentBet + ", win: " + currentWin 
					+ "<br>betsTaken: " + betsTaken + "<br>betsWon: " + betsWon 
					+ ", betsLost: " + betsLost + "<br>betsWonAvg: " + betsWonAvg
					+ ", betsLostAvg: " + betsLostAvg + "<br>totalWon: " + totalWon
					+ ", totalLost: " + totalLost + statDisplayEnd;

frag.appendChild(div);
document.body.appendChild(frag);