-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
59 lines (49 loc) · 1.21 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
var keyword = [];
//domain keyword
const TIME = {
HOUR: 1000 * 60 * 60,
MIN: 1000 * 60,
SEC: 1000
};
/*
var RestOfTime = function(){
};*/
var avoidTab = function(timeOut, tabId){
var interval = 1000;
setTimeout((function(){
console.info("start");
timeOut = timeOut - interval;
return function timerFunc(){
console.info("into timer");
chrome.tabs.remove(tabId, {url:"http://localhost/"});
if(!timeOut){
console.info("limit over");
return;
}
setTimeout(timerFunc, interval);
}
})(), interval);
};
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse){
if(typeof request !== "number") request = parseInt(request);
var period = request;
//count request from popup startbutton
var count = 0;
chrome.tabs.onCreated.addListener(
function(tab){
var url = tab.url;
var id = tab.id;
var list = localStorage["keyword"].split(",");
count++;
if(!list) return;
for(var i = 0; i < list.length; i++){
var regEx = new RegExp("^http(s)?:\\/\\/(" + list[i] +")+\\/[a-z]*", "i");
if(regEx.test(url)){
console.info("regEx");
avoidTab(period, id);
}
}
});
}
);