Greasy Fork is available in English.

Facebook delete Fbclid Link

Automatically detect and remove fuck Fbclid links when scrolling

< Opinie na Facebook delete Fbclid Link

Ocena: OK - skrypt działa, ale ma błędy

§
Napisano: 14-03-2020
Edytowano: 14-03-2020

Sometimes doesn't clean all fbclid's

For example let's take this: https://www.facebook.com/photo.php?fbid=10209291955122809&set=pob.100002008347055&type=3&theater

(Click show more comments to see the link) The link to the picture on deviantart.net still contains this f***ing fbclid and so doesn't work. Error 404.

Looking at the source reveals: https://l.facebook.com/l.php?u=http%3A%2F%2Forig03.deviantart.net%2Fa8f7%2Ff%2F2016%2F021%2Ff%2F0%2Fdie_letzten_streichhoelzer_by_ryanrough-d9orqsg.jpg%3Ffbclid%3DIwAR...

  1. The links are URL-encoded. '%3Ffbclid%3D' => '?fbclid='
  2. There is this stupid l.facebook.com/l.php Prepended to each link. >!

Well I still didn't fixed that problem - however Here is a proposal for the script:

// ==UserScript==
// @name         Facebook delete Fbclid Link
// @namespace    https://greasyfork.org/zh-TW/scripts/396523-facebook-delete-fbclid-link
// @version      0.2
// @description  Automatically detect and remove fuck Fbclid links when scrolling
// @author       You
// @match        https://*.facebook.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    excute()
})();


function excute() {
    const fbclidLinkList = document.querySelectorAll('a[href*="fbclid"]')
    if (!fbclidLinkList || fbclidLinkList.length === 0) {
        debugger
        setTimeout(excute, 500)
        return
    }
    window.addEventListener("scroll", deleteFbclidLink)
    deleteFbclidLink()
}

function deleteFbclidLink() {
    const ERROR = "Houston, we have a problem: "
    const fbclidLinkList = document.querySelectorAll('a[href*="fbclid"]')
    if (!fbclidLinkList || fbclidLinkList.length === 0) {
        debugger
        return
    }
    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


    }
}

Odpowiedz

Zaloguj się, by odpowiedzieć.