Klipfolio Inc.
Copyright © 2002-2009 Klipfolio Inc.
info@klipfolio.com
http://www.klipfolio.com
Stock Tracker
extXYg5KT2/14wHqbWjr/BE1pfvPVXXyhmyjdskLENO4QfwPvVZRDuT2enQthooyQKXJbEdnvYfjVt0+fBGdteMINJskAk+DPywE+FlFz0Zhi73mL0ARYuz4dAqjhO35w+6jq8pieGfKMkQtK8iSa32G4R2IcPgCVZTKHSsCYN4=
4.1
serstock031510
2008.12.09
This Klip displays any stock quotes you want, in addition to Dow, Nasdaq and S&P 500 market summaries.
stock tracker ticker portfolio
http://finance.yahoo.com/?u
http://finance.yahoo.com
http://www.serence.com/serence_klips/pics/stock/st5_icon.png
http://www.serence.com/serence_klips/pics/stock_track_banner.gif
http://www.serence.com/serence_klips/StockTracker.klip
15
--
--
true
5899
true
ShortName
true
Loading stock information...
http://www.serence.com/serence_klips/pics/stock/stock_up.png
http://www.serence.com/serence_klips/pics/stock/stock_down.png
http://www.serence.com/serence_klips/pics/stock/stock_nochg.png
0;
]]>
" + value + "" + tag + ">\r\n";
}
function parseDetails(data, record)
{
var rx4 = new RegExp('head1.*?>([^]*?)\\:[^]*?data1.*?>([^]*?)', 'g');
// The first field name on Yahoo differs between "Last Trade", "Index Value" and "Net Asset Value",
// depending on which kind of symbol is queried. I map all of those fields to the "Value" field.
var fieldName = "Value";
var fieldValue = "";
var detail;
while (detail = rx4.exec(data))
{
if (fieldName == "")
{
fieldName = Klip.stripTags(detail[1]);
fieldName = Klip.processEntities(fieldName);
fieldName = fieldName.replace(/(?:\W|^\d+)/g, "");
}
if (fieldList.indexOf(fieldName) >= 0)
{
fieldValue = Klip.stripTags(detail[2]);
fieldValue = Klip.processEntities(fieldValue);
fieldValue = fieldValue.replace(/(?:^\s+|\s+$)/g, "");
record[fieldName] = fieldValue;
}
fieldName = "";
}
return record;
}
function parseData(data)
{
var names;
var match;
var trend;
var rx2a = new RegExp('(.*?).*?\\((.*?):(.*?)\\)');
var rx2b = new RegExp('Change:<[^]*?\\.gif"\\s+alt="(.*?)"');
var rx2c = new RegExp(']*?src="([^"]*?)" width="192" height="96"');
names = rx2a.exec(data);
if ((!names) || (names.length != 4))
{
trace("Stocktracker ===\r\nWARNING: Some values missing on result page!\r\n----------------\r\n");
return "";
}
trend = "";
match = rx2b.exec(data);
if (match)
{
trend = match[1].toLowerCase();
}
if ((trend != "down") && (trend != "up"))
{
trend = "nochg";
}
record = new Object();
record.Trend = trend;
record.url = "http://finance.yahoo.com/q?s="+names[3];
record.Symbol = names[3];
record.isIndex = (names[3][0] == "^");
if (record.isIndex)
{
var len = names[1].indexOf(" ");
if (len >= 0)
{
record.ShortName = names[1].substring(0, len);
}
else
{
record.ShortName = names[1];
}
}
else
{
record.ShortName = names[3];
}
record.Name = names[1] + " ("+names[2]+")";
match = rx2c.exec(data);
if (match)
{
record.Chart = match[1];
}
else
{
record.Chart = chartBase + "t?s=" + names[3];
}
record.ThumbChart = chartBase + "h?s=" + names[3];
record.Indicator = iconBase + "stock_" + record.Trend + ".png";
record = parseDetails(data, record);
var changeMatch = record.Change.match(/\d+\.\d+/g);
if (changeMatch && (changeMatch.length == 2))
{
record.NetChange = changeMatch[0]-0;
record.RelChange = changeMatch[1]-0;
}
else
{
record.NetChange = 0;
record.RelChange = 0;
}
if (record.Trend == "down")
{
record.NetChange = record.NetChange * -1;
record.RelChange = record.RelChange * -1;
}
record.ChangeValue = 0;
record.ChangePercent = 0;
return record;
}
var net_change;
function processData(record)
{
var result = "- ";
for (var prop in record)
{
result += newElement(prop, record[prop]);
}
result += "
\r\n";
return result;
}
function checkItem(item)
{
var changeTxt = item.getData("Change").split("(");
var indicator = item.getData("Indicator");
var change = "";
if(indicator.indexOf("stock_up") != -1)
{
change = changeTxt[0] + "(+" + changeTxt[1];
}
else if(indicator.indexOf("stock_down") != -1)
{
change = changeTxt[0] + "(-" + changeTxt[1];
}
else
{
change = changeTxt[0] + "(" + changeTxt[1];
}
item.setData("Change", change);
var changeValues = change.split(" ");
var valueChange = changeValues[0];
var percentChange = changeValues[1];
percentChange = percentChange.slice(1, percentChange.indexOf("%"));
if(Number(percentChange) < 0)
{
valueChange = "-" + valueChange;
}
item.setData("ChangeValue", valueChange);
item.setData("ChangePercent", percentChange);
item.canvisit = false;
item.candelete = false;
return true;
}
function itemCreate(newItem)
{
return checkItem(newItem);
}
function itemUpdate(oldItem, parameters)
{
return checkItem(parameters);
}
function onRefresh ()
{
var rx1 = new RegExp('', 'g');
var summary;
var data;
var record;
var food;
var success = false;
var symbolList;
var req;
Items.autoremove = false;
Items.purge(true);
savePrefs ();
symbolList = getSymbolList();
var multiple = (symbolList.split(",").length > 1);
Prefs.defaultlink = "http://finance.yahoo.com/q?s=" + symbolList + "&d=s";
if (symbolList != ",")
{
req = Engines.HTTP.newRequest ("http://finance.yahoo.com/q?s=^DJI" + symbolList + "&d=s");
// The symbol list must have at least 2 symbols to get the format we want.
// If the user has selected DJI as one of the symbols, don't ignore it.
// If the user has selected only DJI, then add a second symbol to the request.
// Otherwise, ignore the first record (which is DJI).
var stripFirst = true;
if (dji.checked)
{
if(symbolList == ",,^DJI")
{
req.url = "http://finance.yahoo.com/q?s=NT,^DJI&d=s";
}
else
{
stripFirst = false;
}
}
if (req.send ())
{
data = req.response.data;
net_change = 0;
food = "";
while (summary = rx1.exec(data))
{
if(stripFirst)
{
stripFirst = false;
continue;
}
record = parseData(summary[1]);
if (record)
{
net_change += record.NetChange;
food += processData(record);
}
}
if (food.length > 0)
{
Engines.KlipFood.onCreate = itemCreate;
Engines.KlipFood.onUpdate = itemUpdate;
success = Engines.KlipFood.process(food);
}
if (net_change > 0)
{
Items.B = iconBase + "st5_up" + (multiple?"_pf":"_single") + ".png";
Items.altB = (multiple?"Net Gain":"Gain");
}
else if (net_change < 0)
{
Items.B = iconBase + "st5_down" + (multiple?"_pf":"_single") + ".png";
Items.altB = (multiple?"Net Loss":"Loss");
}
else
{
Items.B = iconBase + "st5_stable" + (multiple?"_pf":"_single") + ".png";
Items.altB = (multiple?"No Net Change":"Unchanged");
}
}
}
else
{
Items.B = iconBase + "st5_stable" + (multiple?"_pf":"_single") + ".png";
Items.altB = (multiple?"No Net Change":"Unchanged");
Items.clear(true);
success = true;
}
return success;
}
]]>