-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
60 lines (53 loc) · 1.8 KB
/
background.js
File metadata and controls
60 lines (53 loc) · 1.8 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
/**
* Service worker for install-time icon effects.
*
* On first install (NOT on updates, NOT on browser restart):
* 1. Pulse the toolbar icon by alternating between normal and a brighter
* variant a few times.
* 2. Set a "NEW" badge with a mint background and dark green text — the
* colour pairing approximates an outlined pill since chrome.action
* exposes no real stroke property. popup.js clears the badge the
* first time the popup opens.
*/
const FRAMES = [
{
16: 'icons/icon-16.png',
32: 'icons/icon-32.png',
48: 'icons/icon-48.png',
},
{
16: 'icons/icon-16-bright.png',
32: 'icons/icon-32-bright.png',
48: 'icons/icon-48-bright.png',
},
];
const PULSE_FRAMES = 6;
const PULSE_INTERVAL_MS = 280;
// Light mint fill + dark forest-green text. chrome.action exposes no
// stroke property; pairing a near-white background with a deep
// brand-coloured glyph is the closest we can get to "outlined pill".
const BADGE_TEXT = 'NEW';
const BADGE_BG = '#DBF1EC';
const BADGE_FG = '#0D7A5C';
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
async function pulseIcon() {
for (let i = 0; i < PULSE_FRAMES; i++) {
try { await chrome.action.setIcon({ path: FRAMES[i % 2] }); } catch {}
await sleep(PULSE_INTERVAL_MS);
}
try { await chrome.action.setIcon({ path: FRAMES[0] }); } catch {}
}
async function showInstallBadge() {
try {
await chrome.action.setBadgeBackgroundColor({ color: BADGE_BG });
if (chrome.action.setBadgeTextColor) {
await chrome.action.setBadgeTextColor({ color: BADGE_FG });
}
await chrome.action.setBadgeText({ text: BADGE_TEXT });
} catch {}
}
chrome.runtime.onInstalled.addListener(async (details) => {
if (details.reason !== 'install') return;
await pulseIcon();
await showInstallBadge();
});