aboutsummaryrefslogtreecommitdiff
path: root/src/options/options.ts
blob: 8574ab8389ecfbacdc72e75d3a80e71adebd0c98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
type Settings = {
  proxyEndpoint?: string;
  proxyToken?: string;
};

const endpointInput: HTMLInputElement = document.getElementById("endpoint") as HTMLInputElement;
const tokenInput: HTMLInputElement = document.getElementById("token") as HTMLInputElement;
const saveBtn: HTMLButtonElement = document.getElementById("save") as HTMLButtonElement;
const msg: HTMLElement = document.getElementById("msg") as HTMLElement;

async function loadSettings(): Promise<void> {
  const settings: Settings = await browser.storage.local.get(["proxyEndpoint", "proxyToken"]);
  endpointInput.value = settings.proxyEndpoint ?? "";
  tokenInput.value = settings.proxyToken ?? "";
}

async function saveSettings(): Promise<void> {
  await browser.storage.local.set({
    proxyEndpoint: endpointInput.value.trim(),
    proxyToken: tokenInput.value.trim(),
  });
  msg.textContent = "Saved!";
  setTimeout(() => (msg.textContent = ""), 2000);
}

saveBtn.addEventListener("click", saveSettings);
loadSettings();