Dan Lowe

Thoughts on life, the universe, and everything.

Shorten Amazon URL (bookmarklet)

Do you find Amazon’s product page URLs ridiculously long? They’re a pain to paste into an IM window or an email. For most product pages, a much shorter version can be used. For instance, you can turn this:

1
http://www.amazon.com/gp/product/014311638X/ref=s9_simh_gw_p14_i1?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=1V6X9CF9300FXVK16QJY&pf_rd_t=101&apf_rd_p=470938631&pf_rd_i=507846

into this:

1
http://www.amazon.com/gp/product/014311638X

Drag the bookmarklet to your Bookmarks Bar. When you’re on an Amazon product page and want to shorten the URL, click it. You’ll be taken to the same page, with the short URL instead.

Shorten Amazon URL ← Drag this to your Bookmarks Bar

For those who are interested, here is the source code.

1
2
3
4
5
6
7
8
9
10
11
12
13
var url = document.location.href;

var dp_re = /\/dp\//;
var gp_re = /\/gp\/product\//;

if (dp_re.test(url)) {
    location = url.replace(/^(http:\/\/[^\/]+).*(\/dp\/[^\/]+)\/.*$/, "$1$2");
} else if (gp_re.test(url)) {
    location = url.replace(/^(http:\/\/[^\/]+).*(\/gp\/product\/[^\/]+)\/.*$/,
      "$1$2" );
} else {
    alert("Unrecognized URL format");
}