Remove Redundant URL Search Parameters

Remove Redundant URL Search Parameters like fbclid

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Remove Redundant URL Search Parameters
// @namespace    https://github.com/livinginpurple
// @version      2019.08.03.14
// @description  Remove Redundant URL Search Parameters like fbclid
// @author       livinginpurple
// @license      WTFPL
// @exclude      https://*.google.com/*
// @exclude      https://*.facebook.com/*
// @exclude      https://www.plurk.com/*
// @include 	 *
// @grant        none
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';
    console.log(GM_info.script.name + " is loading.");;
    let TotalReplaceUri = location.href.split("?")[0];
    let FirstSearchParameter = location.search.split('&')[0];
    let PartialReplaceUri = TotalReplaceUri + FirstSearchParameter;
    let keywords = ["fbclid", "jobsource", "from=fb", "f=cs", "gclid", "utm_", "from=udn"];

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

    if (PartialReplaceUri.includes("fbclid") && !FirstSearchParameter.includes("fbclid")) {
        ModifyUrl(PartialReplaceUri);
    }

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