Add files via upload
This commit is contained in:
parent
1ee06a5f6c
commit
8eb268753d
@ -74,12 +74,15 @@ function checkProxyFunctionality(proxy, callback) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use Mullvad's DNS server for privacy check
|
const controller = new AbortController();
|
||||||
fetch('https://doh.mullvad.net/dns-query?dns=q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB', {
|
const timeoutId = setTimeout(() => controller.abort(), 5000); // 5 second timeout
|
||||||
|
|
||||||
|
fetch('https://check.en.anyone.tech', {
|
||||||
mode: 'no-cors',
|
mode: 'no-cors',
|
||||||
headers: { 'accept': 'application/dns-message' }
|
signal: controller.signal
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
console.log("Proxy check successful");
|
console.log("Proxy check successful");
|
||||||
callback(true); // Connection successful
|
callback(true); // Connection successful
|
||||||
@ -89,7 +92,11 @@ function checkProxyFunctionality(proxy, callback) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error("Error in proxy check:", error);
|
if (error.name === 'AbortError') {
|
||||||
|
console.log("Request timed out");
|
||||||
|
} else {
|
||||||
|
console.error("Error in proxy check:", error);
|
||||||
|
}
|
||||||
callback(false);
|
callback(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -29,9 +29,12 @@ chrome.storage.local.get(["proxyIP", "proxyPort", "proxyType", "noProxyFor"], (s
|
|||||||
noProxyFor.value = settings.noProxyFor || "";
|
noProxyFor.value = settings.noProxyFor || "";
|
||||||
});
|
});
|
||||||
|
|
||||||
// Function to check internet connectivity
|
// Function to check internet connectivity with a timeout
|
||||||
function checkInternetConnection(host, port) {
|
function checkInternetConnection(host, port) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
const controller = new AbortController();
|
||||||
|
const timeoutId = setTimeout(() => controller.abort(), 5000); // 5 second timeout
|
||||||
|
|
||||||
const proxyConfig = {
|
const proxyConfig = {
|
||||||
mode: "fixed_servers",
|
mode: "fixed_servers",
|
||||||
rules: {
|
rules: {
|
||||||
@ -46,16 +49,18 @@ function checkInternetConnection(host, port) {
|
|||||||
|
|
||||||
chrome.proxy.settings.set({ value: proxyConfig, scope: "regular" }, () => {
|
chrome.proxy.settings.set({ value: proxyConfig, scope: "regular" }, () => {
|
||||||
if (chrome.runtime.lastError) {
|
if (chrome.runtime.lastError) {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
reject(chrome.runtime.lastError.message);
|
reject(chrome.runtime.lastError.message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
fetch('https://doh.mullvad.net/dns-query?dns=q80BAAABAAAAAAAAA3d3dwdleGFtcGxlA2NvbQAAAQAB', {
|
fetch('https://check.en.anyone.tech', {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
mode: 'no-cors',
|
mode: 'no-cors',
|
||||||
headers: { 'accept': 'application/dns-message' }
|
signal: controller.signal
|
||||||
})
|
})
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
clearTimeout(timeoutId);
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
resolve(true); // Connection successful
|
resolve(true); // Connection successful
|
||||||
} else {
|
} else {
|
||||||
@ -63,7 +68,12 @@ function checkInternetConnection(host, port) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
reject(error.message || "Network error encountered");
|
clearTimeout(timeoutId);
|
||||||
|
if (error.name === 'AbortError') {
|
||||||
|
reject("Connection timed out");
|
||||||
|
} else {
|
||||||
|
reject(error.message || "Network error encountered");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -109,8 +119,12 @@ function clearStatusMessage() {
|
|||||||
}, 5000); // Clear message after 5 seconds (5000 milliseconds)
|
}, 5000); // Clear message after 5 seconds (5000 milliseconds)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let isCheckingProxy = false;
|
||||||
|
|
||||||
// Save settings when clicking "Save Settings"
|
// Save settings when clicking "Save Settings"
|
||||||
saveSettings.addEventListener("click", () => {
|
saveSettings.addEventListener("click", () => {
|
||||||
|
if (isCheckingProxy) return; // If a check is already in progress, do nothing
|
||||||
|
|
||||||
if (!isValidIP(proxyIP.value)) {
|
if (!isValidIP(proxyIP.value)) {
|
||||||
statusMessage.textContent = "Invalid IP address.";
|
statusMessage.textContent = "Invalid IP address.";
|
||||||
statusMessage.style.color = "red";
|
statusMessage.style.color = "red";
|
||||||
@ -134,6 +148,10 @@ saveSettings.addEventListener("click", () => {
|
|||||||
statusMessage.style.fontFamily = "Arial";
|
statusMessage.style.fontFamily = "Arial";
|
||||||
statusMessage.style.fontWeight = "bold";
|
statusMessage.style.fontWeight = "bold";
|
||||||
|
|
||||||
|
// Disable the saveSettings button
|
||||||
|
saveSettings.disabled = true;
|
||||||
|
isCheckingProxy = true;
|
||||||
|
|
||||||
const noProxyExceptions = noProxyFor.value.split(',').map(ex => ex.trim());
|
const noProxyExceptions = noProxyFor.value.split(',').map(ex => ex.trim());
|
||||||
const filteredExceptions = noProxyExceptions.filter(ex => ex !== '');
|
const filteredExceptions = noProxyExceptions.filter(ex => ex !== '');
|
||||||
|
|
||||||
@ -171,6 +189,11 @@ saveSettings.addEventListener("click", () => {
|
|||||||
statusMessage.style.fontFamily = "Arial";
|
statusMessage.style.fontFamily = "Arial";
|
||||||
statusMessage.style.fontWeight = "bold";
|
statusMessage.style.fontWeight = "bold";
|
||||||
chrome.proxy.settings.clear({});
|
chrome.proxy.settings.clear({});
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
// Re-enable the saveSettings button after the check is complete
|
||||||
|
saveSettings.disabled = false;
|
||||||
|
isCheckingProxy = false;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user