Facebook Remove Redundant URL Ref

Remove refsrc in facebook url

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Facebook Remove Redundant URL Ref
// @namespace    https://github.com/livinginpurple
// @version      2019.04.25.07
// @description  Remove refsrc in facebook url
// @author       livinginpurple
// @license      WTFPL
// @match        http://*.facebook.com/*
// @match        https://*.facebook.com/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    //https://m.facebook.com/story.php?story_fbid=426978937875840&id=291618078078594&refid=7&__tn__=-R
    console.log(GM_info.script.name + " is loading.");
    let SearchParameters = location.search.split('&');
    let uri = location.origin + location.pathname + SearchParameters[0] + "&" + SearchParameters[1];
    let keywords = ["refsrc", "__tn__", "__xts__"];

    keywords.forEach(element => {
        if (location.href.includes(element)) {
            ModifyUrl(uri);
        }
    });

    function ModifyUrl(replaceUri) {
        // 修改網址,且不留下歷史紀錄
        window.history.replaceState({},
            window.title,
            replaceUri
        );
    }
    console.log(GM_info.script.name + " is running.");
})(window);