Skip to content

Instantly share code, notes, and snippets.

@Weiyuan-Lane
Created January 20, 2019 16:24
Show Gist options
  • Save Weiyuan-Lane/de066f5a255d54a4f28789dbdeb2b17a to your computer and use it in GitHub Desktop.
Save Weiyuan-Lane/de066f5a255d54a4f28789dbdeb2b17a to your computer and use it in GitHub Desktop.
Logic concerning the browser-action icon.
'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