This commit is contained in:
song_xiao_lin
2024-05-15 14:43:04 +08:00
committed by go0p
parent 42b0e958ba
commit 523889014f
+6 -6
View File
@@ -41,8 +41,6 @@ setInterval(heartbeat, 3000)
console.info("Chrome Extenstion Background is loaded") console.info("Chrome Extenstion Background is loaded")
let proxyHost = "";
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) { chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.action === "connect") { if (msg.action === "connect") {
console.info("Start to connect websocket") console.info("Start to connect websocket")
@@ -65,15 +63,17 @@ chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
}, },
scope: 'regular', scope: 'regular',
}) })
proxyHost = `${msg.scheme}://${msg.host}:${msg.port}`
} else if (msg.action === 'clearproxy') { } else if (msg.action === 'clearproxy') {
chrome.proxy.settings.clear({}) chrome.proxy.settings.clear({})
proxyHost = ""
} else if (msg.action === 'proxystatus') { } else if (msg.action === 'proxystatus') {
if (proxyHost !== '') { chrome.proxy.settings.get({}, function (details) {
chrome.runtime.sendMessage({enable: !!proxyHost, proxy: proxyHost}) if (details.value && details.value.mode === "fixed_servers") {
let proxyConfig = details.value.rules.singleProxy;
chrome.runtime.sendMessage({ enable: true, proxy: `${proxyConfig.scheme}://${proxyConfig.host}:${proxyConfig.port}` })
} else { } else {
chrome.runtime.sendMessage({ enable: false, proxy: "" }) chrome.runtime.sendMessage({ enable: false, proxy: "" })
} }
});
} }
}) })