Created
February 2, 2021 03:19
-
-
Save schrobby/2fba54e74e5a39da4cdaf9adc0bb9af6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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