Skip to content

Instantly share code, notes, and snippets.

@cmcavoy
Created February 2, 2011 17:34
Show Gist options
  • Save cmcavoy/808038 to your computer and use it in GitHub Desktop.
Save cmcavoy/808038 to your computer and use it in GitHub Desktop.
draft of a greasemonkey script to add cpl data to amazon
// ==UserScript==
// @name Amazon CPL
// @namespace http://www.lonelylion.com/
// @description Check for CPL books from Amazon
// @include http://www.amazon.com/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js
// ==/UserScript==
function addMenuItem(title, text) {
// adds a menu item to the product details on the amazon page
var m = jQuery('html body.dp div#divsinglecolumnminwidth.singlecolumnminwidth table tbody tr td.bucket div.content ul');
m.prepend("<li><b>"+title+"</b>: "+text+"</li>");
}
function addToTop(text) {
// lets you add text to the top of the Amazon page, mostly for debugging
var m = jQuery('#divsinglecolumnminwidth');
m.prepend(text);
}
function getISBN() {
var isbn = jQuery('html body.dp div#divsinglecolumnminwidth.singlecolumnminwidth table tbody tr td.bucket div.content ul li')[3].innerHTML;
isbn_regex = /\<b\>ISBN-10:\<\/b\>\s(\d+)/;
isbn = isbn_regex.exec(isbn)[1];
return isbn;
}
function loadNinjaData(isbn) {
var ninja = "http://chipubninja.com/branch_search.php?Ntt=" + isbn + "&formats=0&languages=0&audiences=0&ficnonfic=0&onshelfonly=1&showref=0&availability=1";
GM_xmlhttpRequest({
method: "GET",
url: ninja,
onload: function(response) {
var link_to_cpl = jQuery(response.responseText).find('a.whiteButton');
if (link_to_cpl.length > 0) {
addMenuItem('CPL', "<a target='_' href='"+link_to_cpl[1]+"'>Place on Hold</a>");
} else {
addMenuItem('CPL', "isbn "+isbn+" not available at CPL");
}
}
})
}
loadNinjaData(getISBN());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment