Amazon Price Plus Postage

Grrr, Amazon is really annoying. When trying to compare prices, its very difficult, because one company can charge vastly different postage to another. Also, Amazon deliberately make the price bold and red, and the postage small and gray.

Here's my solution : Put the total price at the top, in bold and red.

Code

// ==UserScript==
// @name           Amazon Price Plus Postage
// @namespace      nickthecoder
// @description    Puts the total price in bold red about the price and postage costs.
// @include        http://amazon.co.uk/*
// ==/UserScript==

// Please change the version number before each modification.
var version = "1.01";

// Add stubs for logging if firebug isn't enabled on this browser
if ( ! console ) {
  console = new Object();
  var doNothing = function() {};
  console.debug = console.info = console.log = doNothing;
}
console.debug( "begin greasemonkey script amazon_preice_plus_postage" );


// Now lets do the biz...
var buyBox = document.getElementById( "buyboxDivId" );

if ( buyBox != null ) {

    var boldTags = buyBox.getElementsByTagName( "b" );
    var spanTags = buyBox.getElementsByTagName( "span" );
    var priceTag = null;
    var postageTag = null;

    for ( var i = 0; i < boldTags.length; i ++ ) {
        if ( boldTags[ i ].className == "price" ) {
            priceTag = boldTags[ i ];
        }
    }
    for ( var i = 0; i < spanTags.length; i ++ ) {
        if ( spanTags[ i ].className == "plusShippingText" ) {
            postageTag = spanTags[ i ];
        }
    }

    console.debug( "priceTag", priceTag, "postageTag", postageTag );

    if ( (priceTag != null) && (postageTag != null) ) {

        var price = priceTag.innerHTML.match( /([^0123456789.]*)([0123456789.]*)/ )[2];
        var postage = postageTag.innerHTML.match( /([^0123456789.]*)([0123456789.]*)/ )[2];

        console.debug( "price", price, "postage", postage );

        var html = '<b class="price">';
        html += "&pound;" + ( parseFloat( price ) + parseFloat( postage ) ) + " in total";
        html += "</b>";
        html += ' <a title="about this greasemonkey addition (version ' + version + ' )" href="http://nickthecoder.co.uk/pinkwino/view/Amazon+Price+Plus+Postage">(ntc)</a>';

        console.debug( "adding : ", html );

        var newDiv = document.createElement("div");
        newDiv.innerHTML = html;
        priceTag.parentNode.insertBefore( newDiv, priceTag );

    } else {
        console.debug( "This page doesn't have price and postage - nothing to do" );
    }
} else {
    console.debug( "This page doesn't have a price box - nothing to do" );
}

console.debug( "end greasemonkey script amazon_preice_plus_postage" );

Version History

1.00

Initial version

1.01

Added a link to this page, plus embedded a version number in the <a> tag, which makes it easy to see if you are running the latest version.

1.02

Added debugging info using Firebug.