-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
30 lines (26 loc) · 856 Bytes
/
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
let defaultDuration = 1.0
chrome.alarms.onAlarm.addListener(function (alarm) {
console.log(alarm)
chrome.notifications.create("limit", {
type: "basic",
iconUrl: "128.png",
title: "DRINK WATER",
"message": "STAY HYDRATED !! Don't you wanna look fresh ?"
}, function (notifications) {
setTimeout(function () { chrome.notifications.clear("limit", function () { }); }, 5000);
})
})
function createAlarm() {
chrome.alarms.create("drink_water", { periodInMinutes: defaultDuration });
}
createAlarm()
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
defaultDuration = request.minutes * 1.0;
console.log("Event received");
if (defaultDuration != 0) {
createAlarm();
sendResponse({ sucess: true });
}
}
);