-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
94 lines (86 loc) · 2.16 KB
/
Copy pathbackground.js
File metadata and controls
94 lines (86 loc) · 2.16 KB
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
94
var superhappyval = 6;
var happyval = 11;
var neutralval = 16;
var sadval = 21;
var mostRecentTab;
var limit = false;
var refreshIcon = function(addedTab) {
var queryInfo = new Object();
queryInfo.url = "<all_urls>";
chrome.tabs.query(queryInfo, function(tabs) {
console.log(tabs.length);
var icon = new Object();
if (tabs.length < superhappyval) {
icon.path = "images/0.png";
} else if (tabs.length < happyval) {
icon.path = "images/1.png";
} else if (tabs.length < neutralval) {
icon.path = "images/2.png";
} else if (tabs.length < sadval) {
icon.path = "images/3.png";
} else {
icon.path = "images/4.png";
if (mostRecentTab && addedTab === true && limit === true) {
chrome.tabs.remove(mostRecentTab.id);
alert("Seriously, stop opening tabs :p");
}
}
chrome.browserAction.setIcon(icon);
});
};
var updateVals = function(items) {
if (items.superhappy) {
superhappyval = items.superhappy;
}
if (items.happy) {
happyval = items.happy;
}
if (items.neutral) {
neutralval = items.neutral;
}
if (items.sad) {
sadval = items.sad;
}
console.log(items.limit);
if (items.limit)
{
limit = items.limit;
}
refreshIcon(false);
};
chrome.storage.onChanged.addListener(function(items, area) {
console.log("updated vals");
console.log(items);
if (items.superhappy) {
superhappyval = items.superhappy.newValue;
}
if (items.happy) {
happyval = items.happy.newValue;
}
if (items.neutral) {
neutralval = items.neutral.newValue;
}
if (items.sad) {
sadval = items.sad.newValue;
}
if (items.limit)
{
limit = items.limit.newValue
}
refreshIcon(false);
});
chrome.tabs.onCreated.addListener(function(tab) {
// var queryInfo = new Object();
// queryInfo.url = "<all_urls>";
// chrome.tabs.query(queryInfo, refreshIcon);
mostRecentTab = tab;
refreshIcon(true);
});
chrome.tabs.onRemoved.addListener(function(tab) {
refreshIcon(false);
});
chrome.storage.local.get(['superhappy', 'happy', 'neutral', 'sad', 'limit' ], function(items) {
console.log("updating for the first time");
console.log(items);
updateVals(items);
});