// ==UserScript==
// @name                Transaction ID to URL
// @version             1.1
// @date                2008-10-31
// @author              Ian Malpass ( ian AT etsyhacks DOT com )
// @namespace           etsy.com
// @description         Turns the text "Transaction ID# 12345" into a URL on the printer-friendly receipt page
// @include             http://www.etsy.com/receipt_print.php?order_id=*
// ==/UserScript==

/*
The printer-friendly receipt page includes the transaction number for each item, but not a URL that can be
read when the page is printed. This script changes the transaction ID into a URL.
*/

var tCells = getElementsByClassName( 'itemTransactionCell' );
for ( var t = 0; t < tCells.length; t++ ) {
    tCells[ t ].innerHTML = tCells[ t ].innerHTML.replace( 'Transaction ID# ', 'http://www.etsy.com/view_transaction.php?transaction_id=' );
}

function getElementsByClassName ( class, node ) {
    if ( node == null ) node = document;
    if ( node.getElementsByClassName ) {
        return node.getElementsByClassName( class );
    } else {
        var classElements = new Array();
        var els = node.getElementsByTagName( '*' );
        var elsLen = els.length;
        var pattern = new RegExp("(^|\\s)"+class+"(\\s|$)");
        for (i = 0, j = 0; i < elsLen; i++) {
            if ( pattern.test(els[i].className) ) {
                classElements[j] = els[i];
                j++;
            }
        }
        return classElements;
    }
}
