This is a simple Greasemonkey script that looks for links to items (books, VHS tapes, or DVDs) at Amazon, like this:
Ursula K. Le Guin’s Left Hand of Darkness
Cool Hand Luke
and adds links to look up those items on Melvyl (the combined UC libraries catalog), like this:
Ursula K. Le Guin’s Left Hand of Darkness
Cool Hand Luke
This requires the Greasemonkey Firefox extension, version 0.2.6 or higher. Once you have installed Greasemonkey, right-click on the link below and select “Install User Script…” from the context menu:
amazon2melvyl Greasemonkey user script
Note to UC Berkeley users:
If, after you install amazon2melvyl, you see red Melvyl icons like this rather than blue ones like this
, it means that amazon2melvyl cannot get past the UCB Library Proxy Server to reach the xISBN service (used for finding all ISBNs associated with an item, including other editions, etc). The lookup on Melvyl will still work, but may not find a match since it will use only the original ISBN and not all related ISBNs. To remedy this, simply log in to the UCB Library Proxy Server by visiting a page such as this one. After you do so your icons will turn blue, and everything will be cool.
amazon2melvyl is a web intermediary, and as such its workings are best explained in terms of Leigh Dodds’ patterns of intermediation. These patterns lie along three orthogonal axes:
Trigger: How does the intermediary get invoked? amazon2melvyl is invoked whenever any web page is loaded into the browser, so it follows the Event Driven pattern. Technically, Greasemonkey user scripts like amazon2melvyl are injected into the document after the DOM is fully loaded, but before the “onload” event actually occurs.
Data Source: Where does the intermediary find the data that it acts upon? In this case, there are two data sources: links in the page that point to item details pages at Amazon, and the OCLC’s xISBN service. Thus amazon2melvyl follows the Link Scanner and Service Invoker patterns. Links in the document are found by using Firefox’s support for XPath queries. amazon2melvyl then iterates through the found links and uses a regular expression to find URLs that contain the telltale Amazon /exec/obidos/ASIN or /exec/obidos/tg/detail/-/ strings. If there is a match, the amazon2melvyl extracts the ISBN from the URL and (using Greasemonkey’s XMLHTTPRequest support) asynchronously passes it to the xISBN service, which then returns an XML document containing the whole set of ISBNs for all editions of that item.
Action Taken: Now that all the necessary data has been obtained, what does the intermediary do with the data? amazon2melvyl adds links to the page, thus following the Link Dropper pattern. In this case, the complete set of ISBNs from the xISBN service is used to build a (sometimes quite long) URL for a lookup in the Melvyl catalog, according to the specifications for linking to Melvyl holdings. Finally, an icon linked to this URL is inserted into the page directly after the Amazon link.
Update (March 1, 2005): Fixed to handle ISBNs of the form 123456789X (check digit is X), and relative links on the Amazon site itself.
Update (April 1. 2005): Now uses the OCLC’s xISBN service to find all ISBNs associated with the the linked item, for a better chance of a successful lookup on Melvyl. Thanks to Jeremy Dunck for the suggestion. Also uses a data: URI for the icons, to save my bandwidth. Thanks to Phil Ringnalda for that suggestion.
Update (June 1, 2005): Tweaked Amazon link matching logic to better handle affiliate links.