chromium-proxy-settings/options.ts
Mathieu Strypsteen 8c50b3a9aa
All checks were successful
Build / build (push) Successful in 20s
Refactor
2024-02-18 12:08:41 +01:00

27 lines
1.2 KiB
TypeScript

function saveProxy() {
let active = (document.getElementById("proxyActive") as HTMLInputElement).checked;
const host = (document.getElementById("proxyHost") as HTMLInputElement).value;
const port = (document.getElementById("proxyPort") as HTMLInputElement).value;
const bypass = (document.getElementById("proxyBypass") as HTMLInputElement).value;
if (!host || !port) {
active = false;
(document.getElementById("proxyActive") as HTMLInputElement).checked = false;
}
chrome.storage.local.set({ active: active, host: host, port: Number(port), bypass: bypass.split("\n") });
}
window.addEventListener("DOMContentLoaded", async () => {
(document.getElementById("proxySettings") as HTMLInputElement).addEventListener("submit", saveProxy);
const { active, host, port, bypass } = await chrome.storage.local.get(["active", "host", "port", "bypass"]);
if (active) {
(document.getElementById("proxyActive") as HTMLInputElement).checked = active;
}
if (host) {
(document.getElementById("proxyHost") as HTMLInputElement).value = host;
}
if (port) {
(document.getElementById("proxyPort") as HTMLInputElement).value = port;
}
if (bypass) {
(document.getElementById("proxyBypass") as HTMLInputElement).value = bypass.join("\n");
}
});