diff --git a/background.js b/background.js index 2c2f13e..b15a064 100644 --- a/background.js +++ b/background.js @@ -3,6 +3,10 @@ const browserTypeChrome = 2; const storageTabCountKey = 'tab-count'; +const badgeBackgroundColorGrey = '#636c72'; +const badgeBackgroundColorYellow = '#f0ad4e'; +const badgeBackgroundColorRed = '#d9534f'; + const getBrowser = () => { try { return [browser, browserTypeFirefox]; @@ -40,12 +44,25 @@ browser.storage.onChanged.addListener(changes => { const onTabCountChange = newTabCount => { getTabCountFromStorage().then(tabCount => { + browser.browserAction.setBadgeBackgroundColor({ + color: getBadgeBackgroundColor(tabCount), + }); browser.browserAction.setBadgeText({text: tabCount.toString()}); }); }; +const getBadgeBackgroundColor = tabCount => { + if (tabCount < maxNumTabs) { + return badgeBackgroundColorGrey; + } else if (tabCount === maxNumTabs) { + return badgeBackgroundColorYellow; + } else { + return badgeBackgroundColorRed; + } +} + const setTabCountIntoStorage = tabCount => { - browser.storage.local.set({[storageTabCountKey]: tabs.length}); + browser.storage.local.set({[storageTabCountKey]: tabCount}); }; const getTabCountFromStorage = () => {