Facebook Remove Redundant URL Ref

Remove refsrc and tracking parameters from Facebook URLs

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name         Facebook Remove Redundant URL Ref
// @namespace    https://github.com/livinginpurple
// @version      2025.11.28.09
// @description  Remove refsrc and tracking parameters from Facebook URLs
// @license      WTFPL
// @author       livinginpurple
// @match        https://*.facebook.com/*
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    //https://m.facebook.com/story.php?story_fbid=426978937875840&id=291618078078594&refid=7&__tn__=-R

    const TARGET_PARAMS = ['refsrc', 'refid', '_rdr' , '__tn__', '__xts__', 'hrc', 'fbclid', 'utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'gclid', 'igshid', 'mc_cid', 'mc_eid', 'mkt_tok', 'dclid', 'fb_ref', 'fb_source', 'fref', 'efid', 'hsa_acc', 'hsa_cam', 'hsa_grp', 'hsa_ad', 'hsa_src', 'hsa_tgt', 'hsa_kw', 'hsa_mt', 'hsa_net'];
    try {
        const currentUrl = new URL(window.location.href);
        const searchParams = currentUrl.searchParams;
        let hasModified = false;

        TARGET_PARAMS.forEach(param => {
            if (searchParams.has(param)) {
                searchParams.delete(param);
                hasModified = true;
            }
        });

        if (hasModified) {
            const newUrl = currentUrl.toString();
            window.history.replaceState(null, '', newUrl);
            console.log(`${GMInfo.script.name} URL clean: ${newUrl}`);
        }

    } catch (e) {
        console.error(`${GMInfo.script.name} Error processing URL:`, e);
    }
})();