-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
35 lines (33 loc) · 969 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
// background.js
chrome.runtime.onInstalled.addListener(() => {
chrome.alarms.create('updateReviewCount', { periodInMinutes: 5 });
updateReviewCount(); // initial call, sets up badge when extension is installed
});
chrome.alarms.onAlarm.addListener(alarm => {
if (alarm.name === 'updateReviewCount') {
updateReviewCount();
}
});
function updateReviewCount() {
fetch('http://localhost:8765', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
action: 'findCards',
version: 6,
params: {
query: 'is:due'
}
})
})
.then(response => response.json())
.then(data => {
const dueCount = data.result.length;
chrome.action.setBadgeText({ text: dueCount.toString() });
})
.catch(error => {
console.error('Error updating review count:', error);
});
}