Disable Facebook messenger link redirect cruft

2

Copying a link on Facebook messenger is a pain because Facebook adds redirect garbage to it. For example:

https://l.messenger.com/l.php?u=https%3A%2F%2Fpastebin.com%2Fz3au8T2R&h=ATMDXb187CWsF4_H7J-8fClHEigqWDiV1f-764DDoX7LSfnyJC_pLNqWD0wzLPsLUgQP4bq-MwQ1pxsIEg7i8E3WOboUXiG2tWZkSPthU8ZRimfHooSMatcJYLnIRA6PkDsCCAYGZmQyLa1TgpK-xQ3VmwLutw

Is there a way to remove all that extra cruft/garbage so that when I copy links its just the link:

https://pastebin.com/z3au8T2R

I have a Chrome Tampermonkey script that does something similar for Google links but I cannot find one for Facebook messenger.

Are there any pre-made ones or some way to do it yourself?

Puffycheeses

Posted 2017-09-21T05:37:10.623

Reputation: 175

Answers

2

I figured it out myself and created a Tampermonkey script to do this. Source code here as well as below:

// ==UserScript==
// @name         Remove Messenger Tracker
// @namespace    http://tampermonkey.net/
// @version      1.2
// @homepage     https://github.com/Puffycheeses/TamperMonkeyMessengerCleaner/
// @updateURL    https://github.com/Puffycheeses/TamperMonkeyMessengerCleaner/raw/master/Remove%20Messenger%20Tracker.user.js
// @description  Removes annoying Facebook Tracker
// @author       Puffycheeses
// @match        *://www.messenger.com/*
// @grant        none
// @require http://code.jquery.com/jquery-1.12.4.min.js
// ==/UserScript==
var i=0;
//var cleaned = 0; //For logging can ignore
var links = document.getElementsByTagName('a');
setInterval(function(){
    var links = document.getElementsByTagName('a');
    //console.log('Scanning for new links'); //Log that its actually working
}, 2500);
setInterval(function(){
    link = links[i];
    if(i < links.length) {
        if(link.href.includes('https://l.messenger.com/l.php?u=')){
            var rep = link.href;
            var ret = rep.replace("https://l.messenger.com/l.php?u=", "").replace(/%3A/g, ":").replace(/%2F/g, "/").replace(/%3F/g, "?").replace(/%3D/g, "=");
            var rek = ret.substring(0, ret.indexOf('&h='));
            //console.log(rek); //For displaying the found links
            link.href = rek;
            //cleaned += 1; //For displaying how many links were found
        }
    }
    if(i < links.length) {
        i+=1;
    } else {
        //if(cleaned > 0){ //This who section was to display how many links have been cleaned
        //    console.log(cleaned + ' Links found and cleaned');
        //}
        //cleaned = 0;
        i=0;
    }
}, 100);

Puffycheeses

Posted 2017-09-21T05:37:10.623

Reputation: 175

0

You could also use observers:

function disableLinkRedirection() {
  // Select the node that will be observed for mutations
  const targetNode = document.querySelector('.uiScrollableArea')

  // Options for the observer (which mutations to observe)
  const config = { attributes: true, childList: true, subtree: true }

  // Callback function to execute when mutations are observed
  const callback = function (mutationsList, observer) {
    console.log('Change detected!')
    document.querySelectorAll('a[data-lynx-mode]').forEach((el) => {
      el.addEventListener('click', (e) => {
        window.open(el.href)
        e.preventDefault()
      })
    })
  }

  // Create an observer instance linked to the callback function
  const observer = new MutationObserver(callback)

  // Start observing the target node for configured mutations
  observer.observe(targetNode, config)
}

disableLinkRedirection()

Rafal Enden

Posted 2017-09-21T05:37:10.623

Reputation: 101