forked from Monyer/antiHoneypot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathicon.js
93 lines (89 loc) · 2.15 KB
/
icon.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
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function tabExists(tabId, onExists, onNotExists) {
chrome.windows.getAll({
populate: true
}, function(windows) {
for (var i = 0, window; window = windows[i]; i++) {
for (var j = 0, tab; tab = window.tabs[j]; j++) {
if (tab.id == tabId) {
onExists && onExists(tab);
return;
}
}
}
onNotExists && onNotExists();
});
}
/**
* 设置icon状态
* @param {*} tabId
*/
function setIconStatus(tabId) {
var badgeText = "";
var badgeColor = [255, 255, 255, 255];
var iconPath = {
'32': 'icon/icon32b.png'
};
if (GLOBAL.blockTabs[tabId] && GLOBAL.blockTabs[tabId].length !== 0) {
badgeText = GLOBAL.blockTabs[tabId].length.toString();
badgeColor = [255, 0, 0, 255];
iconPath = {
'32': 'icon/icon32.png'
};
}
tabExists(tabId, function() {
setTimeout((tabId)=>{
if (!GLOBAL.blockTabs[tabId] || GLOBAL.blockTabs[tabId].length <= 1) {
chrome.browserAction.setIcon({
path: iconPath,
tabId: tabId
});
}
chrome.browserAction.setBadgeBackgroundColor({
color: badgeColor,
tabId: tabId
});
chrome.browserAction.setBadgeText({
text: badgeText,
tabId: tabId
});
},100);
});
}
/**
* 标签激活
* @param {*} activeInfo
*/
function tabActived(activeInfo) {
setIconStatus(activeInfo.tabId);
}
/**
* 标签关闭
* @param {*} tabId
* @param {*} removeInfo
*/
function tabRemoved(tabId, removeInfo) {
if (GLOBAL.blockTabs[tabId]) {
delete GLOBAL.blockTabs[tabId];
}
if (GLOBAL.fingerPrints[tabId]) {
delete GLOBAL.fingerPrints[tabId];
}
}
/**
* 标签重载
* @param {*} details
*/
function beforeNavigate(details) {
if (details.frameId == 0) {
if (GLOBAL.blockTabs[details.tabId]) {
delete GLOBAL.blockTabs[details.tabId];
}
if (GLOBAL.fingerPrints[details.tabId]) {
delete GLOBAL.fingerPrints[details.tabId];
}
}
setIconStatus(details.tabId);
}
chrome.tabs.onRemoved.addListener(tabRemoved);
chrome.tabs.onActivated.addListener(tabActived);
chrome.webNavigation.onBeforeNavigate.addListener(beforeNavigate);