Remove URL Tracking Parameters

移除網址中的跟踪參數

16.06.2024 itibariyledir. En son verisyonu görün.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Remove URL Tracking Parameters
// @namespace    http://tampermonkey.net/
// @version      1.0
// @description  移除網址中的跟踪參數
// @author abc0922001
// @match        *://*/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // 定義要移除的跟踪參數
    const trackingParams = [
        'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 
        'fbclid', 'gclid', 'yclid', 'mc_cid', 'mc_eid', 'dclid'
    ];

    function removeTrackingParams(url) {
        const urlObj = new URL(url);
        let params = urlObj.searchParams;
        let removed = false;

        trackingParams.forEach(param => {
            if (params.has(param)) {
                params.delete(param);
                removed = true;
            }
        });

        return removed ? urlObj.toString() : null;
    }

    function cleanURL() {
        const cleanedUrl = removeTrackingParams(window.location.href);
        if (cleanedUrl) {
            window.history.replaceState({}, document.title, cleanedUrl);
        }
    }

    cleanURL();

    // 監聽 URL 變化(例如單頁應用程序中的路由變化)
    const observer = new MutationObserver(cleanURL);
    observer.observe(document, { subtree: true, childList: true });
})();