Skip to content

Instantly share code, notes, and snippets.

@hyagni
Created November 30, 2010 11:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hyagni/721543 to your computer and use it in GitHub Desktop.
Save hyagni/721543 to your computer and use it in GitHub Desktop.
On amazon pages, copy to clipboard the bookinfo (ASIN, author, title, URL) with C-cC-p
key.setViewKey(['C-c', 'C-p'], function(ev){
var loc = getBrowser().contentDocument.URL;
var doc = frame = document.commandDispatcher.focusedWindow.document
|| gBrowser.contentWindow.document;
if(loc.match(/www\.amazon\./)){
asin = loc.split("/")[5];
r = doc.evaluate("//div[@class='buying']",doc,null,XPathResult.FIRST_ORDERED_NODE_TYPE, null);
list = r.singleNodeValue.textContent.split("\n");
var info = Array();
for(i=0; i<list.length; i++ ){
list[i] = list[i].trim();
if(list[i] != "")
info[info.length] = list[i];
}
var title = "";
a = info[0].split(' ');
for(i=0; i<a.length; i++){
if(a[i][0] != "[") title += a[i];
else break;
}
var output = info[1] + " \"" + title + "\" " + asin + "[[" + loc + "]]";
command.setClipboardText(output);
}
}, "Get book information", false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment