-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
60 lines (50 loc) · 1.73 KB
/
popup.js
File metadata and controls
60 lines (50 loc) · 1.73 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
// popup.js — Shows 3 most recent notifications, respects theme
// Apply theme from storage (fallback for popup which may not share localStorage)
chrome.storage.local.get('theme', (data) => {
const theme = data.theme || 'dark';
if (theme === 'dark') {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
});
async function render() {
const notifications = await new Promise(resolve => {
chrome.runtime.sendMessage({ type: 'GET_NOTIFICATIONS' }, resolve);
});
const list = document.getElementById('notif-list');
const empty = document.getElementById('empty-notifs');
const recent = (notifications || []).slice(0, 3);
if (recent.length === 0) {
list.innerHTML = '';
empty.style.display = 'block';
return;
}
empty.style.display = 'none';
list.innerHTML = recent.map(n => `
<div class="notif-item ${n.read ? '' : 'unread'}">
<div class="notif-title">
<span class="notif-icon ${n.kind}"></span>
${escHtml(n.title)}
</div>
<div class="notif-body">${escHtml(n.body)}</div>
<div class="notif-time">${timeAgo(n.ts)}</div>
</div>
`).join('');
}
document.getElementById('mark-read-btn').addEventListener('click', async () => {
await chrome.runtime.sendMessage({ type: 'MARK_ALL_READ' });
render();
});
document.getElementById('open-panel-btn').addEventListener('click', async () => {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (tab) {
chrome.sidePanel.open({ tabId: tab.id });
}
window.close();
});
chrome.runtime.onMessage.addListener((msg) => {
if (msg.type === 'NOTIFICATION_ADDED') render();
});
// escHtml() and timeAgo() provided by utils.js
render();