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 = '';
browser.storage.sync.get('serverUrl').then(r => {
if (r.serverUrl) serverUrl = r.serverUrl.replace(/\/+$/, '');
});
function norm(v) {
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 => {
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) {
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.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) {
const err = await res.json().catch(() => ({}));
throw new Error(err.detail || 'HTTP ' + res.status);

View File

@@ -114,12 +114,19 @@
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) {
serverUrl = (r.serverUrl || '').replace(/\/+$/, '');
if (!serverUrl) showStatus('Set the server URL in Options', false);
updateIndicator();
loadUsers();
});
loadUsers();
captureContext();
noteEl.focus();
})();