-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathevent_script.js
More file actions
100 lines (76 loc) · 1.98 KB
/
event_script.js
File metadata and controls
100 lines (76 loc) · 1.98 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
95
96
97
98
99
100
/**
* Created by priyankark on 27/12/16.
*/
/* blocking code */
var flag=true;
var d="";
function createAlarm() {
chrome.alarms.onAlarm.addListener(function (alarm) {
flag=false;
alert("Alarm beep!")
});
}
function block()
{
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
/* chrome.storage.local.get("data",function(items) {
for(var i=0;i<items.data.length;i++)
{
}
});
*/
if(flag===true) {
// alert(changeInfo.url); //Add blocking code here
var arr=tab.url.split('.');
if(arr[1]==="www"||arr[2]==="in")
d=arr[2];
else
d=arr[1];
//alert(d);
/////////////////
chrome.storage.local.get("data",function(items)
{
// alert("from local storage");
// alert(sender.tab.id);
if(items.data===undefined)
{
//alert("null");
}
else
{
for(var i=0;i<items.data.length;i++)
{
//alert(items.data[i].sites);
// if(d.toUpperCase()===items.data[i].sites.toUpperCase())
// {
// // alert(items.data[i].sites);
// // chrome.tabs.update(sender.tab.id, {
// // active: true,
// // url: "https://www.google.com/"
// // }, function(tab){});
// // window.location.href="https://www.google.com";
// alert(d.toUpperCase());
// }
//alert(d.toUpperCase());
//alert(items.data[i].sites.toUpperCase());
if(d.toUpperCase()==items.data[i].sites.toUpperCase())
{
chrome.tabs.update(tabId, {
active: true,
url: "quote_generator.html"
}, function(tab){});
}
}
}
});
//////////////////////////
}
else
{
//alert("Now unblocking");
}
});
chrome.tabs.onCreated.addListener(function(tab) {
//alert(tab.url);
});
}