-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrowserActionPopUp.html
404 lines (342 loc) · 10.8 KB
/
browserActionPopUp.html
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
<html>
<head>
<script src="common/port.js"></script>
<script src="common/config.js"></script>
<title>Extension Action</title>
<style>
#wrapper {
width:302px;
margin:0px auto;
padding:2px 0px;
background: #EEE;
display:none;
overflow:auto;
-moz-border-radius:5px;
-webkit-border-radius:5px;
-o-border-radius:5px;
border-radius:5px;
}
#wrapperPriority {
width:302px;
margin:2px auto;
padding:2px 2px;
background: green;
display:none;
-moz-border-radius:5px;
-webkit-border-radius:5px;
-o-border-radius:5px;
border-radius:5px;
}
#wrapperStatus {
width:300px;
margin:0px auto;
padding:2px 0px;
background: #f5f5f5;
}
#wrapperSpacer {
width:310px;
height:15px;
margin:0px auto;
padding:5px 0px;
background: #f5f5f5;
display:none;
}
#status {
font-family: 'Arial', arial, serif;
font-size:12px;
color:#000;
text-decoration:none;
}
#footer {
text-align:center;
}
#footer, #footer a {
color:#ccc;
}
h1, h2, p, a {
font-family: 'Arial', arial, serif;
line-height:1.5;
}
h1 {
margin:0 0 10px 0;
letter-spacing:1px;
}
h2 {
margin:20px 0 5px 0;
font-size:20px;
}
body {
background:#f5f5f5;
}
</style>
<style>
div.button {
font-family: 'Arial', arial, serif;
font-size:18px;
color:#000;
text-decoration:none;
cursor: pointer;
width:290px;
padding:10px 5px;
border:1px solid #DDD;
text-align:center;
white-space: wrap;
overflow: hidden;
text-overflow: ellipsis;
display:block;
-moz-border-radius:5px;
-webkit-border-radius:5px;
-o-border-radius:5px;
border-radius:5px;
background:#FFFFFF;
background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#FFFFFF), to(#EEE));
background:-moz-linear-gradient(0% 90% 90deg, #EEE, #FFF);
-webkit-transition: all .4s ease-in-out;
-moz-transition: all .4s ease-in-out;
-o-transition: all .4s ease-in-out;
transition: all .4s ease-in-out;
}
div.button:hover {
color:#fff;
border-color:#3278BE;
background:#4195DD;
background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#4195DD), to(#003C82));
background:-moz-linear-gradient(0% 90% 90deg, #003C82, #4195DD);
}
div.button:active {
background:#4195DD;
background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#003C82), to(#4195DD));
background:-moz-linear-gradient(0% 90% 90deg, #4195DD, #003C82);
}
div.button.notransitions {
-webkit-transition: none;
-moz-transition: none;
-o-transition: none;
transition: none;
}
</style>
<style>
div.ubutton {
font-family: 'Arial', arial, serif;
font-size:12px;
color:#000;
text-decoration:none;
cursor: pointer;
width:290px;
padding:5px 5px;
border:1px solid #DDD;
text-align:center;
white-space: wrap;
overflow: hidden;
text-overflow: ellipsis;
display:block;
-moz-border-radius:5px;
-webkit-border-radius:5px;
-o-border-radius:5px;
border-radius:5px;
background:#FFFFFF;
background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#FFFFFF), to(#EEE));
background:-moz-linear-gradient(0% 90% 90deg, #EEE, #FFF);
-webkit-transition: all .4s ease-in-out;
-moz-transition: all .4s ease-in-out;
-o-transition: all .4s ease-in-out;
transition: all .4s ease-in-out;
}
div.ubutton:hover {
color:#fff;
border-color:#3278BE;
background:#4195DD;
background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#4195DD), to(#003C82));
background:-moz-linear-gradient(0% 90% 90deg, #003C82, #4195DD);
}
div.ubutton:active {
background:#4195DD;
background:-webkit-gradient(linear, 0% 0%, 0% 100%, from(#003C82), to(#4195DD));
background:-moz-linear-gradient(0% 90% 90deg, #4195DD, #003C82);
}
div.ubutton.notransitions {
-webkit-transition: none;
-moz-transition: none;
-o-transition: none;
transition: none;
}
</style>
</head>
<body>
<div id="wrapperStatus">
<div id="status">Status</div>
</div>
<div id="wrapperPriority">
<div onclick="" id="addOrRemove" name="addOrRemove" class="button notransitions"></div>
</div>
<div id="wrapper">
<div onclick="" id="toggleOnOff" name="toggleOnOff" class="button notransitions"></div>
</div>
<div id="wrapperSpacer">
</div>
<div id="wrapper">
<div onclick="" id="lastBlocked1" name="lastBlocked1" class="ubutton notransitions"></div>
</div>
<div id="wrapper">
<div onclick="" id="lastBlocked2" name="lastBlocked2" class="ubutton notransitions"></div>
</div>
<div id="wrapper">
<div onclick="" id="lastBlocked3" name="lastBlocked3" class="ubutton notransitions"></div>
</div>
<script type = "text/javascript">
chrome.tabs.getSelected(null,
function(tab)
{
var statusDiv = document.getElementById("status");
var addOrRemoveDiv = document.getElementById("addOrRemove");
var addOrRemoveWrapper = addOrRemoveDiv.parentNode;
var toggleOnOffDiv = document.getElementById("toggleOnOff");
var toggleOnOffDivWrapper = toggleOnOffDiv.parentNode;
var coreWebsiteAddress = getMainURL(tab.url);
// Toggling on/off
if (urlsGloballyAllowed)
{
statusDiv.innerHTML = "All Pop Ups Temporarily Allowed on New Page Loads";
toggleOnOffDiv.appendChild(document.createTextNode("Revoke All Temporary"));
toggleOnOffDivWrapper.style.display = "block";
}
else
{
if (coreWebsiteAddress)
{
if (isAllowed(coreWebsiteAddress))
{
statusDiv.innerHTML = "Pop Ups Allowed on Site";
addOrRemoveDiv.innerHTML = "Forbid<br/><i>" + coreWebsiteAddress + "</i>";
addOrRemoveWrapper.style.background = "red";
addOrRemoveWrapper.style.display = "block";
addOrRemoveDiv.onclick = function(){removeSite(coreWebsiteAddress);};
}
else
{
statusDiv.innerHTML = "Pop Ups Forbidden on Site";
addOrRemoveDiv.innerHTML = "Allow<br/><i>" + coreWebsiteAddress + "</i>";
addOrRemoveWrapper.style.background = "green";
addOrRemoveWrapper.style.display = "block";
addOrRemoveDiv.onclick = function(){addSite(coreWebsiteAddress);};
// This sendRequest only goes to the top level window of the tab, ie: not to iFrames
chrome.tabs.sendRequest(tab.id, {type: "get last blocked", index: tab.index}, showLastBlocked);
}
}
else // something wrong with the url
{
statusDiv.innerHTML = "Unknown";
addOrRemoveDiv.appendChild(document.createTextNode("~N/A URL"));
addOrRemoveWrapper.style.display = "block";
}
toggleOnOffDiv.appendChild(document.createTextNode("Temporarily Allow All Globally"));
toggleOnOffDivWrapper.style.display = "block";
}
toggleOnOffDiv.onclick = function(){toggleOnOff();};
}
);
function showLastBlocked(response)
{
var lastBlockedDivs = new Array();
var lastBlockedDivWrappers = new Array();
lastBlockedDivs.push(document.getElementById("lastBlocked1"));
lastBlockedDivWrappers.push(document.getElementById("lastBlocked1").parentNode);
lastBlockedDivs.push(document.getElementById("lastBlocked2"));
lastBlockedDivWrappers.push(document.getElementById("lastBlocked2").parentNode);
lastBlockedDivs.push(document.getElementById("lastBlocked3"));
lastBlockedDivWrappers.push(document.getElementById("lastBlocked3").parentNode);
var spacerDiv = document.getElementById("wrapperSpacer");
if (response.error)
{
spacerDiv.style.display = "block";
spacerDiv.innerHTML = "<hr/>";
lastBlockedDivs[0].innerHTML = "<b>Open Blocked Pop Up Error</b><br/><i>" + response.error.description + "</i>";
lastBlockedDivWrappers[0].style.display = "block";
}
else
{
if (response.url)
{
var spacerDisplayed = false;
for (var i = 0; i < response.url.length && i < lastBlockedDivs.length; i++)
{
var currBlockedURL = response.url[i];
if (currBlockedURL === "about:blank" || getMainURL(currBlockedURL))
{
if (!spacerDisplayed)
{
spacerDiv.style.display = "block";
spacerDiv.innerHTML = "<hr/>";
spacerDisplayed = true;
}
currBlockedURL = encodeURI(currBlockedURL.trim());
const maxLines = 2;
var urlChunks = currBlockedURL.chunk(45);
var theMessage = "";
for (var j = 0; j < maxLines && j < urlChunks.length; j++)
{
theMessage += (urlChunks[j] + "<br/>");
}
if (urlChunks.length > maxLines)
{
var lastChunk = urlChunks[maxLines].chunk(35);
theMessage += (lastChunk[0] + "......<br/>");
}
lastBlockedDivs[i].innerHTML = "<b>Open Blocked Pop Up</b><br/><i>" + theMessage + "</i>";
lastBlockedDivWrappers[i].style.display = "block";
lastBlockedDivWrappers[i].setAttribute("data-url", currBlockedURL);
lastBlockedDivWrappers[i].setAttribute("data-index", response.index);
lastBlockedDivWrappers[i].onclick = function(){openTab(this);};
}
}
}
}
}
function openTab(divCaller)
{
chrome.tabs.create({url: divCaller.getAttribute("data-url"), index: parseInt(divCaller.getAttribute("data-index")) + 1, selected: true});
}
function removeSite(url) {
revokeUrl(url);
checkAndReload(url);
window.close();
}
function addSite(url) {
permitUrl(url);
checkAndReload(url);
window.close();
}
function toggleOnOff() {
/* // For browser action button
if (urlsGloballyAllowed == true)
{
config.set('globalAllowAll', false);
chrome.browserAction.setBadgeText({text:String('on')});
chrome.browserAction.setBadgeBackgroundColor({color:[0, 200, 0, 100]});
}
else
{
config.set('globalAllowAll', true);
chrome.browserAction.setBadgeText({text:String('off')});
chrome.browserAction.setBadgeBackgroundColor({color:[0, 0, 0, 100]});
}
*/
config.set('globalAllowAll', !urlsGloballyAllowed);
checkAndReload("***NOTINWHITELIST***");
window.close();
}
function checkAndReload(url) {
var shouldReload = config.get('reloadCurrentTabOnToggle');
if (shouldReload)
{
// Reloading by chrome.tabs.executeScript(...). Works with or without javascript enabled.
//chrome.tabs.executeScript(null, {code:"if(window.location.href.indexOf('http') == 0) {window.location.reload();}"});
// We can't use chrome.windows.getAll(...) from this page for some reason so we have to do
// it from the background page
chrome.extension.getBackgroundPage().refreshTabs(url);
}
}
</script>
</body>
</head>
</html>