Clean fbclid from Facebook links

Removes the fbclid(= Facebook Click ID) parameter and Facebook redirect - (l.facebook.com?u=...) from all links in Facebook when scrolling.

目前為 2021-04-15 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Clean fbclid from Facebook links
// @namespace    https://gf.qytechs.cn/scripts/396523-facebook-delete-fbclid-link
// @icon         https://facebook.com/favicon.ico
// @version      0.3
// @description  Removes the fbclid(= Facebook Click ID) parameter and Facebook redirect - (l.facebook.com?u=...) from all links in Facebook when scrolling.
// @author       Djamana
// @match        https://*.facebook.com/*
// @grant        none
// ==/UserScript==


(
    function() {
    'use strict';

	execute()
})();



function execute() {

    const fbclid_Selector = 'a[href*="fbclid"]'
    const ERROR           = "Houston, we have a problem: "

	const fbclidLinkList = document.querySelectorAll( fbclid_Selector )
	if (!fbclidLinkList || fbclidLinkList.length === 0) {
        debugger

     // ... No fbclid links found on the page ?
     // ... so run-deleteFbclidLink() every 5 seconds
		setTimeout(execute, 5000)

    } else {

        // There are fbclid links on the page.
        // Install run-deleteFbclidLink()-when-scrolling handler ...
        window.addEventListener("scroll", deleteFbclidLink)

        // ... and remove them now ( = run deleteFbclidLink() )
        deleteFbclidLink()
	}
}

function deleteFbclidLink() {

    const fbclid_Selector = 'a[href*="fbclid"]'
    const fbclidLinkList = document.querySelectorAll( fbclid_Selector)
	if (!fbclidLinkList || fbclidLinkList.length === 0) {
        return
    }

        const ERROR           = "Houston, we have a problem: "

	for (const fbclidLink of fbclidLinkList) {
        const fbclidURL = new URL(fbclidLink.href)

        // Remove Facebook redirect - l.facebook.com?u=
        try {
            if ( fbclidURL.host === "l.facebook.com" ) {
                fbclidURL.href = decodeURI( fbclidURL.searchParams.get("u") )
            }

        }  catch (e) {
           console.log( "Remove redirect - " +  ERROR + e)
        }

        // Remove '...&fbclid=...' parameter
        try {

           fbclidURL.searchParams.delete("fbclid")

        }  catch (e) {
           console.log( "Remove fbclid - " + ERROR + e)
        }
        debugger
        console.log (fbclidLink.href + " -> " + fbclidURL.href)

        // 'Output cleared link
        fbclidLink.href = fbclidURL.href


    }
}

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址