Skip to content

Commit f5b45a3

Browse files
committed
Don't show badges if summaryCount is 0
1 parent cf7318a commit f5b45a3

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

background.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -558,8 +558,12 @@ function checkAndFetchSummaryCount(domain, tabId) {
558558
chrome.storage.local.get([domain], function(result) {
559559
if (result[domain] && new Date().getTime() - result[domain].timestamp < 86400000) { // 86400000 ms = 1 day
560560
// Data is still valid
561-
chrome.action.setBadgeText({text: result[domain].count.toString(), tabId: tabId});
562-
chrome.action.setBadgeBackgroundColor({color: '#22c55e', tabId: tabId});
561+
if (result[domain].count > 0) {
562+
chrome.action.setBadgeText({text: result[domain].count.toString(), tabId: tabId});
563+
chrome.action.setBadgeBackgroundColor({color: '#22c55e', tabId: tabId});
564+
} else {
565+
chrome.action.setBadgeText({text: '', tabId: tabId});
566+
}
563567
} else {
564568
// Data is outdated or not present, fetch new data
565569
fetchSummaryCount(domain, tabId);
@@ -577,13 +581,21 @@ function fetchSummaryCount(domain, tabId) {
577581
})
578582
.then(response => response.json())
579583
.then(data => {
580-
if (data && data.summariesCount) {
584+
if (data.summariesCount !== undefined) {
581585
chrome.storage.local.set({[domain]: {count: data.summariesCount, timestamp: new Date().getTime()}});
582-
chrome.action.setBadgeText({text: data.summariesCount.toString(), tabId: tabId});
583-
chrome.action.setBadgeBackgroundColor({color: '#22c55e', tabId: tabId});
586+
if (data.summariesCount > 0) {
587+
chrome.action.setBadgeText({text: data.summariesCount.toString(), tabId: tabId});
588+
chrome.action.setBadgeBackgroundColor({color: '#22c55e', tabId: tabId});
589+
} else {
590+
chrome.action.setBadgeText({text: '', tabId: tabId});
591+
}
584592
} else {
585593
chrome.action.setBadgeText({text: '', tabId: tabId});
586594
}
587595
})
588-
.catch(error => console.error('Error fetching summary count:', error));
596+
.catch(error => {
597+
console.error('Error fetching summary count:', error);
598+
chrome.action.setBadgeText({text: '', tabId: tabId});
599+
});
589600
}
601+

0 commit comments

Comments
 (0)