-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoptions.html
More file actions
489 lines (447 loc) · 18.2 KB
/
options.html
File metadata and controls
489 lines (447 loc) · 18.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; img-src 'self' chrome: chrome-extension: moz-extension: data:; style-src 'self' 'unsafe-inline'; script-src 'self';"
/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>UVCS — Options</title>
<style>
:root {
--bg: #0b0f14;
--panel: #11161d;
--card: #141b24;
--muted: #8aa0b2;
--text: #e5eef5;
--accent: #66d9ef;
--ok: #22c55e;
--warn: #f59e0b;
--err: #ef4444;
--border: #1f2937;
--chip: #1d2530;
--radius: 14px;
}
* { box-sizing: border-box; }
html, body {
margin: 0; padding: 0; background: var(--bg); color: var(--text); font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial;
}
.container { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
header {
display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px;
}
h1 { font-size: 22px; margin: 0; letter-spacing: .2px; }
.chip {
padding: 6px 10px; background: var(--chip); border: 1px solid var(--border);
border-radius: 999px; color: var(--muted); font-size: 12px;
}
.grid {
display: grid; grid-template-columns: 360px 1fr; gap: 16px;
}
@media (max-width: 960px) { .grid { grid-template-columns: 1fr; } }
.panel {
background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px;
}
.panel h2 { font-size: 16px; margin: 0 0 10px 0; color: var(--muted); font-weight: 600; }
.row { display: grid; grid-template-columns: 180px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px dashed #1b2530; }
.row:last-child { border-bottom: 0; }
.row label { color: var(--muted); font-size: 13px; }
.row input[type="text"], .row input[type="number"], .row textarea, .row select {
width: 100%; background: var(--card); color: var(--text);
border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; font-size: 14px;
}
.row textarea { min-height: 70px; resize: vertical; }
.switch { display: inline-flex; align-items: center; gap: 10px; }
.switch input { transform: scale(1.1); }
.btns { display: flex; gap: 8px; flex-wrap: wrap; }
button {
background: var(--card); color: var(--text); border: 1px solid var(--border);
padding: 8px 12px; border-radius: 10px; cursor: pointer; font-size: 14px;
}
button.primary { border-color: #2b3b4d; background: #0f1520; }
button.ok { border-color: #1f4730; background: #0f1a14; color: #96f2b1; }
button.warn { border-color: #5b3b10; background: #1a140f; color: #ffd08a; }
button:disabled { opacity: .6; cursor: not-allowed; }
/* History list */
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.toolbar input[type="text"] { width: 320px; }
.history {
background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 8px;
max-height: 70vh; overflow: auto;
}
.day { padding: 8px 10px; color: var(--muted); font-size: 12px; position: sticky; top: 0; background: var(--panel); border-bottom: 1px solid var(--border); }
.item {
display: grid; grid-template-columns: 28px 1fr auto; align-items: center; gap: 10px;
padding: 10px; border-radius: 12px; border: 1px solid transparent;
}
.item:hover { background: #121925; border-color: #1b2836; }
.favicon { width: 16px; height: 16px; border-radius: 3px; }
.url {
font-weight: 600; font-size: 14px; line-height: 1.2; max-width: 600px;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.meta { font-size: 12px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.status { font-size: 11px; padding: 2px 6px; border-radius: 6px; background: #0f1420; border: 1px solid #1f2a3a; color: #a6c8ff; }
.duration { color: #9dd6b7; }
.right { display: flex; gap: 8px; align-items: center; }
.mini-btn {
font-size: 12px; padding: 4px 8px; border-radius: 8px; background: #0f1520; border: 1px solid #203044; color: #c1d7e9;
}
/* Custom context menu */
.ctx {
position: fixed; z-index: 9999; background: #0c121b; border: 1px solid #1e293b; border-radius: 10px; min-width: 190px; box-shadow: 0 10px 30px rgba(0,0,0,.35); display: none;
}
.ctx .cx-row { padding: 10px 12px; cursor: pointer; font-size: 14px; color: #dbe7f3; }
.ctx .cx-row:hover { background: #111a26; }
.toast {
position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
background: #0f1420; border: 1px solid #203045; color: #e2efff; padding: 10px 14px; border-radius: 10px; display: none;
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>URL Version Control System — Options</h1>
<div class="chip" id="statusChip">Idle</div>
</header>
<div class="grid">
<!-- Left: Settings -->
<section class="panel">
<h2>Settings</h2>
<div class="row">
<label>Recording</label>
<div class="switch"><input type="checkbox" id="recToggle" /> <span id="recLabel">Off</span></div>
</div>
<div class="row">
<label>Dwell threshold (seconds)</label>
<input type="number" id="dwellSec" min="1" step="1" placeholder="e.g., 10" />
</div>
<div class="row">
<label>Capture snapshots</label>
<div class="switch"><input type="checkbox" id="snapToggle" /> <span>Capture cleaned page snapshots (opt-in)</span></div>
</div>
<div class="row">
<label>Retention (days)</label>
<input type="number" id="retentionDays" min="1" step="1" placeholder="e.g., 90" />
</div>
<div class="row">
<label>Ignore hosts (one per line)</label>
<textarea id="ignoreHosts" placeholder="localhost
accounts.google.com
bank.example.com"></textarea>
</div>
<div class="row" style="align-items:center">
<label>Data</label>
<div class="btns">
<button id="exportBtn" class="primary">Export JSON</button>
<label class="primary" style="display:inline-flex; align-items:center; gap:8px; padding:8px 12px; border:1px solid var(--border); border-radius:10px; cursor:pointer;">
<input id="importFile" type="file" accept="application/json" style="display:none" />
Import JSON
</label>
<button id="clearBtn" class="warn">Clear All</button>
</div>
</div>
</section>
<!-- Right: History -->
<section>
<div class="panel">
<h2>History</h2>
<div class="toolbar">
<input id="searchBox" type="text" placeholder="Search URL or title…" />
<select id="domainFilter">
<option value="">All domains</option>
</select>
<button id="refreshBtn" class="mini-btn">Refresh</button>
</div>
<div class="history" id="historyList">
<!-- Filled by JS -->
</div>
</div>
</section>
</div>
</div>
<!-- Custom context menu -->
<div class="ctx" id="ctxMenu">
<div class="cx-row" data-action="open">Open in new tab</div>
<div class="cx-row" data-action="copy">Copy link</div>
<div class="cx-row" data-action="snapshot">View snapshot</div>
</div>
<div class="toast" id="toast"></div>
<script>
// Cross-browser API pick
const api = (typeof chrome !== 'undefined') ? chrome : browser;
// ----- Helpers -----
const el = (id) => document.getElementById(id);
const statusChip = el('statusChip');
const recToggle = el('recToggle'); const recLabel = el('recLabel');
const dwellSec = el('dwellSec'); const snapToggle = el('snapToggle');
const retentionDays = el('retentionDays'); const ignoreHosts = el('ignoreHosts');
const exportBtn = el('exportBtn'); const importFile = el('importFile'); const clearBtn = el('clearBtn');
const searchBox = el('searchBox'); const domainFilter = el('domainFilter');
const refreshBtn = el('refreshBtn'); const historyList = el('historyList');
const ctxMenu = el('ctxMenu'); const toast = el('toast');
const SHORT_LEN = 68; // characters shown in the list before "…"
let visits = []; // cached
let edges = []; // if background provides them
let ctxTarget = null; // stores the clicked item’s data
function fmtDate(ts) {
const d = new Date(ts);
return d.toLocaleString();
}
function shortUrl(u, max = SHORT_LEN) {
try {
const { host, pathname } = new URL(u);
const display = host + pathname;
if (display.length <= max) return display;
return display.slice(0, max) + '…';
} catch { return u.length > max ? (u.slice(0, max) + '…') : u; }
}
function faviconSrc(u) {
try {
// Chromium/Firefox support chrome://favicon for extensions
return `chrome://favicon/${u}`;
} catch { return ''; }
}
function groupByDay(items) {
const map = new Map();
for (const v of items) {
const d = new Date(v.ts);
const key = d.toLocaleDateString();
if (!map.has(key)) map.set(key, []);
map.get(key).push(v);
}
return Array.from(map.entries());
}
function showToast(msg, ms = 2000) {
toast.textContent = msg;
toast.style.display = 'block';
setTimeout(() => { toast.style.display = 'none'; }, ms);
}
// ----- Load & Save Settings -----
async function loadSettings() {
return new Promise(resolve => {
api.storage.local.get(['recording','dwellMs','snapshots','retentionDays','ignoreHosts'], (obj) => {
recToggle.checked = (typeof obj.recording === 'boolean') ? obj.recording : true;
recLabel.textContent = recToggle.checked ? 'On' : 'Off';
dwellSec.value = Math.max(1, Math.round((obj.dwellMs || 10000)/1000));
snapToggle.checked = !!obj.snapshots;
retentionDays.value = obj.retentionDays || 90;
ignoreHosts.value = (obj.ignoreHosts || []).join('\n');
resolve();
});
});
}
async function saveSetting(key, value) {
await api.storage.local.set({ [key]: value });
statusChip.textContent = 'Saved';
setTimeout(() => statusChip.textContent = 'Idle', 800);
}
// ----- Visit Data -----
async function fetchVisits() {
// Uses your background message “uvcs.query” (from your earlier scaffold)
return new Promise((resolve) => {
api.runtime.sendMessage({ type: 'uvcs.query' }, (res) => {
if (!res) { resolve({ visits: [], edges: [] }); return; }
resolve({ visits: res.visits || [], edges: res.edges || [] });
});
});
}
function applyFilters(items) {
const q = (searchBox.value || '').toLowerCase().trim();
const dom = domainFilter.value;
return items.filter(v => {
const okQ = !q || (String(v.url).toLowerCase().includes(q) || String(v.title||'').toLowerCase().includes(q));
const okD = !dom || (new URL(v.url).host === dom);
return okQ && okD;
});
}
function populateDomainFilter(items) {
const uniq = Array.from(new Set(items.map(v => {
try { return new URL(v.url).host; } catch { return ''; }
}).filter(Boolean))).sort();
domainFilter.innerHTML = `<option value="">All domains</option>` + uniq.map(h => `<option value="${h}">${h}</option>`).join('');
}
function renderHistory() {
const items = applyFilters(visits).sort((a,b) => b.ts - a.ts);
const byDay = groupByDay(items);
historyList.innerHTML = '';
for (const [day, arr] of byDay) {
const dayDiv = document.createElement('div');
dayDiv.className = 'day';
dayDiv.textContent = day;
historyList.appendChild(dayDiv);
for (const v of arr) {
const row = document.createElement('div');
row.className = 'item';
row.dataset.url = v.url;
row.dataset.id = v.id;
// favicon
const ic = document.createElement('img');
ic.className = 'favicon';
ic.src = faviconSrc(v.url);
row.appendChild(ic);
// main content
const main = document.createElement('div');
const urlDiv = document.createElement('div');
urlDiv.className = 'url';
urlDiv.title = v.url;
urlDiv.textContent = shortUrl(v.url);
main.appendChild(urlDiv);
const meta = document.createElement('div');
meta.className = 'meta';
const ts = document.createElement('span');
ts.textContent = fmtDate(v.ts);
const kind = document.createElement('span');
kind.className = 'status';
kind.textContent = v.kind || v.transition || 'visit';
const dur = document.createElement('span');
if (v.durationMs) {
dur.className = 'duration';
dur.textContent = `• ${Math.round(v.durationMs/1000)}s`;
}
meta.appendChild(ts);
meta.appendChild(kind);
if (v.httpStatus) {
const st = document.createElement('span');
st.className = 'status';
st.textContent = `HTTP ${v.httpStatus}`;
meta.appendChild(st);
}
if (dur.textContent) meta.appendChild(dur);
main.appendChild(meta);
row.appendChild(main);
// right-side quick actions
const right = document.createElement('div');
right.className = 'right';
const openBtn = document.createElement('button');
openBtn.className = 'mini-btn';
openBtn.textContent = 'Open';
openBtn.addEventListener('click', () => api.tabs.create({ url: v.url }));
const snapBtn = document.createElement('button');
snapBtn.className = 'mini-btn';
snapBtn.textContent = 'Snapshot';
snapBtn.addEventListener('click', () => viewSnapshot(v.id));
right.appendChild(openBtn);
right.appendChild(snapBtn);
row.appendChild(right);
// Right-click context menu
row.addEventListener('contextmenu', (ev) => {
ev.preventDefault();
ctxTarget = v;
ctxMenu.style.display = 'block';
const pad = 4;
const mx = Math.min(ev.clientX, window.innerWidth - ctxMenu.offsetWidth - pad);
const my = Math.min(ev.clientY, window.innerHeight - ctxMenu.offsetHeight - pad);
ctxMenu.style.left = mx + 'px';
ctxMenu.style.top = my + 'px';
});
historyList.appendChild(row);
}
}
}
// ----- Context menu actions -----
document.addEventListener('click', () => { ctxMenu.style.display = 'none'; });
ctxMenu.addEventListener('click', (e) => {
const action = e.target?.dataset?.action;
if (!action || !ctxTarget) return;
if (action === 'open') {
api.tabs.create({ url: ctxTarget.url });
} else if (action === 'copy') {
navigator.clipboard.writeText(ctxTarget.url).then(() => showToast('Link copied'));
} else if (action === 'snapshot') {
viewSnapshot(ctxTarget.id);
}
ctxMenu.style.display = 'none';
});
async function viewSnapshot(visitId) {
// Expect background to answer with { html } or { url } or { error }
api.runtime.sendMessage({ type: 'uvcs.snapshot.get', visitId }, (res) => {
if (!res || res.error) { showToast('No snapshot available'); return; }
if (res.url) {
api.tabs.create({ url: res.url });
return;
}
if (res.html) {
const blob = new Blob([res.html], { type: 'text/html;charset=utf-8' });
const url = URL.createObjectURL(blob);
api.tabs.create({ url });
} else {
showToast('No snapshot available');
}
});
}
// ----- Bind settings events -----
recToggle.addEventListener('change', () => {
recLabel.textContent = recToggle.checked ? 'On' : 'Off';
api.runtime.sendMessage({ type: 'uvcs.toggle', enabled: recToggle.checked });
saveSetting('recording', recToggle.checked);
});
dwellSec.addEventListener('change', () => {
const ms = Math.max(1, Number(dwellSec.value)) * 1000;
saveSetting('dwellMs', ms);
});
snapToggle.addEventListener('change', () => saveSetting('snapshots', snapToggle.checked));
retentionDays.addEventListener('change', () => saveSetting('retentionDays', Math.max(1, Number(retentionDays.value))));
ignoreHosts.addEventListener('blur', () => {
const list = ignoreHosts.value.split(/\r?\n/).map(s => s.trim()).filter(Boolean);
saveSetting('ignoreHosts', list);
});
// ----- Data buttons -----
exportBtn.addEventListener('click', async () => {
const data = { visits, edges, exportedAt: new Date().toISOString(), app: 'uvcs' };
const blob = new Blob([JSON.stringify(data, null, 2)], { type: 'application/json' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.download = `uvcs-export-${Date.now()}.json`;
a.href = url; a.click();
setTimeout(() => URL.revokeObjectURL(url), 3000);
});
importFile.addEventListener('change', async () => {
const file = importFile.files[0];
if (!file) return;
const text = await file.text();
let json;
try { json = JSON.parse(text); } catch { showToast('Invalid JSON'); return; }
// Ask background to handle import if you have an API; otherwise store locally for now
api.runtime.sendMessage({ type: 'uvcs.import', payload: json }, (res) => {
if (res && res.ok) {
showToast('Imported');
reload();
} else {
showToast('Import not supported by background');
}
});
});
clearBtn.addEventListener('click', () => {
if (!confirm('Clear all stored visits? This cannot be undone.')) return;
api.runtime.sendMessage({ type: 'uvcs.clear' }, (res) => {
if (res && res.ok) {
visits = []; edges = []; renderHistory();
showToast('Cleared');
} else {
showToast('Background did not clear data');
}
});
});
// ----- Reload pipeline -----
async function reload() {
statusChip.textContent = 'Loading…';
await loadSettings();
const res = await fetchVisits();
visits = Array.isArray(res.visits) ? res.visits : [];
edges = Array.isArray(res.edges) ? res.edges : [];
populateDomainFilter(visits);
renderHistory();
statusChip.textContent = 'Idle';
}
// Initial
reload();
// Live re-render on search/filter
searchBox.addEventListener('input', renderHistory);
domainFilter.addEventListener('change', renderHistory);
refreshBtn.addEventListener('click', reload);
</script>
</body>
</html>