@@ -5,6 +5,9 @@ import dB from "./utils/db";
5
5
6
6
const urlUtilsController = new urlUtils ( ) ;
7
7
const dbController = new dB ( ) ;
8
+ let ActiveTabDetails = {
9
+ tabId : null
10
+ }
8
11
9
12
dbController . get ( "isFirstTimeLoad" ) . then ( ( res ) => {
10
13
if ( res === undefined ) {
@@ -30,7 +33,7 @@ chrome.history.onVisited.addListener(function (details) {
30
33
} ) ;
31
34
32
35
chrome . tabs . onActivated . addListener ( ( activeTabDetail ) => {
33
- console . log ( activeTabDetail ) ;
36
+ ActiveTabDetails . tabId = activeTabDetail . tabId ;
34
37
chrome . tabs . get ( activeTabDetail . tabId , ( tab ) => {
35
38
dbController . get ( urlUtilsController . getHostname ( tab . url ) ) . then ( ( res ) => {
36
39
const key = Object . keys ( res ) ;
@@ -46,16 +49,19 @@ chrome.tabs.onActivated.addListener((activeTabDetail)=>{
46
49
47
50
} ) ;
48
51
chrome . tabs . onUpdated . addListener ( function ( tabId , changeInfo , tab ) {
49
- chrome . tabs . get ( tabId , ( tab ) => {
50
- dbController . get ( urlUtilsController . getHostname ( tab . url ) ) . then ( ( res ) => {
51
- const key = Object . keys ( res ) ;
52
- if ( key . length > 0 )
53
- chrome . browserAction . setBadgeText ( { text : '♥' } ) ;
54
- else
52
+ console . log ( "onUpdated" , tabId ) ;
53
+ if ( tabId === ActiveTabDetails . tabId ) {
54
+ chrome . tabs . get ( tabId , ( tab ) => {
55
+ dbController . get ( urlUtilsController . getHostname ( tab . url ) ) . then ( ( res ) => {
56
+ const key = Object . keys ( res ) ;
57
+ if ( key . length > 0 )
58
+ chrome . browserAction . setBadgeText ( { text : '♥' } ) ;
59
+ else
60
+ chrome . browserAction . setBadgeText ( { text : '' } ) ;
61
+ } ) . catch ( ( e ) => {
62
+ console . log ( "else " , e ) ;
55
63
chrome . browserAction . setBadgeText ( { text : '' } ) ;
56
- } ) . catch ( ( e ) => {
57
- console . log ( "else " , e ) ;
58
- chrome . browserAction . setBadgeText ( { text : '' } ) ;
59
- } )
60
- } ) ;
64
+ } )
65
+ } ) ;
66
+ }
61
67
} ) ;
0 commit comments