Skip to content

Commit 7710b10

Browse files
committed
stable 0.0.1
1 parent 0a02b2a commit 7710b10

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

src/background.js

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import dB from "./utils/db";
55

66
const urlUtilsController = new urlUtils();
77
const dbController = new dB();
8+
let ActiveTabDetails = {
9+
tabId : null
10+
}
811

912
dbController.get("isFirstTimeLoad").then((res) => {
1013
if(res === undefined) {
@@ -30,7 +33,7 @@ chrome.history.onVisited.addListener(function (details) {
3033
});
3134

3235
chrome.tabs.onActivated.addListener((activeTabDetail)=>{
33-
console.log(activeTabDetail);
36+
ActiveTabDetails.tabId = activeTabDetail.tabId;
3437
chrome.tabs.get(activeTabDetail.tabId , (tab) => {
3538
dbController.get(urlUtilsController.getHostname(tab.url)).then((res)=>{
3639
const key = Object.keys(res);
@@ -46,16 +49,19 @@ chrome.tabs.onActivated.addListener((activeTabDetail)=>{
4649

4750
});
4851
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);
5563
chrome.browserAction.setBadgeText({text: ''});
56-
}).catch((e)=>{
57-
console.log("else ",e);
58-
chrome.browserAction.setBadgeText({text: ''});
59-
})
60-
});
64+
})
65+
});
66+
}
6167
});

0 commit comments

Comments
 (0)