Skip to content

Instantly share code, notes, and snippets.

@origamiofficial
Last active May 10, 2025 13:13
Show Gist options
  • Save origamiofficial/23203b030d4ecbd219e48d3d41d406d3 to your computer and use it in GitHub Desktop.
Save origamiofficial/23203b030d4ecbd219e48d3d41d406d3 to your computer and use it in GitHub Desktop.
Redirects non-Australian Amazon domains to amazon.com.au, handles 404 errors, and prevents loops. | Note: This script is solely intended for the use of educational purposes only and not to abuse any website. Use it wisely and do not abuse any website. Click "Raw" to install it on Tampermonkey
// ==UserScript==
// @name Amazon AU Redirect
// @namespace https://gist.github.com/origamiofficial/23203b030d4ecbd219e48d3d41d406d3
// @version 3.0
// @description Redirects non-Australian Amazon domains to amazon.com.au, handles 404 errors, and prevents loops.
// @author OrigamiOfficial
// @match *://*.amazon.*/*
// @grant none
// @run-at document-start
// @updateURL https://gist.githubusercontent.com/origamiofficial/23203b030d4ecbd219e48d3d41d406d3/raw/AmazonRedirect.user.js
// @downloadURL https://gist.githubusercontent.com/origamiofficial/23203b030d4ecbd219e48d3d41d406d3/raw/AmazonRedirect.user.js
// ==/UserScript==
(function() {
'use strict';
// List of non-Australian Amazon domains to redirect from
const amazonDomains = [
'amazon.com',
'amazon.co.uk',
'amazon.ca',
'amazon.de',
'amazon.fr',
'amazon.it',
'amazon.es',
'amazon.co.jp',
'amazon.in',
'amazon.com.br',
'amazon.com.mx',
'amazon.cn',
'amazon.nl',
'amazon.se',
'amazon.pl',
'amazon.ae',
'amazon.sa',
'amazon.sg',
'amazon.co.nz'
];
// Target Australian domain
const targetDomain = 'amazon.com.au';
// Get current URL components
const url = new URL(window.location.href);
const params = url.searchParams;
const currentHostname = url.hostname;
// Part 1: Immediate redirection from non-AU to AU
if (!params.has('tm-redirected') || params.get('tm-redirected') !== '1') {
if (amazonDomains.includes(currentHostname)) {
// Store the original domain and redirect to AU
const originalDomain = currentHostname;
url.hostname = targetDomain;
url.searchParams.set('original-domain', originalDomain);
window.location.href = url.toString();
}
}
// Part 2: Check for 404 on AU site and redirect back if necessary
if (currentHostname === targetDomain) {
document.addEventListener('DOMContentLoaded', function() {
if (is404Page()) {
const originalDomain = params.get('original-domain');
if (originalDomain) {
// Redirect back to the original domain with a flag to prevent re-redirection
url.hostname = originalDomain;
url.searchParams.delete('original-domain');
url.searchParams.set('tm-redirected', '1');
window.location.href = url.toString();
}
}
});
}
// Function to detect a 404 page based on the provided HTML
function is404Page() {
return document.body && document.body.innerHTML.includes('The Web address you entered is not a functioning page on our site');
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment