-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
35 lines (34 loc) · 1.07 KB
/
popup.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
// popup.js
document.addEventListener('DOMContentLoaded', function() {
console.log('DOMContentLoaded event fired');
updateReviewCount();
});
function updateReviewCount() {
console.log('updateReviewCount function called');
fetch('http://localhost:8765', { // need AnkiConnect running
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
action: 'findCards',
version: 6,
params: {
query: 'is:due'
}
})
})
.then(response => {
console.log('Response received', response);
return response.json();
})
.then(data => {
console.log('Data parsed', data);
const dueCount = data.result.length;
document.getElementById('review-count').textContent = `You have ${dueCount} cards to review.`;
})
.catch(error => {
console.error('Error fetching review count:', error);
document.getElementById('review-count').textContent = 'Error loading revview count';
});
}