-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpopup.js
More file actions
127 lines (83 loc) · 3.26 KB
/
popup.js
File metadata and controls
127 lines (83 loc) · 3.26 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
$(document).ready(function () {
function update()
{
chrome.storage.local.get("data",function(items)
{
if(items.data==undefined)
{
$(".blocked").append("No sites blocked till now!!");
}
else
{
for(var i=0;i<items.data.length;i++)
{
$(".blocked").append("<li>"+items.data[i].sites+"</li>");
console.log(items);
}
}
});
}
function perform(){
var Url=document.forms["add_remove"]["Url"].value;
var option=document.forms["add_remove"]["opt"].value;
console.log(option);
chrome.storage.local.get(function(items) {
//object named items with array of objects data
if(option==="Block") {
if (Object.keys(items).length > 0 && items.data) {
// The data array already exists, add to it the new server and nickname
items.data.push({sites: Url});
}
else {
// The data array doesn't exist yet, create it
items.data = [{sites: Url}];
}
// Now save the updated items using set
chrome.storage.local.set(items, function () {
console.log('Data successfully saved to the storage!');
}
);
}
else
if(option==="Remove")
{
if (Object.keys(items).length > 0 && items.data) {
// The data array already exists, add to it the new server and nickname
items.data=items.data.filter(function(obj)
{
if(obj["sites"]===Url)
return false;
else
return true;
}
);
}
else {
// The data array doesn't exist yet, create it
message("Oops! That URL was not found.")
}
// Now save the updated items using set
chrome.storage.local.set(items, function () {
console.log('Data successfully saved to the storage!');
}
);
}
})
update();
}
update();
$("#form1").submit(perform);
var bgPage=chrome.extension.getBackgroundPage();
var flag=true;
function getTime()
{
var time =parseFloat(document.forms["time_form"]["time"].value);
chrome.alarms.create("myAlarm", {delayInMinutes: time});
alert("Alarm created with " + time);
var background = chrome.extension.getBackgroundPage();
background.flag=true;
bgPage.block();
bgPage.createAlarm();
}
$("#form2").submit(getTime);
});