26 lines
808 B
TypeScript
26 lines
808 B
TypeScript
import { Storage } from './common';
|
|
|
|
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");
|
|
if (!active) {
|
|
chrome.proxy.settings.clear({ scope: "regular" }, function () { });
|
|
await chrome.action.setBadgeText({ text: "" });
|
|
return;
|
|
}
|
|
const config = {
|
|
mode: "fixed_servers",
|
|
rules: {
|
|
singleProxy: {
|
|
scheme: "socks5",
|
|
host: host,
|
|
port: port
|
|
},
|
|
bypassList: bypass
|
|
}
|
|
};
|
|
chrome.proxy.settings.set({ value: config, scope: "regular" }, function () { });
|
|
await chrome.action.setBadgeText({ text: "✓" });
|
|
}
|
|
chrome.storage.onChanged.addListener(() => { void applyProxy(); });
|
|
void applyProxy();
|