/
background.js
37 lines (35 loc) · 1.29 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
chrome.runtime.onMessage.addListener(function ({ nanoDonateEntries }, { tab }, sendResponse) {
// Only continue if URL doesn't start with "chrome://"
if (!tab.url.startsWith('chrome://')) {
chrome.storage.local.get({nanoAddressCache: {}}, function ({ nanoAddressCache }) {
// Valid Nano address/es found so add tab details to cache
if (nanoDonateEntries.length) {
nanoAddressCache[tab.id] = {
url: tab.url,
nanoDonateEntries
}
chrome.storage.local.set({ nanoAddressCache })
chrome.action.setIcon({
path: 'images/nano-donate-active-128.png',
tabId: tab.id
})
// No Nano addresses found so remove tab details from cache
} else {
delete nanoAddressCache[tab.id]
chrome.storage.local.set({ nanoAddressCache })
chrome.action.setIcon({
path: 'images/nano-donate-inactive-128.png',
tabId: tab.id
})
}
})
}
})
// ---------------------------------------------------
// When tab removed (closed)
chrome.tabs.onRemoved.addListener(function (tabId, removeInfo) {
chrome.storage.local.get({nanoAddressCache: {}}, function ({ nanoAddressCache }) {
delete nanoAddressCache[tabId]
chrome.storage.local.set({nanoAddressCache: nanoAddressCache})
})
})