// ==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 = "
" + "" + "" + "
MMG Statistics
"; var statDisplayEnd = "
"; // 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 + "
betsTaken: " + betsTaken + "
betsWon: " + betsWon + ", betsLost: " + betsLost + "
betsWonAvg: " + betsWonAvg + ", betsLostAvg: " + betsLostAvg + "
totalWon: " + totalWon + ", totalLost: " + totalLost + statDisplayEnd; frag.appendChild(div); document.body.appendChild(frag);