Brozy123 commited on
Commit
8a8ccbf
·
verified ·
1 Parent(s): 941b50c

Update network_fix.js

Browse files
Files changed (1) hide show
  1. 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 url = typeof input === 'string' ? input : (input.url || input.toString());
93
- const isDiscord = (u) => u && (u.includes('discord.com') || u.includes('discordapp.com') || u.includes('dis.gd') || u.includes('discord.gg'));
94
- if (isDiscord(url)) {
95
- const newUrl = url.replace(/discord\.com|discordapp\.com|dis\.gd|discord\.gg/, DOMAINS[current_index]);
96
- return _oldFetch.call(this, newUrl, init);
 
 
 
 
 
 
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