-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.html
235 lines (202 loc) · 6.49 KB
/
options.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
<!DOCTYPE html>
<html>
<head>
<title>Google search results blocker options</title>
<style type="text/css">
body {
background: #c7ccd7;
font-family: sans-serif;
}
#container {
width: 700px;
margin: 100px auto;
background: #fcfdfd;
padding: 20px;
border-radius: 8px;
border: 1px solid #aaa;
border-bottom: 2px solid #777;
}
form .entry {
margin: 1em 0;
}
form .entry select {
display: block;
background: #eee;
border: 1px solid #ccc;
width: 300px;
}
form .entry select option {
padding: 2px 4px;
}
#right {
float: right;
width: 330px;
}
#import textarea#txtimport {
width: 280px;
height: 120px;
}
#export textarea#txtexport {
width: 280px;
height: 100px;
}
</style>
<script type="text/javascript">
// Background worker reference for messaging
var background = opera.extension;
// Select box listing blocked hosts
var select;
// Textarea containing list of hosts for exporting
var txtexport;
// Textarea where user can input hosts to block
var txtimport;
// Checkboxes
var opt_confirm_block;
var opt_remove_redirects;
/*
* Event handler for incoming messages
*/
opera.extension.onmessage = function(event) {
// Handle messages from background worker
switch(event.data['what']) {
case 'all blocked hosts':
update_blocked_hosts_list(event.data['list']);
break;
case 'options':
update_blocked_hosts_list(event.data['value']['blocked_hosts']);
opt_confirm_block.checked = event.data['value']['confirm_block'];
opt_remove_redirects.checked = event.data['value']['remove_redirects'];
break;
}
}
window.addEventListener('DOMContentLoaded', function() {
background.postMessage({what: 'id', name: 'options'});
background.postMessage({what: 'get full options'});
select = document.querySelector('form .entry.blocked.hosts select');
txtexport = document.querySelector('#txtexport');
txtimport = document.querySelector('#txtimport');
opt_confirm_block = document.querySelector('#opt_confirm_block');
opt_remove_redirects = document.querySelector('#opt_remove_redirects');
// Enable deletion of blocked hosts
document.querySelector('form button[data-role=remove]').addEventListener(
'click',function(e) {
delete_selected_hosts();
e.stopPropagation();
return false;
},false);
// Enable importing hosts to block list
document.querySelector('form button[data-role=import]').addEventListener(
'click',function(e) {
import_hosts();
e.stopPropagation();
return false;
},false);
// Enable saving 'confirm block' setting
opt_confirm_block.addEventListener('change',function(e) {
background.postMessage({
what: 'set option',
name: 'confirm_block',
value: this.checked
});
});
// Enable saving 'remove_redirects' setting
opt_remove_redirects.addEventListener('change',function(e) {
background.postMessage({
what: 'set option',
name: 'remove_redirects',
value: this.checked
});
});
});
/*
* Update list of blocked hosts on the options page
*
* list: array of blocked hosts to update the options page with
*/
function update_blocked_hosts_list(list) {
select.innerHTML = '';
list.sort();
list.forEach(function(item) {
var option = document.createElement('option');
option.value = item;
option.label = item;
select.appendChild(option);
});
txtexport.innerHTML = list.join("\n");
}
/*
* Import blocked hosts from the import textarea
*/
function import_hosts() {
var str = txtimport.value;
if(str && str.length > 2) {
var hosts = str.split(/\s+|[, ]+/).filter(function(h) { return h.length > 2});
background.postMessage({what: 'block hosts', list: hosts });
txtimport.value = '';
}
}
/*
* Removes any hosts selected in the select box from the list of blocked hosts
*/
function delete_selected_hosts() {
var hosts = Array.prototype.filter.call(select.childNodes, function(opt) {
return opt.selected;
}).map(function(opt) {
return opt.value;
});
background.postMessage({what: 'unblock hosts', list: hosts});
}
</script>
</head>
<body>
<div id="container">
<h2>Google search results blocker options</h2>
<form onsubmit="return false;">
<div id="right">
<div class="entry">
<label for="opt_confirm_block" title="You will need to click block twice to block a host">Confirm block</label>
<input type="checkbox" id="opt_confirm_block" />
</div>
<div class="entry">
<label for="opt_remove_redirects" title="Remove googles redirects">Remove redirects</label>
<input type="checkbox" id="opt_remove_redirects" />
</div>
<div id="import">
<div class="entry">
<label for="txtimport">Import</label><br/>
<small>(newline/space/tab/comma separated, *.example.com style wildcards)</small>
<textarea id="txtimport"></textarea>
</div>
<div class="entry">
<button data-role="import">Import</button>
</div>
</div>
<div id="export">
<div class="entry">
<label for="txtexport">Export</label>
<textarea readonly id="txtexport"></textarea>
</div>
</div>
</div>
<div id="left">
<div id="list">
<form onsubmit="return false;">
<div class="entry blocked hosts">
<label for="bhosts">Blocked hosts</label>
<select size="20" multiple id="bhosts"></select>
</div>
<div class="entry">
<button data-role="remove">Remove</button>
</div>
</form>
</div>
</div>
</form>
<div id="info">
Currently, this does not sync with your google account.<br/>
Report issues & fork code at <a href="https://github.com/dxg/opera-gsblock">github</a>.<br/>
<br/>
</div>
</div>
</body>
</html>