Last active
June 11, 2019 23:31
-
-
Save AlD/e288d567bc581c97f4a3a4bc1bf5d447 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 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