diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/TabCache.js | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/lib/TabCache.js b/src/lib/TabCache.js new file mode 100644 index 0000000..16d6e1f --- /dev/null +++ b/src/lib/TabCache.js @@ -0,0 +1,24 @@ +var TabCache = (() => { + + let cache = new Map(); + + browser.tabs.onUpdated.addListener(tab => { + cache.set(tab.id, tab); + }); + + browser.tabs.onRemoved.addListener(tab => { + cache.delete(tab.id); + }); + + (async () => { + for (let tab of await browser.tabs.query({})) { + cache.set(tab.id, tab); + } + })(); + + return { + get(tabId) { + return cache.get(tabId); + } + }; +})(); |