Skip to content

Instantly share code, notes, and snippets.

@ryanfeeley
Created January 17, 2026 15:29
Show Gist options
  • Select an option

  • Save ryanfeeley/f13e77852b2087cbd503d30fd9275090 to your computer and use it in GitHub Desktop.

Select an option

Save ryanfeeley/f13e77852b2087cbd503d30fd9275090 to your computer and use it in GitHub Desktop.
Amazon.com to .ca link swapper
// 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