Skip to content

Instantly share code, notes, and snippets.

@akirilyuk
Created January 23, 2025 08:49
Show Gist options
  • Select an option

  • Save akirilyuk/08b6fca11b28643c3187b20ee3b50f24 to your computer and use it in GitHub Desktop.

Select an option

Save akirilyuk/08b6fca11b28643c3187b20ee3b50f24 to your computer and use it in GitHub Desktop.
Overwrite global fetch with discord proxy
const addProxy = (url) => {
if(url.startsWith('data')){
return url;
}
const split = url.split('/');
const proxyIndex = url.includes('://') ? 3 : split[0] !== '' ? 0 : 1;
if (split.length <= proxyIndex) {
return url;
}
if (split[proxyIndex] !== '.proxy' && split[proxyIndex] !== '') {
split.splice(proxyIndex, 0, '.proxy');
return split.join('/');
}
return url;
};
const originalFetch = window.fetch;
window.fetch = (param1, param2) => {
if (typeof param1 === 'string') {
return originalFetch(addProxy(param1), param2);
}
return originalFetch(param1, param2);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment