Assuming I have an Amazon product URL like so
http://www.amazon.com/Kindle-Wireless-Reading-Display-Generation/dp/B0015T963C/ref=amb_link_86123711_2?pf_rd_m=ATVP
If the ASIN is always in that position in the URL:
var asin= decodeURIComponent(url.split('/')[5]);
though there's probably little chance of an ASIN getting %-escaped.