chromium-proxy-settings/options.ts

28 lines
1.2 KiB
TypeScript
Raw Normal View History

2024-02-18 08:28:00 +01:00
function setProxy() {
2024-02-18 10:27:44 +01:00
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;
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 10:27:44 +01:00
chrome.storage.local.set({ active: active, host: host, port: Number(port), bypass: bypass.split("\n") });
2024-02-18 08:28:00 +01:00
}
2024-02-18 10:27:44 +01:00
window.addEventListener("DOMContentLoaded", async () => {
(document.getElementById("proxySettings") as HTMLInputElement).addEventListener("submit", setProxy);
const { active, host, port, bypass } = await chrome.storage.local.get(["active", "host", "port", "bypass"]);
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) {
(document.getElementById("proxyPort") as HTMLInputElement).value = port;
}
2024-02-18 10:27:44 +01:00
if (bypass) {
(document.getElementById("proxyBypass") as HTMLInputElement).value = bypass.join("\n");
}
2024-02-18 08:28:00 +01:00
});