Twitch remove referrer=raid

automatically remove ?referrer=raid from twitch urls

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Twitch remove referrer=raid
// @description  automatically remove ?referrer=raid from twitch urls
// @namespace    https://github.com/adrianmgg
// @version      2.0.2
// @author       amgg
// @license      MIT
// @compatible   chrome
// @compatible   firefox
// @match        https://www.twitch.tv/*
// @match        https://www.twitch.tv
// @grant        unsafeWindow
// @run-at       document-start
// ==/UserScript==

// i can't think of what to name this function right now
function doTheThing(url) {
    // doing it this way (referrer=raid without the ?) since this works when there are other url params
    if(url.includes("referrer=raid")) {
        document.location.href = url.replace("referrer=raid", "");
    }
}

const PUSHSTATE = unsafeWindow.history.pushState;
unsafeWindow.history.pushState = function(state, title, url) {
    doTheThing(url);
    return PUSHSTATE.apply(this, arguments);
};

// just in case we were brought to the page directly rather than through pushstate
doTheThing(document.location.href);