// ==UserScript==
// @name                Printer-friendly linker
// @version             1.1
// @date                2010-04-16
// @author              Ian Malpass ( ian AT etsyhacks DOT com )
// @namespace           etsy.com
// @description         Adds a link to the printer-friendly receipt to each order on the orders page
// @include             http://www.etsy.com/your/listings/sold*
// ==/UserScript==

var anchors = document.getElementsByTagName( 'a' ); // get all the links

// go in reverse order, so that new links don't throw us off
for ( var a = anchors.length - 1; a >= 0; a-- ) {
    if ( anchors[ a ].href.match( 'receipt.php' ) ) {
        var anchor = anchors[ a ];
        var print = anchor.cloneNode( true );
        anchor.parentNode.appendChild( document.createElement( 'br' ) );
        anchor.parentNode.appendChild( print );
        print.innerHTML = 'Print';
        print.href = print.href.replace( 'receipt.php', 'receipt_print.php' );
    }
}

