I have written a script for GreaseMonkey (a FireFox addon) to check the prices of Kindle ebooks linked in MobileRead forum posts. Once installed, any links to a Kindle ebook will have the price displayed after then. Prices are coloured red for free and blue otherwise.
Currently the script only works in FireFox with GreaseMonkey installed. Even though Google Chrome can use some GreaseMonkey scripts, it can't use this one. I should be able to make it work as a proper Chrome extension, just ask and i will.
The script is set up to check amazon.com links. It can check amazon.co.uk links, just change the appropriate line at the top. Adding of additional Amazon countries should be easy enough. It should even be possible to add other ebook stores, eg Kobo or B&N.
To install the script, go to
http://userscripts.org/scripts/show/138544 or copy out the code below.
Code:
// ==UserScript==
// @name MobileRead Kindle Price Check
// @namespace kakapo.public
// @description Checks price of Kindle ebook links in MobileRead forum posts
// @include https://www.mobileread.com/forums/showthread.php*
// @version 1
// ==/UserScript==
// change com in line below to co.uk for Amazon UK
var site_regex = /^(http|https):\/\/(www\.)?amazon\.(com)(\/.*)/;
var ebook_url_regexs = [
/^\/dp\//,
/^\/[^\/]+\/dp\//,
/^\/gp\/product\//
];
var check_price = function(element, url) {
var xhr = GM_xmlhttpRequest({
method: 'GET',
url: url,
onload: function(response) {
var data = response.responseText;
var pos0 = data.indexOf('class="priceLarge"');
var pos1 = data.indexOf('>', pos0);
var pos2 = data.indexOf('<', pos1);
var price = data.substring(pos1 + 1, pos2).trim();
if (price == '') {
price = 'N/A';
}
var color = price == 'Free' || price == '$0.00' || price == '£0.00' ? 'red' : 'blue';
element.insertAdjacentHTML('afterend', ' <span style="color:'+color+'">('+price+')</span>');
}
});
}
var a = document.getElementsByTagName('a');
for (var i = 0; i < a.length; i++) {
var url = a[i].href;
var parts = site_regex.exec(url);
if (parts) {
for (var j = 0; j < ebook_url_regexs.length; j++) {
if (ebook_url_regexs[j].test(parts[parts.length-1])) {
check_price(a[i], url);
}
}
}
}