chromium-proxy-settings/options.ts

35 lines
1.4 KiB
TypeScript
Raw Normal View History

2024-02-18 14:10:13 +01:00
import { Storage } from './common';
async function saveProxy() {
2024-02-18 10:27:44 +01:00
let active = (document.getElementById("proxyActive") as HTMLInputElement).checked;
const host = (document.getElementById("proxyHost") as HTMLInputElement).value;
2024-02-18 14:10:13 +01:00
const port = (document.getElementById("proxyPort") as HTMLInputElement).valueAsNumber;
2024-02-18 10:27:44 +01:00
const bypass = (document.getElementById("proxyBypass") as HTMLInputElement).value;
2024-02-18 08:28:00 +01:00
if (!host || !port) {
active = false;
2024-02-18 10:27:44 +01:00
(document.getElementById("proxyActive") as HTMLInputElement).checked = false;
2024-02-18 08:28:00 +01:00
}
2024-02-18 14:10:13 +01:00
await chrome.storage.local.set({ active: active, host: host, port: port, bypass: bypass.split("\n") });
2024-02-18 08:28:00 +01:00
}
2024-02-18 14:10:13 +01:00
async function fillForm() {
(document.getElementById("proxySettings") as HTMLInputElement).addEventListener("submit", () => {
void saveProxy();
});
const { active, host, port, bypass } = await chrome.storage.local.get(["active", "host", "port", "bypass"]) as Storage;
2024-02-18 08:28:00 +01:00
if (active) {
(document.getElementById("proxyActive") as HTMLInputElement).checked = active;
}
if (host) {
(document.getElementById("proxyHost") as HTMLInputElement).value = host;
}
if (port) {
2024-02-18 14:10:13 +01:00
(document.getElementById("proxyPort") as HTMLInputElement).valueAsNumber = port;
2024-02-18 08:28:00 +01:00
}
2024-02-18 10:27:44 +01:00
if (bypass) {
(document.getElementById("proxyBypass") as HTMLInputElement).value = bypass.join("\n");
}
2024-02-18 14:10:13 +01:00
}
window.addEventListener("DOMContentLoaded", () => {
void fillForm();
2024-02-18 08:28:00 +01:00
});