@@ -558,8 +558,12 @@ function checkAndFetchSummaryCount(domain, tabId) {
558
558
chrome . storage . local . get ( [ domain ] , function ( result ) {
559
559
if ( result [ domain ] && new Date ( ) . getTime ( ) - result [ domain ] . timestamp < 86400000 ) { // 86400000 ms = 1 day
560
560
// 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
+ }
563
567
} else {
564
568
// Data is outdated or not present, fetch new data
565
569
fetchSummaryCount ( domain , tabId ) ;
@@ -577,13 +581,21 @@ function fetchSummaryCount(domain, tabId) {
577
581
} )
578
582
. then ( response => response . json ( ) )
579
583
. then ( data => {
580
- if ( data && data . summariesCount ) {
584
+ if ( data . summariesCount !== undefined ) {
581
585
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
+ }
584
592
} else {
585
593
chrome . action . setBadgeText ( { text : '' , tabId : tabId } ) ;
586
594
}
587
595
} )
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
+ } ) ;
589
600
}
601
+
0 commit comments