chromium-proxy-settings/worker.ts

27 lines
808 B
TypeScript
Raw Permalink Normal View History

2024-02-18 14:10:13 +01:00
import { Storage } from './common';
2024-02-18 12:08:41 +01:00
async function applyProxy() {
const { host, port, bypass } = await chrome.storage.local.get(["host", "port", "bypass"]) as Storage;
const { active } = await chrome.storage.session.get("active");
2024-02-18 08:28:00 +01:00
if (!active) {
2024-02-18 10:27:44 +01:00
chrome.proxy.settings.clear({ scope: "regular" }, function () { });
2024-02-19 12:17:44 +01:00
await chrome.action.setBadgeText({ text: "" });
2024-02-18 08:28:00 +01:00
return;
}
const config = {
mode: "fixed_servers",
rules: {
singleProxy: {
scheme: "socks5",
host: host,
port: port
2024-02-18 10:27:44 +01:00
},
bypassList: bypass
2024-02-18 08:28:00 +01:00
}
};
2024-02-18 10:27:44 +01:00
chrome.proxy.settings.set({ value: config, scope: "regular" }, function () { });
2024-02-19 12:17:44 +01:00
await chrome.action.setBadgeText({ text: "✓" });
2024-02-18 08:28:00 +01:00
}
2024-02-18 14:10:13 +01:00
chrome.storage.onChanged.addListener(() => { void applyProxy(); });
void applyProxy();