不要長FB連結(No FB long url)

remove fbclid on you mouse down the link(讓點下去連結短一點)

当前为 2021-11-20 提交的版本,查看 最新版本

// ==UserScript==
// @name         不要長FB連結(No FB long url)
// @namespace    http://tampermonkey.net/
// @version      0.5
// @description  remove fbclid on you mouse down the link(讓點下去連結短一點)
// @author       You
// @match        https://*.facebook.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    document.body.addEventListener('mousedown', function () {
    // 兼容处理
    var target = event.target || event.srcElement;
    // 判断是否匹配目标元素console.log('当前点击的 a 标签: ', target);

        if(event.button==2){
            return;
        }

        // 处理完 a 标签的内容,重新触发跳转,根据原来 a 标签页 target 来判断是否需要新窗口打开
        function getTopA(node){
            if(node.nodeName.toLocaleLowerCase() === 'a'){
                return node;
            }else{
                if(node.parentElement==null){
                    return null;
                }else{
                    return getTopA(node.parentElement);
                }
            }
        }
        function prevent(){
            if (event.preventDefault) {
                             event.preventDefault();
                         } else {
                             window.event.returnValue = true;
                         }
        }
        function openNewBackgroundTab(url) {
            var a = document.createElement("a");
            a.href = url;
            var evt = document.createEvent("MouseEvents");

            //the tenth parameter of initMouseEvent sets ctrl key
            evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, false, 0, null);
            a.dispatchEvent(evt);
        }

        //console.log(target);
         if(target.nodeName.toLocaleLowerCase() === 'i' || target.nodeName.toLocaleLowerCase() === 'div'){

         }else{
             target=getTopA(target);
             if(target!=null){
                 var url = target.getAttribute("href");
                 if(url!=null)
                 {
                     if (target.getAttribute("target") === '_blank') {
                         if(url.includes("https://l.facebook.com/l.php?u=")){
                             url=decodeURIComponent(url.substring("https://l.facebook.com/l.php?u=".length));
                         }
                         if(url.match(/&*fbclid=.*&/)){
                             url=url.replace(/&*fbclid=.*&/,"&")
                         }else{
                             url=url.replace(/&*fbclid=.*/,"")
                         }
                         url=url.replace(/\?$/,"")
                         target.setAttribute("href",url);
                         if(event.buttons==1){
                             prevent()
                             window.open(url)
                         }
                     }
                 }
             }
         }
});
})();

QingJ © 2025

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