Skip to content

Instantly share code, notes, and snippets.

@schrobby
Created February 2, 2021 03:19
Show Gist options
  • Save schrobby/2fba54e74e5a39da4cdaf9adc0bb9af6 to your computer and use it in GitHub Desktop.
Save schrobby/2fba54e74e5a39da4cdaf9adc0bb9af6 to your computer and use it in GitHub Desktop.
const CODE = `
const origFetch = window.fetch;
window.fetch = (url, init, ...args) => {
try {
if (typeof url === "string") {
if (url.includes("/access_token")) {
url = url.replace("player_type=site", "player_type=embed");
} else if (
url.includes("/gql") &&
init &&
typeof init.body === "string" &&
init.body.includes("PlaybackAccessToken")
) {
const newBody = JSON.parse(init.body);
newBody.variables.playerType = "embed";
init.body = JSON.stringify(newBody);
}
}
} catch (e) {}
return origFetch(url, init, ...args);
};
`;
// To access the page's JS context, we need to inject an actual script
if (window.location.href.startsWith("https://www.twitch.tv/")) {
const script = document.createElement("script");
script.textContent = CODE;
document.documentElement.prepend(script);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment