-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
39 lines (31 loc) · 1.26 KB
/
background.js
File metadata and controls
39 lines (31 loc) · 1.26 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
const QB_ALARM_TITLE = "Quarter Blasted";
const QUARTER_LABEL = "quarterLabel";
const BLASTED_QUARTERS = "blastedQuarters";
const MESSAGE = "Hooray!";
const SOUND_PATH = "assets/sounds/radio-cuba-cue_03-106715.mp3"; //https://pixabay.com/sound-effects/radio-cuba-cue-03-106715/
const AUDIO = new Audio(SOUND_PATH);
async function saveBlastedQuarter() {
quarterLabel =
(await browser.storage.local.get(QUARTER_LABEL))[QUARTER_LABEL] || "";
const timeOfBlast = new Date().toISOString(); // using UTC time
blastedQuarters =
(await browser.storage.local.get(BLASTED_QUARTERS))[BLASTED_QUARTERS] ||
[];
blastedQuarters.push([quarterLabel, timeOfBlast]);
browser.storage.local.set({ [BLASTED_QUARTERS]: blastedQuarters });
}
browser.alarms.onAlarm.addListener(async function (alarmInfo) {
saveBlastedQuarter();
// notify user about end of quarter
browser.notifications.create({
type: "basic",
title: alarmInfo.name,
message: MESSAGE,
});
AUDIO.play();
// start next quarter if autoStart is enabled
autoStartEnabled =
(await browser.storage.local.get("autoStart")).autoStart || false;
if (autoStartEnabled)
browser.alarms.create(QB_ALARM_TITLE, { delayInMinutes: 15 });
});