-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
37 lines (33 loc) · 968 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
31
32
33
34
35
36
37
(function() {
function saveEndStateAndClearInterval(intervalId, location, message) {
chrome.storage.local.set({ [location]: message }, function() {
clearInterval(intervalId);
});
}
function startTimer(duration, location) {
var timer = duration;
var intervalId = setInterval(function() {
if (--timer < 0) {
saveEndStateAndClearInterval(intervalId, location, "Timed Out");
} else {
chrome.storage.local.set({ [location]: timer });
}
}, 1000);
}
chrome.runtime.onMessage.addListener(function(request) {
if (request.newTimer) {
chrome.storage.local.get(null, function(items) {
Object.entries(items).forEach(function([key, value]) {
if (
key !== "timer" &&
key !== "custom" &&
value !== "Finished" &&
value !== "Timed Out"
) {
startTimer(value, key);
}
});
});
}
});
})()