Created
January 20, 2019 16:24
-
-
Save Weiyuan-Lane/de066f5a255d54a4f28789dbdeb2b17a to your computer and use it in GitHub Desktop.
Logic concerning the browser-action icon.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use-strict' | |
import CONSTANTS from 'scripts/constants/Constants' | |
function updateIconWith({ tabId, url }){ | |
if(url && url.match(CONSTANTS.BROWSER_ICON_URL_REGEX)){ | |
chrome.browserAction.setIcon({ path: 'public/images/logos/staff-32.png', tabId: tabId}); | |
} else { | |
chrome.browserAction.setIcon({ path: 'public/images/logos/staff-32-faded.png', tabId: tabId}); | |
} | |
} | |
chrome.tabs.onActivated.addListener(function(info){ | |
chrome.tabs.get(info.tabId, function(change){ | |
updateIconWith({ | |
tabId: info.tabId, | |
url: change.url | |
}) | |
}) | |
}) | |
chrome.tabs.onUpdated.addListener(function (tabId, change, tab){ | |
updateIconWith({ | |
tabId: tabId, | |
url: tab.url | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment