Files
2026-10-21 20:40:39 -04:00

65 lines
1.6 KiB
JavaScript

"use strict";
const list = document.getElementById("profiles");
const status = document.getElementById("status");
function showError(text) {
status.className = "error";
status.textContent = text;
}
async function init() {
let profiles;
try {
profiles = await listProfiles();
} catch (e) {
showError(
`Cannot reach the native host (${e.message}). Run host/install.sh, then reload this page.`
);
return;
}
if (!profiles.length) {
showError("No profiles found in ~/.mozilla/firefox/Profile Groups.");
return;
}
const { targetPath } = await browser.storage.local.get("targetPath");
for (const profile of profiles) {
const li = document.createElement("li");
const label = document.createElement("label");
const radio = document.createElement("input");
radio.type = "radio";
radio.name = "target";
radio.value = profile.path;
radio.checked = profile.path === targetPath;
radio.addEventListener("change", async () => {
await browser.storage.local.set({ targetPath: profile.path });
status.className = "";
status.textContent = `Saved: ${profile.name}`;
});
const img = document.createElement("img");
img.alt = "";
const src = avatarDataURL(profile, "48");
if (src) {
img.src = src;
}
const text = document.createElement("div");
const name = document.createElement("div");
name.textContent = profile.name;
const path = document.createElement("div");
path.className = "path";
path.textContent = profile.path;
text.append(name, path);
label.append(radio, img, text);
li.append(label);
list.append(li);
}
}
init();