-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
71 lines (63 loc) · 1.51 KB
/
background.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
// Called when the user clicks on the browser action.
/*
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript(null, {code:"document.body.style.background='red !important'"});
chrome.tabs.captureVisibleTab(undefined,function(dataUrl){
alert("You just screwed the Background :D\n"+dataUrl);
});
});
*/
chrome.browserAction.setBadgeBackgroundColor({
color : [0, 200, 0, 100]
});
var i = 0;
/*
chrome.extension.onRequest.addListener(function(req,sender,resp){
globstr=String(req.data);
});
*/
var curval = 0;
cnt = 0;
window.setInterval(function() {
cnt++;
cur = "";
chrome.windows.getCurrent(function(w) {
if (w.focused) {
chrome.tabs.query({
"active" : true,
"windowId" : chrome.windows.WINDOW_ID_CURRENT
}, function(t) {
if ( typeof t != "undefined") {
var hdb = {};
if (cnt % 10 == 0) {
hdb = JSON.parse(localStorage.getItem("histdb"));
if (hdb == null)
hdb = {};
}
for ( i = 0; i < t.length; i++) {
cur += String(t[i].url) + "\n<br/>";
if (cnt % 10 == 0) {
tmp = 0;
var domain = t[i].url.match(/:\/\/(.[^/]+)/)[1];
try {
tmp = hdb[domain];
} catch(e) {
}
tmp++;
hdb[domain] = tmp;
curval = tmp;
}
}
if (cnt % 10 == 0) {
localStorage.setItem("histdb", JSON.stringify(hdb));
}
localStorage.setItem("hist", cur);
i = t.length;
}
});
}
});
chrome.browserAction.setBadgeText({
text : String(curval)
});
}, 100);