chromium-proxy-settings/options.ts

23 lines
1 KiB
TypeScript

function setProxy() {
let active = (document.getElementById('proxyActive') as HTMLInputElement).checked;
const host = (document.getElementById('proxyHost') as HTMLInputElement).value;
const port = (document.getElementById('proxyPort') 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) });
}
window.addEventListener('DOMContentLoaded', async () => {
(document.getElementById("proxySettings") as HTMLInputElement).addEventListener('submit', setProxy);
const { active, host, port } = await chrome.storage.local.get(["active", "host", "port"]);
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;
}
});