-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
44 lines (36 loc) · 1.12 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
41
42
43
44
// require(init.js)
// require(storage_manager.js)
chrome.tabs.onActivated.addListener(function(info) {
chrome.tabs.get(info.tabId, function(tab) {
updatePageIcon(tab);
});
});
chrome.tabs.onUpdated.addListener(function(tabId, info, tab) {
updatePageIcon(tab);
});
chrome.pageAction.onClicked.addListener(function(tab) {
storageManager.toggleRead(tab.url);
updatePageIcon(tab);
});
function updatePageIcon(tab) {
storageManager.hasRead(tab.url, function(hasRead) {
var iconInfo = {
path: (hasRead ? 'checked.png' : 'mark.png'),
tabId: tab.id
};
chrome.pageAction.setIcon(iconInfo);
chrome.pageAction.show(tab.id);
});
}
chrome.commands.onCommand.addListener(function(command) {
if (command == config.COMMAND_TOGGLE_READ) {
chrome.tabs.query({active: true, currentWindow: true},
function(tabs) {
if (tabs.length > 0) {
var tab = tabs[0];
storageManager.toggleRead(tab.url);
updatePageIcon(tab);
}
});
}
});