// ==UserScript==
// @name StockSum
// @namespace http://www.websterrf.com/SP
// @description Totals the current values of all stocks held in SpyBattle
// @include http://*spybattle.com/portfolio.php
//
// @author Matt McHugh
// @homepage http://www.mattmchugh.net/
// @version 1.1.4
// @copyright Matt McHugh, 2008
// ==/UserScript==
// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
// Check if jQuery's loaded
function GM_wait() {
if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
else { $ = unsafeWindow.jQuery; mainFunction(); }
}
GM_wait();
// Function to process stock information
function mainFunction()
{
var investment = 0, currentvalue = 0, gainloss;
var textcolor = "white";
var diffchar = "";
var appendStr = "";
$('img[title="Total"]').parent("b").parent("td").attr("nowrap","nowrap");
var $children = $('tr.contentcontent').children();
var i = 0;
while (i < $children.length)
{
var stockInvestment = parseFloat($children[i+2].innerHTML.replace('$','').replace(/,/g,'')) * parseInt($children[i+3].innerHTML.replace(/,/g,''));
var stockValue = parseFloat($children[i+4].innerHTML.replace('$','').replace(/,/g,''));
investment += stockInvestment;
currentvalue += stockValue;
if (stockValue < stockInvestment)
textcolor = "violet";
else if (stockValue > stockInvestment)
textcolor = "green";
else
textcolor = "white";
$children[i+4].style.color = textcolor;
if (textcolor == "green")
$children[i+4].innerHTML += "
(+ $" + addCommas(roundMoney(stockValue - stockInvestment).toString()) + ")";
else if (textcolor == "violet")
$children[i+4].innerHTML += "
(- $" + addCommas(roundMoney(stockInvestment - stockValue).toString()) + ")";
else
$children[i+4].innerHTML += "
(+/- $0)";
i += 6;
}
if (currentvalue < investment)
{
textcolor = "violet";
gainloss = "- $" + addCommas(roundMoney(investment - currentvalue).toString());
}
else if (currentvalue > investment)
{
textcolor = "green";
gainloss = "+ $" + addCommas(roundMoney(currentvalue - investment).toString());
}
else
gainloss = "+/- $0";
investment = addCommas(roundMoney(investment).toString());
currentvalue = addCommas(currentvalue.toString());
appendStr = "