add proxy

This commit is contained in:
v1ll4n
2024-03-21 11:08:42 +08:00
parent 96141b9d30
commit bb584fc7d1
5 changed files with 137 additions and 5 deletions
+26
View File
@@ -41,6 +41,8 @@ setInterval(heartbeat, 3000)
console.info("Chrome Extenstion Background is loaded")
let proxyHost = "";
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
if (msg.action === "connect") {
console.info("Start to connect websocket")
@@ -55,5 +57,29 @@ chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
} else {
chrome.runtime.sendMessage({connected: false})
}
} else if (msg.action === 'setproxy') {
chrome.proxy.settings.set({
value: {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: msg.scheme,
host: msg.host,
port: parseInt(`${msg.port}`)
}
}
},
scope: 'regular',
})
proxyHost = `${msg.scheme}://${msg.host}:${msg.port}`
} else if (msg.action === 'clearproxy') {
chrome.proxy.settings.clear({})
proxyHost = ""
} else if (msg.action === 'proxystatus') {
if (proxyHost !== '') {
chrome.runtime.sendMessage({enable: !!proxyHost, proxy: proxyHost})
} else {
chrome.runtime.sendMessage({enable: false, proxy: ""})
}
}
})