Skip to content

Instantly share code, notes, and snippets.

@phette23
Last active December 15, 2015 06:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phette23/5215923 to your computer and use it in GitHub Desktop.
Save phette23/5215923 to your computer and use it in GitHub Desktop.
Bookmarklet to grab title, author, price, & URL from Amazon, ripe for pasting into a spreadsheet (e.g. Google Drive)
(function( $ ) {
var title, authors, price, url,
loc = document.location;
title = $( '#btAsinTitle' ).text().replace( /\s\[(Paperback|Hardcover|Bargain Price|Mass Market Paperback)\]/g, '' );
// authors' names, skip over role e.g. (editor)
if ( $( '.contributorNameTrigger' )[ 0 ] ) {
if ( $( '.contributorNameTrigger' ).length > 1 ) {
authors = $( '.contributorNameTrigger a' )[ 0 ].text();
for ( var i = 1; i < $( '.contributorNameTrigger' ).length; i++) {
authors += ', ' + $( '.contributorNameTrigger a' )[ i * 2 ].text();
}
} else authors = $( '.contributorNameTrigger a' ).text();
} else authors = $( '.buying .parseasinTitle ').next().text().replace( /( \(Introduction\))|( \(Foreword\))|( \(Editor\))|( \(Author\))|( \(Translator\))/ig, '' ).trim();
if ( $( '.priceLarge' ).length > 1 ) {
// NB: would use $( '.priceLarge' ).last() here
// but Amazon's jQuery is v. 1.2.6 which doesn't support $().last()
price = $( '.priceLarge' ).eq( $( '.priceLarge' ).length - 1 ).text();
} else price = $( '.priceLarge' ).text();
// leave off query string by combining domain & path
url = loc.origin + loc.pathname;
// easiest way to push text into clipboard right now
prompt( "Press Ctrl+C to copy & then Enter to close this dialog.", title + '\t' + authors + '\t' + price + '\t' + url );
} ( jQuery ));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment