View Single Post
Old 09-18-2015, 11:37 PM   #1
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 24,905
Karma: 47303824
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo:Touch,Glo, AuraH2O, GloHD,AuraONE, ClaraHD, Libra H2O; tolinoepos
GreaseMonkey script to check Kobo prices in this forum

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:
  1. Copy the script to the clipboad
  2. Go to the Greasemonkey user scripts in the Firefox addons.
  3. Click "New user script".
  4. On the next dialog, click "Use Script from clipboard".
  5. Click "Save" to save the script.

Code:
// ==UserScript==
// @name        MobileRead Kobo Price Check
// @namespace   http://dunck.us/code/greasemonkey
// @description Checks price of Kindle ebook links in MobileRead forum posts.
// @include     https://www.mobileread.com/forums/show*.php*
// @version     1
// @grant       GM_xmlhttpRequest
// @grant       GM_log
// ==/UserScript==
// https://store.kobobooks.com/en-GB/ebook/summoner-book-0-origins-the-prequel
var site_regex = /^(http|https):\/\/store.kobobooks.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('class="right inline-price"');
      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);
  }
}
davidfor is offline   Reply With Quote