Greasy Fork 还支持 简体中文。

Remove Amazon Tracking Parameters (All Domains)

Aggressive approach to remove Amazon tracking parameters across all country domains

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Remove Amazon Tracking Parameters (All Domains)
// @namespace    http://tampermonkey.net/
// @version      2.0
// @description  Aggressive approach to remove Amazon tracking parameters across all country domains
// @include       *://*.amazon.*/*
// @grant        none
// @run-at       document-start
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    /**
     * Removes tracking from the current URL if it matches an Amazon product page
     * and rewrites history to a clean version of the URL.
     */
    function cleanAmazonUrl() {
        var currentURL = window.location.href;
        // Matches /dp/ASIN or /gp/product/ASIN with a 10-character code
        // The 'i' flag lets it match uppercase or lowercase letters/numbers
        var asinPattern = /\/(?:dp|gp\/product)\/([A-Z0-9]{10})(?:[/?]|$)/i;
        var match = asinPattern.exec(currentURL);
        if (match) {
            var asin = match[1];
            var newURL = window.location.protocol + '//' + window.location.host + '/dp/' + asin;
            if (newURL !== currentURL) {
                // Rewrite the URL in the address bar without triggering a page reload
                window.history.replaceState({}, document.title, newURL);
            }
        }
    }

    // --- Hook into history methods and popstate to catch all Amazon URL changes --- //

    var _pushState = history.pushState;
    var _replaceState = history.replaceState;

    // Override pushState
    history.pushState = function(state, title, url) {
        var ret = _pushState.apply(this, arguments);
        // After pushState is called, clean the URL
        setTimeout(cleanAmazonUrl, 10);
        return ret;
    };

    // Override replaceState
    history.replaceState = function(state, title, url) {
        var ret = _replaceState.apply(this, arguments);
        // After replaceState is called, clean the URL
        setTimeout(cleanAmazonUrl, 10);
        return ret;
    };

    // Also listen for popstate (back/forward browser buttons)
    window.addEventListener('popstate', function() {
        // Clean the URL after a brief delay
        setTimeout(cleanAmazonUrl, 10);
    });

    // Lastly, do an initial cleanup as early as possible (document-start)
    cleanAmazonUrl();
})();