// ==UserScript==
// @name Remove Amazon Tracking Parameters
// @namespace http://tampermonkey.net/
// @version 1.1
// @description Remove unnecessary tracking parameters from Amazon product pages
// @author USForeign Policy
// @match https://www.amazon.au/*
// @match https://www.amazon.be/*
// @match https://www.amazon.com/*
// @match https://www.amazon.com.au/*
// @match https://www.amazon.com.be/*
// @match https://www.amazon.com.mx/*
// @match https://www.amazon.co.jp/*
// @match https://www.amazon.co.uk/*
// @match https://www.amazon.de/*
// @match https://www.amazon.es/*
// @match https://www.amazon.fr/*
// @match https://www.amazon.in/*
// @match https://www.amazon.it/*
// @match https://www.amazon.nl/*
// @match https://www.amazon.pl/*
// @match https://www.amazon.se/*
// @grant none
// @license MIT
// @downloadURL https://update.greasyfork.org/scripts/481017/Remove%20Amazon%20Tracking%20Parameters.user.js
// @updateURL https://update.greasyfork.org/scripts/481017/Remove%20Amazon%20Tracking%20Parameters.meta.js
// ==/UserScript==
(function() {
'use strict';
// Select all links on the web page.
var links = document.querySelectorAll("a");
// Wait for 1 second before executing the script.
setTimeout(function() {
// Iterate over the links.
for (var i = 0; i < links.length; i++) {
// Call the `removeTrackingParameters()` function for each link.
removeTrackingParameters(links[i]);
}
}, 1000); // 1000 milliseconds (1 second)
// Function `removeTrackingParameters()`.
function removeTrackingParameters(link) {
// Get the URL of the link.
var url = link.href;
// Check if the URL contains "/dp/" followed by a 10-character product code.
var regex = /\/dp\/([A-Z0-9]{10})(.*)/;
var match = url.match(regex);
// If the URL contains a product code, extract it.
if (match) {
var productCode = match[1];
// Build the new URL without tracking parameters.
var newURL = url.replace(regex, "/dp/" + productCode);
// Replace the link with the new URL.
link.href = newURL.replace(/\/dp\/([A-Z0-9]{10})(.*)\//, "/dp/$1");
}
}
})();
I edited your code because it didn't work for me. I have used 2 AI to generate the new code with the ideas I have had. I think the next step could be to delete parameters for the categories. Brave does this by pressing the copy clean link button. https://www.amazon.es/gcx/Regalos-para-Hombres/gfhz/category?categoryId=adult-male I have also seen that you can also clean the nodes by leaving them like this https://www.amazon.com.be/b/node=27901539031 or like this https://www.amazon.com.be/b/?encoding=UTF8&node= 27901594031&bbn=27156491031&ref=Oct_d_odnav_d_27901539031_1