Twitch remove referrer=raid

automatically remove ?referrer=raid from twitch urls

当前为 2021-02-17 提交的版本,查看 最新版本

// ==UserScript==
// @name         Twitch remove referrer=raid
// @description  automatically remove ?referrer=raid from twitch urls
// @namespace    https://github.com/adrianmgg
// @version      2.0.1
// @author       amgg
// @license      WTFPL
// @compatible   chrome only browser i've tested this on
// @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);