O'Reilly logo

Greasemonkey Hacks by Mark Pilgrim

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #94. Compare Book Prices

Add competitors' prices to online book retailers.

When the Web was new, pundits and trade magazines hyped the possibility of agents that followed you around online and fetched the lowest prices, or recommended similar sites, or made your coffee, or something. The hype died down quickly, but many of the best ideas have eventually resurfaced in one form or another. It turns out that most people don't actually care about some bureaucrat's idea of "similar sites," but everybody cares about finding the lowest prices.

This hack adds a floating window to online bookstores, such as Amazon. com, that shows you the price for the same book on other sites. Really.

The Code

This user script runs on several online book stores:

  • Amazon.com

  • BarnesAndNoble.com

  • Powells.com

  • Half.com

  • Buy.com

The script parses the ISBN—a globally unique identifier for the book you're viewing—and uses it to fetch pricing information from other sites. Sites like Amazon.com provide an official web services API for getting this information; for other sites, the script relies on tried-and-true techniques of screen scraping.

Tip

By default, this script adds associate IDs to the links it constructs, which gives the script's author a small referral fee. If you dislike this, or you have your own associate ID, you can change the first few lines of code to define your own IDs or remove them altogether.

Save the following user script as bookburro.user.js:

 // ==UserScript== // @name Book Burro - Remixing the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required