-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
51 lines (44 loc) · 1.36 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* @author Boris Tronquoy <b.tronquoy@gmail.com>
* @description Get notified
* @version 20181207
*/
'use strict';
// --- configuration --- //
// apiUrl: api url to test every x secondes (eg: https//test.com/api/example/)
// timer: in milliseconds (eg: 5000 for 5 seconds)
// --------------------- //
const apiUrl = ''
const timer = 5000
var notificationNumber = 0;
function issueCheck() {
fetch(apiUrl).then(response =>
response.json().then(data => ({
data: data,
status: response.status
})
).then(res => {
if(res.data.data.length !== 0) {
res.data.data.forEach(function(element) {
notificationNumber++
chrome.notifications.create(element.id, {
type: 'basic',
iconUrl: 'icon.png',
title: 'Notification: Hey! Something happened!',
message: 'Issue numéro: ' + element.id
}, function(notificationId) {});
});
issueBadge(notificationNumber)
}
}));
}
function issueBadge(i) {
var num = i.toString();
chrome.browserAction.setBadgeText({text: num});
}
// On click, deleting notifications
chrome.browserAction.onClicked.addListener(function (tab) {
issueBadge(0)
notificationNumber = 0;
});
setInterval(issueCheck, timer);