Skip to content

Instantly share code, notes, and snippets.

@cshtdd
Created April 22, 2015 02:52

Revisions

  1. cshtdd created this gist Apr 22, 2015.
    22 changes: 22 additions & 0 deletions amazon-affiliate-bookmark
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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];
    }
    }
    }