禁用 Facebook Messenger 链接重定向

禁用 Facebook Messenger 链接重定向

在 Facebook Messenger 上复制链接很麻烦,因为 Facebook 会添加重定向垃圾。例如:

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

有没有办法删除所有多余的垃圾/垃圾,以便当我复制链接时它只是链接:

https://pastebin.com/z3au8T2R

我有一个 Chrome Tampermonkey 脚本,可以对 Google 链接执行类似操作,但我找不到适用于 Facebook messenger 的脚本。

有没有现成的或者自己做的方法?

答案1

我自己解决了这个问题并创建了一个 Tampermonkey 脚本来实现这一点。源代码在这里以及以下内容:

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

答案2

您还可以使用观察员:

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()

相关内容