-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
52 lines (49 loc) · 1.29 KB
/
background.js
File metadata and controls
52 lines (49 loc) · 1.29 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
40
41
42
43
44
45
46
47
48
49
50
51
52
async function getNotification() {
var token = '';
var date = new Date();
date.setMinutes(date.getMinutes() - 2);
const ISOFormat = date.toISOString();
var repoLink;
var url;
chrome.storage.sync.get(['repo'], (repo) => {
repoLink = repo.repo;
console.log(repoLink);
var url =
'https://api.github.com/repos/' + repoLink + '/issues?since=' + ISOFormat;
fetch(url, {
headers: {
Authorization: `token ${token}`,
},
})
.then((res) => res.json())
.then((json) => {
if (json.length === 0) {
console.log('empty');
return;
}
var myobj = [];
json.forEach((element) => {
chrome.notifications.create(
'',
{
type: 'basic',
iconUrl: '/assets/globe.jpg',
title: element.title,
message: 'new issue opened!',
},
function () {
console.log('Last error:', chrome.runtime.lastError);
}
);
myobj.push({
title: element.title,
url: element.html_url,
});
});
chrome.storage.sync.set({ key: myobj }, () => {
console.log('saved');
});
});
});
}
setInterval(getNotification, 60000);