Created
April 22, 2015 02:52
-
-
Save cshtdd/fed895d6ca32a7bca2c3 to your computer and use it in GitHub Desktop.
bookmark to generate amazon affiliate links
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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