Created
January 8, 2024 12:59
-
-
Save if1live/8d1b310ae615cbc803dee4064b3fadfd to your computer and use it in GitHub Desktop.
override globalThis.fetch
This file contains 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
// https://corsproxy.io/ | |
const fetch_base = globalThis.fetch; | |
const fetch_next: typeof fetch_base = async (url, init) => { | |
if (typeof url === "string") { | |
const urlObj = new URL(url); | |
if (urlObj.hostname === "www.youtube.com") { | |
const proxyUrl = `https://corsproxy.io/?${encodeURIComponent(url)}`; | |
return await fetch_base(proxyUrl, init); | |
} | |
} | |
// else | |
return await fetch_base(url, init); | |
}; | |
globalThis.fetch = fetch_next as typeof fetch_base; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment