This commit is contained in:
2026-09-23 13:51:53 -07:00
parent 6ea3f19b29
commit 163cad4f5f
4 changed files with 37 additions and 9 deletions

View File

@@ -1,12 +1,18 @@
let serverUrl = ''; let serverUrl = '';
browser.storage.sync.get('serverUrl').then(r => { function norm(v) {
if (r.serverUrl) serverUrl = r.serverUrl.replace(/\/+$/, ''); return (v || '').replace(/\/+$/, '');
}); }
async function getServerUrl() {
const r = await browser.storage.sync.get('serverUrl');
serverUrl = norm(r.serverUrl);
return serverUrl;
}
browser.storage.onChanged.addListener(changes => { browser.storage.onChanged.addListener(changes => {
if (changes.serverUrl) { if (changes.serverUrl) {
serverUrl = changes.serverUrl.newValue.replace(/\/+$/, ''); serverUrl = norm(changes.serverUrl.newValue);
} }
}); });
@@ -22,10 +28,18 @@ browser.runtime.onMessage.addListener((msg, sender) => {
}); });
async function request(path, opts) { async function request(path, opts) {
if (!serverUrl) throw new Error('Server URL not configured'); const base = await getServerUrl();
if (!base) {
throw new Error('Server URL not set — open snotes and click "Capture" → "Apply to Extension", or set it in Options');
}
opts = opts || {}; opts = opts || {};
opts.credentials = 'include'; opts.credentials = 'include';
const res = await fetch(serverUrl + path, opts); let res;
try {
res = await fetch(base + path, opts);
} catch (e) {
throw new Error('Cannot reach ' + base + ' (' + e.message + ')');
}
if (!res.ok) { if (!res.ok) {
const err = await res.json().catch(() => ({})); const err = await res.json().catch(() => ({}));
throw new Error(err.detail || 'HTTP ' + res.status); throw new Error(err.detail || 'HTTP ' + res.status);

View File

@@ -114,12 +114,19 @@
browser.runtime.openOptionsPage(); browser.runtime.openOptionsPage();
}); });
function updateIndicator() {
var el = document.getElementById('server-indicator');
var display = serverUrl ? serverUrl.replace(/^https?:\/\//, '') : 'Set server URL…';
el.textContent = display;
el.title = serverUrl || '';
}
browser.storage.sync.get('serverUrl').then(function (r) { browser.storage.sync.get('serverUrl').then(function (r) {
serverUrl = (r.serverUrl || '').replace(/\/+$/, ''); serverUrl = (r.serverUrl || '').replace(/\/+$/, '');
if (!serverUrl) showStatus('Set the server URL in Options', false); updateIndicator();
loadUsers();
}); });
loadUsers();
captureContext(); captureContext();
noteEl.focus(); noteEl.focus();
})(); })();

View File

@@ -327,6 +327,10 @@ body {
.tools-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; } .tools-row { display: flex; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.tools-row .muted { min-height: 1.2em; } .tools-row .muted { min-height: 1.2em; }
.tools-head { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.tools-head h1 { margin: 0; }
.tools-logo { height: 40px; width: auto; }
.login-card { .login-card {
display: flex; display: flex;
flex-direction: column; flex-direction: column;

View File

@@ -254,7 +254,10 @@ function showTools() {
const qsApply = el("button", { class: "btn", text: "Apply to Extension" }); const qsApply = el("button", { class: "btn", text: "Apply to Extension" });
const card = el("div", { class: "help-card" }, [ const card = el("div", { class: "help-card" }, [
el("h1", { text: "Quick capture" }), el("div", { class: "tools-head" }, [
el("img", { src: "/static/snotes-logo.png", class: "tools-logo", alt: "quickSnote" }),
el("h1", { text: "Quick capture" }),
]),
el("p", { html: 'The <b>quickSnote</b> browser extension lets you jot a note from any page. It prefills the note with the text you\'ve selected, and a <b>Page</b> button inserts the current page\'s title and link.' }), el("p", { html: 'The <b>quickSnote</b> browser extension lets you jot a note from any page. It prefills the note with the text you\'ve selected, and a <b>Page</b> button inserts the current page\'s title and link.' }),
el("h2", { text: "Firefox" }), el("h2", { text: "Firefox" }),