Skip to content

Instantly share code, notes, and snippets.

@rondevera
Forked from nathos/amznshortener.js
Created October 23, 2011 06:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rondevera/1306958 to your computer and use it in GitHub Desktop.
Save rondevera/1306958 to your computer and use it in GitHub Desktop.
Amazon short URL bookmarklet
(function(d){
var asin = d.getElementById('ASIN'), url;
if (asin) {
url = 'http://' + d.domain + '/dp/' + asin.value;
if (prompt('Short Amazon URL (hit OK to load):', url)) {
window.location.href = url;
}
} else {
alert("Can't find an Amazon product ID.");
}
}(document));
// Bookmarklet:
// javascript:(function(d){var asin=d.getElementById('ASIN'),url;if(asin){url='http://'+d.domain+'/dp/'+asin.value;if(prompt('Short Amazon URL (hit OK to load):',url)){window.location.href=url;}}else{alert("Can't find an Amazon product ID.");}}(document));
// Alternative bookmarklet generator:
// http://ted.mielczarek.org/code/mozilla/bookmarklet.html
@rondevera
Copy link
Author

This version adds support for:

  • Using the amazon.com domain (instead of the shorter amzn.com) to preserve the existing session (including cart contents).
  • Domain-relative URLs (e.g., amazon.ca).
  • Immediately loading the shortened URL as a sanity check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment