Skip to content

Instantly share code, notes, and snippets.

@sergiosusa
Created June 27, 2019 14:04
Show Gist options
  • Save sergiosusa/c2644d9919aa172c4443604221e1d941 to your computer and use it in GitHub Desktop.
Save sergiosusa/c2644d9919aa172c4443604221e1d941 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name My Amazon Affiliate
// @namespace https://sergiosusa.com
// @version 0.3
// @description This script add my affiliate tag to all amazon.es product pages, thanks for your help.
// @author Sergio Susa (https://sergiosusa.com)
// @match https://www.amazon.de/*/dp/*
// @match https://www.amazon.de/dp/*
// @match https://www.amazon.de/*/gp/*
// @match https://www.amazon.de/gp/*
// @exclude https://www.amazon.de/gp/huc/*
// @grant none
// ==/UserScript==
const AMAZON_AFFILIATE_ID = 'sergiosusa07-21';
(function () {
'use strict';
let originalUrl = document.URL;
if (!originalUrl.includes('tag=' + AMAZON_AFFILIATE_ID)) {
window.location.href = updateQueryStringParameter(originalUrl, "tag", AMAZON_AFFILIATE_ID);
}
})();
function updateQueryStringParameter(uri, key, value) {
let re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
let separator = uri.indexOf("?") !== -1 ? "&" : "?";
if (uri.match(re)) {
return uri.replace(re, "$1" + key + "=" + value + "$2");
} else {
return uri + separator + key + "=" + value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment