Files
2026-10-18 02:15:25 -05:00

36 lines
1.9 KiB
JavaScript

import { $, bg, askMaster, withUnlock, fingerprint, domainOfTab } from "./common.js";
const prompt = $("#prompt"), out = $("#out");
fingerprint(prompt.elements.master, prompt.querySelector(".fp"));
const [tab] = await browser.tabs.query({ active: true, currentWindow: true });
const site = domainOfTab(tab);
const say = (t, err) => { out.textContent = t; out.className = err ? "err" : ""; };
const ask = () => askMaster(prompt).then(state);
async function state() {
const { unlocked } = await bg("status");
$("#state").textContent = unlocked ? "Unlocked" : "Locked";
$("#lock").textContent = unlocked ? "Lock" : "Unlock";
$("#lock").onclick = unlocked ? () => bg("lock").then(state) : ask;
}
const btn = (text, fn) => Object.assign(document.createElement("button"), { textContent: text, onclick: fn });
const act = (fn) => async () => { try { await fn(); } catch (e) { say(e.message, true); } };
$("#dom").textContent = site || "No site";
$("#manager").onclick = () => { browser.tabs.create({ url: browser.runtime.getURL("manager.html") }); close(); };
state();
try {
const profiles = site ? (await bg("list")).profiles.filter((p) => p.site === site) : [];
$("#accounts").replaceChildren(...profiles.map((p) => {
const li = document.createElement("li");
li.className = "row";
li.append(Object.assign(document.createElement("span"), { className: "grow", textContent: p.login || "(no login)" }),
btn("Fill", act(async () => { await withUnlock("fill", { tabId: tab.id, profile: p }, ask); close(); })),
btn("Copy user", act(async () => { await navigator.clipboard.writeText(p.login); say("Username copied"); })),
btn("Copy pass", act(async () => { await withUnlock("copy", { profile: p }, ask); say("Password copied — clears in 30s"); })));
return li;
}));
if (site && !profiles.length) say(`No accounts for ${site}`);
} catch (e) { say(`Native host: ${e.message}`, true); }