// Yahoo! Finance user script to make link to transactions
// $Revision: 1.6 $
// $Date: 2005/09/09 14:10:14 $
// Copyright (c) 2005, Brian St. Pierre
//
// Permission to use, copy, modify, and distribute this software and its
// documentation for any purpose, without fee, and without a written agreement
// is hereby granted, provided that the above copyright notice and this
// paragraph and the following two paragraphs appear in all copies.
//
// IN NO EVENT SHALL THE AUTHOR BE LIABLE TO ANY PARTY FOR DIRECT,
// INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
// PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
// EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// THE AUTHOR SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
// PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS"
// BASIS, AND THE AUTHOR HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE,
// SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          YahooFinanceShowTransactions
// @namespace     http://bstpierre.org/Projects/greasemonkey/yahoofinance.user.js
// @description   Script to create a "show transactions" link on portfolio pages
// @include       http://finance.yahoo.com/p?*
// ==/UserScript==

window.replaceLinks = function() {
    var newBody = document.body.innerHTML;
    var pfKey = window.location.href.match(/k=tpf_([^-]*-+)/)[1];
    var now = new Date();
    var year = (1900 + now.getYear());
    var month = now.getMonth();
    var monthday = now.getDate();

    newBody = newBody.replace(/<a[^>]*q?s=([A-Z]+).*>\1<\/a>/g, '<a href="/q?s=$1&d=t">$1</a> <a href="http://edit.finance.dcn.yahoo.com/xa?.filter=1&.portkey=tpf_' + pfKey + '&.acctid=' + pfKey + '&.intl=us&k=tpf_' + pfKey + '&fm=11&fd=19&fy=2000&tm=' + month + '&td=' + monthday + '&ty=' + year + '&a=1&a=5&a=3&a=6&a=2&a=7&a=4&a=8&a=9&a=10&a=14&a=15&a=13&a=16&a=11&a=12&.symbol=$1">(t)</a>');

    document.body.innerHTML = newBody;
};

window.addEventListener(
    'load',
    window.replaceLinks,
    true);
