Universal Tracker Remover

Removes common tracking parameters (e.g., utm_source, fbclid, from) from all links and the browser address bar, on all websites.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Universal Tracker Remover
// @namespace    https://cleanlinks.net/
// @version      1.0
// @description  Removes common tracking parameters (e.g., utm_source, fbclid, from) from all links and the browser address bar, on all websites.
// @author       DiCK
// @match        *://*/*
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // List of tracking parameters to remove
    const trackingParams = [
        'utm_source',
        'utm_medium',
        'utm_campaign',
        'utm_term',
        'utm_content',
        'fbclid',
        'gclid',
        'mc_cid',
        'mc_eid',
        'ref',
        'ref_',
        'from'
    ];

    // Remove trackers from a given URL string
    function removeTrackersFromUrl(urlString) {
        try {
            const url = new URL(urlString, window.location.origin);
            let modified = false;

            trackingParams.forEach(param => {
                if (url.searchParams.has(param)) {
                    url.searchParams.delete(param);
                    modified = true;
                }
            });

            return modified ? url.toString() : urlString;
        } catch (e) {
            // Fail silently if invalid URL
            return urlString;
        }
    }

    // Clean all anchor tags on the page
    function cleanLinks() {
        const links = document.querySelectorAll('a[href*="?"], a[href*="&"]');

        links.forEach(link => {
            const cleaned = removeTrackersFromUrl(link.href);
            if (cleaned !== link.href) {
                link.href = cleaned;
            }
        });
    }

    // Clean the browser address bar (without reloading the page)
    function cleanAddressBar() {
        const currentUrl = window.location.href;
        const cleaned = removeTrackersFromUrl(currentUrl);

        if (cleaned !== currentUrl) {
            const urlObj = new URL(cleaned);
            const newUrl = urlObj.pathname + urlObj.search + urlObj.hash;
            window.history.replaceState(null, '', newUrl);
        }
    }

    // Run immediately
    cleanLinks();
    cleanAddressBar();

    // Watch for dynamic changes (e.g., AJAX navigation)
    const observer = new MutationObserver(() => {
        cleanLinks();
    });

    observer.observe(document.body, { childList: true, subtree: true });
})();