-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathbackground.js
More file actions
34 lines (30 loc) · 836 Bytes
/
Copy pathbackground.js
File metadata and controls
34 lines (30 loc) · 836 Bytes
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
humansByTab = {}
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
var u = parseUri(tab.url), site = "http://" + u.host;
if (u.port && u.port.strlen) site += ":" + u.port
if (humansByTab[tab.id] && humansByTab[tab.id].site == site) return showPageAction(tab); // already cached
loadHumans(site, function(text, link) {
showPageAction(tab);
humansByTab[tab.id] = {
site: site,
text: text,
link: link
}
}, function() {
hidePageAction(tab);
});
});
function showPageAction(tab) {
chrome.pageAction.show(tab.id);
chrome.pageAction.setIcon({
tabId: tab.id,
path: "h.jpg"
});
}
function hidePageAction(tab) {
delete humansByTab[tab.id];
chrome.pageAction.hide(tab.id);
}
chrome.tabs.onRemoved.addListener(function(tabId) {
delete humansByTab[tabId];
});