Created
January 17, 2026 15:29
-
-
Save ryanfeeley/f13e77852b2087cbd503d30fd9275090 to your computer and use it in GitHub Desktop.
Amazon.com to .ca link swapper
This file contains hidden or 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
| // Amazon.com to .ca link swapper | |
| (() => { | |
| const a = document.getElementById("redir-go-to-site"); | |
| if (!a) return; | |
| const buildCaUrl = () => { | |
| const u = new URL(location.href); | |
| // Keep same path/query/hash, but switch to amazon.ca | |
| // This handles amazon.com / amazon.co.uk / etc. | |
| u.hostname = "www.amazon.ca"; | |
| // If you want to drop the interstitial ref param: | |
| u.searchParams.delete("ref_"); | |
| return u.toString(); | |
| }; | |
| const target = buildCaUrl(); | |
| // Update visible href (nice-to-have) | |
| a.href = target; | |
| // Kill Amazon’s handler + force navigation | |
| a.addEventListener( | |
| "click", | |
| (e) => { | |
| e.preventDefault(); | |
| e.stopPropagation(); | |
| e.stopImmediatePropagation(); | |
| window.location.assign(target); | |
| }, | |
| true // capture phase so we run before their listener | |
| ); | |
| console.log("Forced click target:", target); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment