Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
41 lines (36 sloc) 1.01 KB
<script src="jquery.min.js"></script>
<script src="parseUri.js"></script>
<script src="humans.js"></script>
<script>
var selectedTabId, humansByTab = {}
chrome.tabs.onSelectionChanged.addListener(function(tabId) {
selectedTabId = tabId;
});
function getSelectedHumans() {
return humansByTab[selectedTabId];
}
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
var u = parseUri(tab.url), site = u.protocol + "://" + u.host;
if (u.port && u.port.strlen) site += ":" + u.port
if (humansByTab[tab.id] && humansByTab[tab.id].site == site) return; // already cached
loadHumans(site, function(text, link) {
chrome.pageAction.show(tab.id);
humansByTab[tab.id] = {
site: site,
text: text,
link: link
}
chrome.pageAction.setIcon({
tabId: tab.id,
path: "h.jpg"
});
}, function() {
delete humansByTab[tab.id];
chrome.pageAction.hide(tab.id);
}
);
});
chrome.tabs.onRemoved.addListener(function(tabId) {
delete humansByTab[tabId];
});
</script>