-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
40 lines (33 loc) · 1.15 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
38
39
40
/* Copyright (c) 2014, Anthony Garcia <[email protected]>
* Distributed under the ISC License
*/
chrome.runtime.onInstalled.addListener(function() {
if (!localStorage.feeds) {
localStorage.feeds = "{}";
}
// Cleans the feed cache to avoid buildup. Yes it's hacky but Google forced my hand!
chrome.alarms.create("feedCleaner", {periodInMinutes: 60});
});
chrome.alarms.onAlarm.addListener(function() {
chrome.tabs.query({}, function(tabs) {
var feeds = JSON.parse(localStorage.feeds);
var tabKeys = [];
for (var i = 0; i < tabs.length; ++i) {
tabKeys.push(tabs[i].id.toString());
}
for (var key in feeds) {
if (tabKeys.indexOf(key) == -1) {
delete feeds[key];
}
}
localStorage.feeds = JSON.stringify(feeds);
});
});
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse) {
if (request.feeds) {
feedStore = JSON.parse(localStorage.feeds);
feedStore[sender.tab.id] = request.feeds;
localStorage.feeds = JSON.stringify(feedStore);
chrome.pageAction.show(sender.tab.id);
}
});