Spaces:
Runtime error
Runtime error
Update network_fix.js
Browse files- network_fix.js +11 -6
network_fix.js
CHANGED
|
@@ -89,13 +89,18 @@ function applyAdvancedFixes() {
|
|
| 89 |
if (globalObj.fetch) {
|
| 90 |
const _oldFetch = globalObj.fetch;
|
| 91 |
globalObj.fetch = async function(input, init) {
|
| 92 |
-
let
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
const
|
| 96 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
}
|
| 98 |
-
return _oldFetch.call(this, input, init);
|
| 99 |
};
|
| 100 |
}
|
| 101 |
|
|
|
|
| 89 |
if (globalObj.fetch) {
|
| 90 |
const _oldFetch = globalObj.fetch;
|
| 91 |
globalObj.fetch = async function(input, init) {
|
| 92 |
+
let urlStr = typeof input === 'string' ? input : (input.url || input.toString());
|
| 93 |
+
try {
|
| 94 |
+
const url = new URL(urlStr);
|
| 95 |
+
const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('discordapp.net') || h.includes('dis.gd') || h.includes('discord.gg'));
|
| 96 |
+
if (isDiscord(url.hostname)) {
|
| 97 |
+
// Replace the hostname entirely with our target domain
|
| 98 |
+
url.hostname = DOMAINS[current_index];
|
| 99 |
+
}
|
| 100 |
+
return _oldFetch.call(this, url.toString(), init);
|
| 101 |
+
} catch (e) {
|
| 102 |
+
return _oldFetch.call(this, input, init);
|
| 103 |
}
|
|
|
|
| 104 |
};
|
| 105 |
}
|
| 106 |
|