Facebook Remove Redundant URL Ref

Remove refsrc and tracking parameters from Facebook URLs

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==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);
    }
})();