Skip to content

Instantly share code, notes, and snippets.

@AlD
Last active June 11, 2019 23:31
Show Gist options
  • Save AlD/e288d567bc581c97f4a3a4bc1bf5d447 to your computer and use it in GitHub Desktop.
Save AlD/e288d567bc581c97f4a3a4bc1bf5d447 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Amazon Smile Redirect
// @license BSD-3-Clause
// @namespace https://gist.github.com/AlD/e288d567bc581c97f4a3a4bc1bf5d447
// @updateURL https://gist.github.com/AlD/e288d567bc581c97f4a3a4bc1bf5d447/raw/amazon-smile-redirect.user.js
// @downloadURL https://gist.github.com/AlD/e288d567bc581c97f4a3a4bc1bf5d447/raw/amazon-smile-redirect.user.js
// @version 0.3.0
// @description Redirect from regular Amazon to Amazon Smile
// @author Daniel Albers <[email protected]>
// @match https://www.amazon.de/*
// @match https://www.amazon.com/*
// @match https://www.amazon.co.uk/*
// @grant GM_getValue
// @grant GM_setValue
// @run-at document-start
// ==/UserScript==
(function() {
'use strict';
const lp = '[Smile Redirect]';
const lrt = 'lastRedirectTarget';
let u = window.location;
let h = u.hostname.split('.');
console.assert(h[0] == 'www', "URL not matching 'www.*'");
h[0] = 'smile';
let r = new URL(u);
r.hostname = h.join('.');
if (GM_getValue(lrt) != r.toString()) {
console.log([lp, 'Redirecting from', u, 'to', r + '.'].join(' '));
GM_setValue(lrt, r.toString());
window.location = r;
} else {
console.log([
lp, 'Previous redirect also originated from', u + '.',
'Not redirecting again to prevent loops.',
].join(' '));
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment