-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
33 lines (30 loc) · 1.09 KB
/
background.js
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
const message = {
type: "basic",
iconUrl: "icon.png",
title: "eye-do-care reminder",
message:
"Take a 20-second break by focusing your eyes on something 20 feet away",
buttons: [{ title: "Give those eyes a rest." }]
};
chrome.alarms.onAlarm.addListener(alarm => {
console.log(`${alarm.name} alarm fired!`);
alert("Time to rest your eyes for 20 seconds!")
chrome.notifications.create(message);
//communicate to content.js:
chrome.tabs.query({ currentWindow: true, active: true }, tabs => {
chrome.tabs.sendMessage(tabs[0].id, {message: "alarm"});
});
});
//if relying on notifications to set the next alarm:
// chrome.notifications.onClosed.addListener(() => {
// chrome.storage.sync.get(["minutes"], item => {
// if (item.minutes) {
// chrome.browserAction.setBadgeText({ text: "ON" });
// chrome.alarms.create({ delayInMinutes: item.minutes });
// }
// });
// });
// //allow extension to run without having to refresh/reload:
// chrome.webNavigation.onHistoryStateUpdated.addListener(() => {
// chrome.tabs.executeScript(null, { file: "content.js" });
// });