Skip to content

Instantly share code, notes, and snippets.

@NanoAi
Last active October 30, 2020 23:03
Show Gist options
  • Save NanoAi/1c67f4d8858060b6f9c4ea3a91000b11 to your computer and use it in GitHub Desktop.
Save NanoAi/1c67f4d8858060b6f9c4ea3a91000b11 to your computer and use it in GitHub Desktop.
Twitch bypassing ublock yet again... let's fix that.
// ==UserScript==
// @name Twitch Ad Things
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://www.twitch.tv/*
// @grant unsafeWindow
// @run-at document-start
// ==/UserScript==
/// Original by https://ttv-ublock.vercel.app/twitch-videoad.js
/// Thread: https://www.reddit.com/r/uBlockOrigin/comments/jjesgn/
/// This version was edited to work as a userscript it also binds some event listeners.
(function QWOji() {
'use strict';
const origFetch = window.fetch;
window.fetch = (url, init, ...args) => {
if (typeof url === "string") {
if (url.includes("/access_token")) {
url = url.replace("player_type=site", "player_type=facebook");
} else if (
url.includes("/gql") &&
init &&
typeof init.body === "string" &&
init.body.includes("PlaybackAccessToken")
) {
const newBody = JSON.parse(init.body);
newBody.variables.playerType = "facebook";
init.body = JSON.stringify(newBody);
}
}
return origFetch(url, init, ...args);
};
window.addEventListener("hashchange", QWOji, false);
window.addEventListener("load", QWOji, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment