Quote:
Originally Posted by davidfor
Firstly, this is shamelessy stolen from GreaseMonkey script to check Kindle prices in this forum.
Below is a Greasemonkey script for checking prices of books in the Kobo store. This looks at the link posted and adds the price after the link. If you are logged into you Kobo account, it will also show whether you already own the book.
I have been using this for a while and it works well. But, I mainly use the Australian shop. As far as I can tell, they are all the same, but there might be some differences. If you have any problems, please report them here and I will have a look at it.
To install: - Copy the script to the clipboad
- Go to the Greasemonkey user scripts in the Firefox addons.
- Click "New user script".
- On the next dialog, click "Use Script from clipboard".
- Click "Save" to save the script.
|
I have updated this script to work with the US Kobo ebookstore due to website changes.
I have not checked if it works with you library YMMV
Code:
// ==UserScript==
// @name MobileRead Kobo Price Check
// @namespace http://dunck.us/code/greasemonkey
// @description Checks price of Kobo US ebook links in MobileRead forum posts.
// @include (http|https)://www.mobileread.com/forums/show*.php*
// @version 1
// @grant GM_xmlhttpRequest
// @grant GM_log
// ==/UserScript==
// https://www.kobo.com/us/en/ebook/summoner-book-0-origins-the-prequel
var site_regex = /^(http|https):\/\/www.kobo.com\/.*\/*ebook\/.*/;
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 price = '';
var color = 'blue';
var data = response.responseText;
var pos0 = data.indexOf('span class="price" translate=no');
if (pos0 > 1) {
var pos1 = data.indexOf('>', pos0);
var pos2 = data.indexOf('<', pos1);
price = data.substring(pos1 + 1, pos2).trim();
}
else if (data.indexOf('>Free eBook<') > 0) {
price = 'Free';
color = 'red'
}
else if (data.indexOf('view-in-library') > 0) {
price = 'already own';
color = 'red'
}
if (price == '') {
price = 'N/A';
}
if (color == '') {
var color = 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) {
check_price(a[i], url);
}
}
bernie