Created
June 19, 2019 18:33
-
-
Save sergiosusa/de0144c8605aa93b4b93db5417d725c4 to your computer and use it in GitHub Desktop.
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
// ==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