Clean Cloudflare URL

Remove ugly Cloudflare-generated parameters from the url

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name               Clean Cloudflare URL
// @name:zh-CN         清理 Cloudflare 生成的 URL 参数
// @namespace          https://github.com/andylizi
// @version            0.2
// @author             andylizi
// @description        Remove ugly Cloudflare-generated parameters from the url
// @description:zh-CN  清除 Cloudflare 在 URL 中插入的一长串参数
// @icon               https://www.cloudflare.com/favicon.ico
// @include            /__cf_chl_(jschl_|captcha_|managed_|rt_|f_|)tk(__)?=/
// @run-at             document-start
// @grant              none
// @noframes
// ==/UserScript==

(function() {
    'use strict';

    const oldUrl = location.href, url = new URL(oldUrl);
    const params = url.searchParams;
    ["__cf_chl_jschl_tk__", "__cf_chl_managed_tk__", "__cf_chl_captcha_tk__", "__cf_chl_tk", "__cf_chl_rt_tk", "__cf_chl_f_tk"]
        .forEach(p => params.delete(p));
    const newUrl = url.toString();
    (newUrl !== oldUrl) && history.replaceState(history.state, '', newUrl);
})();