Skip to content

Instantly share code, notes, and snippets.

@sergiosusa
Created June 19, 2019 18:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sergiosusa/de0144c8605aa93b4b93db5417d725c4 to your computer and use it in GitHub Desktop.
Save sergiosusa/de0144c8605aa93b4b93db5417d725c4 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name My Indiegala Affiliate
// @namespace https://sergiosusa.com
// @version 0.1
// @description This script add my affiliate tag to all indiegala.com.
// @author Sergio Susa (https://sergiosusa.com)
// @match https://www.indiegala.com*
// @match https://www.indiegala.com/*
// @grant none
// ==/UserScript==
const INDIEGALA_AFFILIATE_ID = 'sergiosusa';
(function () {
'use strict';
let originalUrl = document.URL;
if (!originalUrl.includes('ref=' + INDIEGALA_AFFILIATE_ID)) {
window.location.href = updateQueryStringParameter(originalUrl, "ref", INDIEGALA_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