Skip to content

Instantly share code, notes, and snippets.

@cshtdd
Created April 22, 2015 02:52
Show Gist options
  • Save cshtdd/fed895d6ca32a7bca2c3 to your computer and use it in GitHub Desktop.
Save cshtdd/fed895d6ca32a7bca2c3 to your computer and use it in GitHub Desktop.
bookmark to generate amazon affiliate links
javascript:
var affiliateId = "YOUR_AFFILIATE_ID";
var l = window.location.href;
var urlPieces = l.split("/");
var productId = getProductId("dp");
if (!productId){
productId = getProductId("product");
}
if (productId){
var newurl = "http://www.amazon.com/dp/" + productId + "/?tag=" + affiliateId;
alert(newurl);
}
function getProductId(prevKey){
for (var i = 0; i < urlPieces.length - 1; i++){
if (urlPieces[i].toLowerCase() == prevKey){
return urlPieces[i + 1];
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment