View Single Post
Old 07-12-2012, 01:21 PM   #6
eckyecky
Junior Member
eckyecky began at the beginning.
 
Posts: 1
Karma: 10
Join Date: Jul 2012
Device: Kindle Keyboard
Greasemonkey script It makes finding free books really easy. (Sets height of result div to 0px for non-free books.) credits to kakapo
Code:
// ==UserScript==
// @name        Amazon Free Books
// @namespace   ecky.public
// @include     http://www.amazon.com/*
// @version     1
// ==/UserScript==

function runClear() {     
  unsafeWindow.amznJQ.jQuery('.zg_availability').each(function() {
    if (unsafeWindow.amznJQ.jQuery(this).html().trim() == 'Currently unavailable') {
      unsafeWindow.amznJQ.jQuery(this).parent().parent().css('opacity', 0.2);
      unsafeWindow.amznJQ.jQuery(this).parent().parent().css('height', 0);
    }
  });
  unsafeWindow.amznJQ.jQuery('.price').each(function() {
    var url = unsafeWindow.amznJQ.jQuery(this).parent().parent().find('a').attr('href').trim();
    var price = unsafeWindow.amznJQ.jQuery(this).html().trim();
    if (price == 'Free' || price == '$0.00') { 
      (function(price_node, old_price, url) {
        unsafeWindow.amznJQ.jQuery.get(url, {}, function (data, textStatus) {
          var pos0 = data.indexOf('class="priceLarge"');
          var pos1 = data.indexOf('>', pos0);
          var pos2 = data.indexOf('<', pos1);
          var new_price = data.substring(pos1 + 1, pos2).trim();
          unsafeWindow.amznJQ.jQuery(price_node).after(' actual:' + new_price);
          if (new_price != '$0.00') {
            unsafeWindow.amznJQ.jQuery(price_node).parent().parent().parent().css('opacity', 0.2);
            unsafeWindow.amznJQ.jQuery(price_node).parent().parent().parent().css('height', 0);
          }
        }, 'text');
      })(this, price, url);
    } else {
      unsafeWindow.amznJQ.jQuery(this).parent().parent().parent().css('opacity', 0.2);
      unsafeWindow.amznJQ.jQuery(this).parent().parent().parent().css('height', 0);
      unsafeWindow.amznJQ.jQuery(this).parent().parent().parent().css('overflow', 'hidden');
    }
  });
  
}
document.addEventListener('click',function (){setTimeout(runClear,3000)},true);
runClear();
eckyecky is offline   Reply With Quote