forked from nqbao/chromesniffer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.html
77 lines (66 loc) · 1.83 KB
/
background.html
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<html>
<head>
<script type="text/javascript" src="common.js"></script>
<script type="text/javascript" src="engine.js"></script>
<script type="text/javascript" src="apps.js"></script>
<script>
window.dd = function(msg)
{
console.log(msg);
}
var tabinfo = {};
chrome.tabs.onRemoved.addListener(function(tabId)
{
// free memory
delete tabinfo[tabId];
});
/*chrome.tabs.onUpdated.addListener(function(tabId,changeInfo,tab)
{
// do not show for chrome page
if (changeInfo.status != 'complete' || /^chrome/i.test(tab.url))
return;
chrome.pageAction.show(tabId);
});*/
chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.msg == 'sniff') {
if (request.info && request.info.length > 0) // only store available info
{
tabinfo[sender.tab.id] = request.info;
// change the tab icon
var app = request.info[0];
for (var i = 1;i < request.info.length;i++)
{
var check = request.info[i];
if (appinfo[check].priority)
{
if (!appinfo[app].priority)
{
app = check;
}
else if (appinfo[app].priority > appinfo[check].priority)
{
app = check;
}
}
}
if (appinfo[app]) // lazy bug
{
chrome.pageAction.setIcon({tabId: sender.tab.id, path: 'apps/' + appinfo[app].icon});
chrome.pageAction.setTitle({tabId: sender.tab.id, title: (appinfo[app].title ? appinfo[app].title : app) + (request.info.length > 0 ? ' - Click for more detail.' : '')});
}
chrome.pageAction.show(sender.tab.id);
}
sendResponse({});
} else if (request.msg == 'get') {
var info = tabinfo[request.tab];
sendResponse({info: info});
}
});
</script>
</head>
<body></body>
</html>
<!--
Chrome AppSniffer by Bao Nguyen <[email protected]>
Released under GLPv3 license.
-->