Firefox WebExtension that lets you share the current tab to frontpage.fyi with minimal effort.
1const api = globalThis.browser ?? globalThis.chrome;
2
3const form = document.getElementById("login-form");
4const handleInput = document.getElementById("handle");
5const passwordInput = document.getElementById("password");
6const pdsInput = document.getElementById("pds");
7const loginBtn = document.getElementById("login-btn");
8const logoutBtn = document.getElementById("logout-btn");
9const statusEl = document.getElementById("auth-status");
10
11function setStatus(message, isError = false) {
12 statusEl.textContent = message;
13 statusEl.className = isError ? "status error" : "status success";
14}
15
16async function refreshAuthStatus() {
17 try {
18 const response = await api.runtime.sendMessage({ type: "frontpage-get-auth" });
19 if (!response?.auth) {
20 setStatus("Not connected. Save your handle and app password to enable posting.");
21 logoutBtn.disabled = true;
22 return;
23 }
24 const auth = response.auth;
25 handleInput.value = auth.handle ?? "";
26 pdsInput.value = auth.pds ?? "";
27 passwordInput.value = "";
28 logoutBtn.disabled = false;
29 setStatus(`Connected as ${auth.handle} (${auth.did}).`);
30 } catch (error) {
31 console.error("Unable to read auth state", error);
32 setStatus("Could not read authentication state.", true);
33 }
34}
35
36form.addEventListener("submit", async (event) => {
37 event.preventDefault();
38 setStatus("Signing in…");
39 loginBtn.disabled = true;
40 try {
41 const payload = {
42 handle: handleInput.value,
43 password: passwordInput.value,
44 pds: pdsInput.value
45 };
46 const response = await api.runtime.sendMessage({
47 type: "frontpage-login",
48 payload
49 });
50 if (!response?.ok) {
51 throw new Error(response?.error ?? "Unknown error");
52 }
53 passwordInput.value = "";
54 setStatus("Credentials saved.");
55 await refreshAuthStatus();
56 } catch (error) {
57 console.error("Login failed", error);
58 setStatus(error.message, true);
59 } finally {
60 loginBtn.disabled = false;
61 }
62});
63
64logoutBtn.addEventListener("click", async () => {
65 logoutBtn.disabled = true;
66 try {
67 await api.runtime.sendMessage({ type: "frontpage-logout" });
68 passwordInput.value = "";
69 pdsInput.value = "";
70 setStatus("Logged out.");
71 } catch (error) {
72 console.error("Logout failed", error);
73 setStatus(error.message, true);
74 } finally {
75 await refreshAuthStatus();
76 }
77});
78
79refreshAuthStatus();