chromium-proxy-settings/options.ts
Mathieu Strypsteen 7f52254c6b
All checks were successful
Build / build (push) Successful in 33s
Add eslint
2024-02-18 14:22:59 +01:00

34 lines
1.4 KiB
TypeScript

import { Storage } from './common';
async 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).valueAsNumber;
const bypass = (document.getElementById("proxyBypass") as HTMLInputElement).value;
if (!host || !port) {
active = false;
(document.getElementById("proxyActive") as HTMLInputElement).checked = false;
}
await chrome.storage.local.set({ active: active, host: host, port: port, bypass: bypass.split("\n") });
}
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;
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).valueAsNumber = port;
}
if (bypass) {
(document.getElementById("proxyBypass") as HTMLInputElement).value = bypass.join("\n");
}
}
window.addEventListener("DOMContentLoaded", () => {
void fillForm();
});