-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
30 lines (27 loc) · 1.21 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
// This is a really nasty kludge until we can load from chrome://favicon/
// (#11854). The API here sucks. We could attach a callback to tabs.create
// or tabs.update, but that will return a useless copy of the just-created
// Tab object (#24558). We can't provide a callback to fire when the tab
// actually completes and favIconUrl is available. So, we watch every
// single tab update to see if it contains something of interest. To avoid
// bloating localStorage we filter this on actually-bookmarked URLs. We
// can update *that* list when a bookmark is created, but on deletion...
// fuck it. This is good enough. It's just a hack. I will delete the entire
// file with much relish. Hopefully soon.
var watching = {};
function watchAll(bookmarks) {
bookmarks.forEach(function(b) {
if ('children' in b)
watchAll(b.children);
else
watching[b.url] = true;
});
}
chrome.bookmarks.getTree(watchAll);
chrome.bookmarks.onCreated.addListener(function(id, b) {
watching[b.url] = true;
});
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (tab.url in watching && tab.status == 'complete' && tab.favIconUrl)
localStorage[tab.url] = tab.favIconUrl;
});