mirror of
https://github.com/yaklang/yaklang-chrome-extension.git
synced 2026-09-26 21:21:53 +08:00
add inject code
This commit is contained in:
+45
-34
@@ -8,41 +8,52 @@ const websocketManager = new WebSocketManager();
|
||||
|
||||
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
|
||||
console.log("msg", msg)
|
||||
if (msg.action === ActionType.CONNECT) {
|
||||
console.info("Start to connect websocket")
|
||||
const host = msg['host'] || "127.0.0.1"
|
||||
const port = msg['port'] || 11212
|
||||
websocketManager.connectWebsocket(`ws://${host}:${port}/?token=${"a"}`)
|
||||
} else if (msg.action === ActionType.DISCONNECT) {
|
||||
websocketManager.disconnectWebsocket()
|
||||
} else if (msg.action === ActionType.SETPROXY) {
|
||||
chrome.proxy.settings.set({
|
||||
value: {
|
||||
mode: "fixed_servers",
|
||||
rules: {
|
||||
singleProxy: {
|
||||
scheme: msg.scheme,
|
||||
host: msg.host,
|
||||
port: parseInt(`${msg.port}`)
|
||||
switch (msg.action) {
|
||||
case ActionType.CONNECT:
|
||||
console.info("Start to connect websocket")
|
||||
const host = msg['host'] || "127.0.0.1"
|
||||
const port = msg['port'] || 11212
|
||||
websocketManager.connectWebsocket(`ws://${host}:${port}/?token=${"a"}`)
|
||||
break;
|
||||
case ActionType.DISCONNECT:
|
||||
websocketManager.disconnectWebsocket();
|
||||
break;
|
||||
case ActionType.SETPROXY:
|
||||
chrome.proxy.settings.set({
|
||||
value: {
|
||||
mode: "fixed_servers",
|
||||
rules: {
|
||||
singleProxy: {
|
||||
scheme: msg.scheme,
|
||||
host: msg.host,
|
||||
port: parseInt(`${msg.port}`)
|
||||
}
|
||||
}
|
||||
},
|
||||
scope: 'regular',
|
||||
});
|
||||
break;
|
||||
case ActionType.CLEARPROXY:
|
||||
chrome.proxy.settings.clear({})
|
||||
break;
|
||||
case ActionType.PROXYSTATUS:
|
||||
chrome.proxy.settings.get({}, function (details) {
|
||||
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 {
|
||||
chrome.runtime.sendMessage({enable: false, proxy: ""})
|
||||
}
|
||||
},
|
||||
scope: 'regular',
|
||||
})
|
||||
|
||||
} else if (msg.action === ActionType.CLEARPROXY) {
|
||||
chrome.proxy.settings.clear({})
|
||||
} else if (msg.action === ActionType.PROXYSTATUS) {
|
||||
chrome.proxy.settings.get({}, function (details) {
|
||||
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 {
|
||||
chrome.runtime.sendMessage({enable: false, proxy: ""})
|
||||
}
|
||||
});
|
||||
});
|
||||
break;
|
||||
}
|
||||
})
|
||||
|
||||
chrome.tabs.query({}, (tabs) => {
|
||||
tabs.forEach(function (tab) {
|
||||
console.log("Tab ID",tab.id); // 输出每个标签页的ID
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user