-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
45 lines (35 loc) · 1.12 KB
/
popup.js
File metadata and controls
45 lines (35 loc) · 1.12 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
const webExt = typeof browser !== 'undefined' ? browser : chrome;
async function exportHistory() {
const statusEl = document.getElementById('status');
try {
statusEl.textContent = 'Starting export...';
const response = await webExt.runtime.sendMessage({
action: 'exportHistory'
});
if (response && response.ok === false) {
statusEl.textContent = `Export failed: ${response.error || 'Unknown error'}`;
return;
}
statusEl.textContent = 'Download started.';
} catch (error) {
const message = error?.message || String(error);
if (/cancel/i.test(message)) {
statusEl.textContent = 'Download canceled.';
} else {
statusEl.textContent = `Export failed: ${message}`;
}
}
}
function setupPopup() {
const exportButton = document.getElementById('exportBtn');
const statusEl = document.getElementById('status');
if (!exportButton || !statusEl) {
return;
}
exportButton.addEventListener('click', exportHistory);
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', setupPopup, { once: true });
} else {
setupPopup();
}