Spaces:
Runtime error
Runtime error
Update network_fix.js
Browse files- network_fix.js +19 -3
network_fix.js
CHANGED
|
@@ -3,9 +3,9 @@ const http = require('http');
|
|
| 3 |
const dns = require('dns');
|
| 4 |
|
| 5 |
const DOMAINS = [
|
|
|
|
| 6 |
"canary.discord.com",
|
| 7 |
"ptb.discord.com",
|
| 8 |
-
"discordapp.com",
|
| 9 |
"discord.com"
|
| 10 |
];
|
| 11 |
let current_index = 0;
|
|
@@ -40,6 +40,9 @@ function applyAdvancedFixes() {
|
|
| 40 |
const target_domain = DOMAINS[current_index];
|
| 41 |
console.log(`[*] NetworkFix: Forcing traffic through ${target_domain}...`);
|
| 42 |
|
|
|
|
|
|
|
|
|
|
| 43 |
// Patch https.request to hijack all Discord-related domains
|
| 44 |
const _oldRequest = https.request;
|
| 45 |
https.request = function(options, callback) {
|
|
@@ -91,6 +94,19 @@ function applyAdvancedFixes() {
|
|
| 91 |
const _oldFetch = globalObj.fetch;
|
| 92 |
globalObj.fetch = async function(input, init) {
|
| 93 |
let urlStr = typeof input === 'string' ? input : (input.url || input.toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
try {
|
| 95 |
const url = new URL(urlStr);
|
| 96 |
const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('discordapp.net') || h.includes('dis.gd') || h.includes('discord.gg'));
|
|
@@ -99,9 +115,9 @@ function applyAdvancedFixes() {
|
|
| 99 |
if (isDiscord(url.hostname) && !isAsset(url.hostname)) {
|
| 100 |
url.hostname = DOMAINS[current_index];
|
| 101 |
}
|
| 102 |
-
return _oldFetch.call(this, url.toString(),
|
| 103 |
} catch (e) {
|
| 104 |
-
return _oldFetch.call(this, input,
|
| 105 |
}
|
| 106 |
};
|
| 107 |
}
|
|
|
|
| 3 |
const dns = require('dns');
|
| 4 |
|
| 5 |
const DOMAINS = [
|
| 6 |
+
"discordapp.com",
|
| 7 |
"canary.discord.com",
|
| 8 |
"ptb.discord.com",
|
|
|
|
| 9 |
"discord.com"
|
| 10 |
];
|
| 11 |
let current_index = 0;
|
|
|
|
| 40 |
const target_domain = DOMAINS[current_index];
|
| 41 |
console.log(`[*] NetworkFix: Forcing traffic through ${target_domain}...`);
|
| 42 |
|
| 43 |
+
// Basic Connectivity Test
|
| 44 |
+
global.fetch && global.fetch("https://www.google.com").then(r => console.log(`[*] Network Test: google.com -> ${r.status}`)).catch(e => console.log(`[!] Network Test: google.com -> FAILED (${e.message})`));
|
| 45 |
+
|
| 46 |
// Patch https.request to hijack all Discord-related domains
|
| 47 |
const _oldRequest = https.request;
|
| 48 |
https.request = function(options, callback) {
|
|
|
|
| 94 |
const _oldFetch = globalObj.fetch;
|
| 95 |
globalObj.fetch = async function(input, init) {
|
| 96 |
let urlStr = typeof input === 'string' ? input : (input.url || input.toString());
|
| 97 |
+
let newInit = { ...init };
|
| 98 |
+
if (!newInit.headers) newInit.headers = {};
|
| 99 |
+
|
| 100 |
+
// Spoof User-Agent
|
| 101 |
+
const UA = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36';
|
| 102 |
+
if (newInit.headers instanceof Headers) {
|
| 103 |
+
newInit.headers.set('User-Agent', UA);
|
| 104 |
+
} else if (Array.isArray(newInit.headers)) {
|
| 105 |
+
newInit.headers.push(['User-Agent', UA]);
|
| 106 |
+
} else {
|
| 107 |
+
newInit.headers['User-Agent'] = UA;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
try {
|
| 111 |
const url = new URL(urlStr);
|
| 112 |
const isDiscord = (h) => h && (h.includes('discord.com') || h.includes('discordapp.com') || h.includes('discordapp.net') || h.includes('dis.gd') || h.includes('discord.gg'));
|
|
|
|
| 115 |
if (isDiscord(url.hostname) && !isAsset(url.hostname)) {
|
| 116 |
url.hostname = DOMAINS[current_index];
|
| 117 |
}
|
| 118 |
+
return _oldFetch.call(this, url.toString(), newInit);
|
| 119 |
} catch (e) {
|
| 120 |
+
return _oldFetch.call(this, input, newInit);
|
| 121 |
}
|
| 122 |
};
|
| 123 |
}
|