forked from cyberstream/Fix-the-Web
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.html
302 lines (252 loc) · 13.5 KB
/
popup.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<style type="text/css">
body {
padding:0;
margin: 0;
background:rgb(245, 245, 245);
font-family: "arial", "lucida grande", "lucida sans unicode", "bitstream vera sans", "dejavu sans", "trebuchet ms", sans-serif;
}
body * {
box-sizing:border-box;
}
p{
margin:10px 5px;
}
form{
border-bottom:1px solid #efefef;
padding-bottom:10px;
}
ul li, a {
list-style:none;
margin: 0;
font:bold 14px sans-serif;
color:#111;
}
ul li:hover {
color:#fff;
background:rgb(51, 153, 255);
}
ul li:hover a {color:#fff}
ul {
padding:0;
margin:0;
margin-top:10px;
}
a {
text-decoration:none;
padding:6px 0;
}
a:hover {text-decoration:underline}
#page-address{
width:100%;
}
input[type=text], textarea, select, input[type=url] {
border:1px solid #dfdfdf;
padding:3px 4px;
font-family: "arial", "lucida grande", "lucida sans unicode", "bitstream vera sans", "dejavu sans", "trebuchet ms", sans-serif;
}
input[type="text"]:hover, input[type=url]:hover, textarea:hover, select:hover{
border:1px solid rgb(51, 153, 255);
}
input[type="text"]:focus, input[type=url]:focus, textarea:focus,select:focus{
border:1px solid #999;
box-shadow:inset 0 0 3px #999;
}
textarea{
width:100%;
}
input[type="submit"]{
border:0;
padding:4px 10px;
background:-o-linear-gradient(top,rgb(60, 160, 255),rgb(40, 140, 250));
box-shadow:0 0 1px 1px #999;
color:#fff;
font-weight:bolder;
float: right;
margin:0 5px;
}
input[type="submit"]:hover {
cursor:pointer;
background:-o-linear-gradient(top,#54aaff,rgb(40, 140, 250));
}
#opera-version,#opera-build-number,#OS{
float:left;
width:33%;
}
#additional-information-details-panel-opener, #link-related-with-the-site li {
cursor: pointer;
letter-spacing:-1pt;
}
#link-related-with-the-site li a{
width:100%;
padding:6px 4px;
display: block;
}
#additional-information-details-panel-opener:hover, #open-comment-panel:hover {text-decoration: underline}
#additional-information-details-panel{
display:none;
}
div.pad_bottom {padding-bottom:10px}
#error {
background:#ffdbdb;
border:1px solid #dd5959;
}
#success {
background:#dbffd6;
border:1px solid #62cc5b;
}
#error, #success {
display:inline-block;
padding:3px 4px;
border-radius:6px/15px;
margin: 5px 0 0 5px;
font:bold 14px sans-serif;
text-shadow:0 1px 0 #fff;
}
#error:before, #success:before {
padding-right:3px;
top:3px;
position:relative;
}
#error:before {content:url(images/errors.png)}
#success:before {content:url(images/success.png)}
</style>
<title>Fix the Web</title>
</head>
<body>
<!-- TODO only display this form if the user is authenticated with MyOpera.
Server-side verification should also be done to ensure that they are authenticated;
TODO give this form nicer styles -->
<form action="" method="post" id="report-site-form">
<p>
<input type="url" required="required" id="page-address" name="page_address" placeholder="You must enter page location" />
</p>
<p>
<label for="report-category">Category</label>
<select id="report-category" name="category">
<option value="0">Minor Annoyance</option>
<option value="1">Major Problem</option>
<option value="2">Site Unusable</option>
</select>
</p>
<p>
<label for="error-report-description">Error Details</label>
<textarea rows="5" cols="30" id="error-report-description" required="required" name="description" placeholder="What triggered the problem, what you were expecting, etc"></textarea>
</p>
<div class="pad_bottom"><em id="additional-information-details-panel-opener">Additional details...</em><input type="submit" value="Submit Report >" />
<p id="additional-information-details-panel">
<input type="text" id="OS" name="OS" />
<input type="text" id="opera-version" name="opera_version" />
<input type="text" id="opera-build-number" name="opera_build_number" />
<textarea id="additional-information" name="additional_information" cols="35" rows="4"></textarea>
</p>
</div>
</form>
<ul id="link-related-with-the-site">
<li><a href="#" id="open-comment-panel">View problems reported on this site</a></li>
<li><a href="index.html" target="_blank">View recent bug reports</a></li>
</ul>
<script type="text/javascript">
window.addEventListener("DOMContentLoaded",function() {
// get the current tab's URL
var tab = opera.extension.bgProcess.opera.extension.tabs.getFocused();
if (tab) document.getElementById('page-address').value = tab.url
// when "Vew problems reported on this site" is clicked, open the comments panel
document.getElementById('open-comment-panel').addEventListener("click", function() {
// TODO close the popup when the comments frame loads
opera.extension.bgProcess.opera.extension.tabs.getFocused().postMessage('load comments frame'); // trigger the comments frame's creation
return false; // keep link from following the default action
}, false);
// function show_message() shows an error or success message above the form
function show_message (text, message_mode) { // message_mode: 'error' or 'success'
var message = document.querySelector('#error, #success'),
form_element = document.getElementById('report-site-form');
if (message) error_message.parentNode.removeChild(message); // remove old messages before displaying a new one
var element = document.createElement('div');
element.id = message_mode;
element.innerHTML = text;
form_element.parentNode.insertBefore(element, form_element);
}
// process the form when it is submitted
document.getElementById('report-site-form').onsubmit = function() {
var error_message = document.getElementById('error');
if (error_message) error_message.parentNode.removeChild(error_message);
var error_form = document.getElementById('report-site-form'),
domain_name = error_form.page_address.value.match(/:\/\/([^\/]+)\/?/) ? error_form.page_address.value.match(/:\/\/([^\/]+)\/?/)[1] : '', // get the second item in the result's array (the matched text in the parentheses)
params = {
mode : 'submit error', // this is to select the correct form handler in ajax_request_handler.php
url : error_form.page_address.value,
domain : domain_name,
category : error_form.category.value,
description : error_form.description.value,
system : error_form.OS.value,
version : error_form.opera_version.value,
build : error_form.opera_build_number.value,
misc : error_form.additional_information.value
};
// TODO maybe...validate the params.url field with a regular expression (regex) to make sure it is a real URL???
// send report asynchronously to the server with the ajax_request_handler.php file on it
// see the "Fix the Web Server Side" repo on Github for that file
// validate and process the form POST request in ajax_request_handler.php
opera.extension.bgProcess.sendRequest('GET', 'http://localhost/ajax_request_handler.php', function(data) { // TODO change form processing URL
if (data == 'success') show_message ('Thanks for reporting this bug. It will be reviewed soon.', 'success');
else if (data.length > 0) show_message (data, 'error');
else show_message('The server form validation and processing needs to be finished.', 'error');
}, params);
return false; // prevent the form from actually submitting
}
// Toggle additional information panel by clicking the text "Additional information"
document.getElementById("additional-information-details-panel-opener").addEventListener("click",function(){
var state = document.getElementById("additional-information-details-panel").style.display;
switch(state){
// if #additional-information-panel is hidden, it will be indicated
case "block":
document.getElementById("additional-information-details-panel").style.display="none";
break;
// if #additional-information-panel is visible, it will disappear
case "none":
case "":
document.getElementById("additional-information-details-panel").style.display="block";
break;
}
},false);
if ((window.opera) && (opera.buildNumber)){
// learn and write version into hidden element (#opera-version)
document.getElementById("opera-version").value = opera.version();
// learn and write version of Opera into hidden element (#opera-build-number)
document.getElementById("opera-build-number").value = opera.buildNumber();
}
// seperator will split additional information to different parts
var separator = "\r\n===========\r\n";
// cache (#additional-information) element
var bug = document.getElementById('additional-information');
// learn what plugins is installed and write them into hidden element (#additional-information)
bug.value += "PLUGINS:" + separator;
// navigator.plugins stores what plugins is installed and which are activated
if (navigator.plugins) {
for (var i = 0; i < navigator.plugins.length; i++) {
// for each plugin obtain its name, description and file name. Then write them into hidden element (#additional-information)
var plugin = navigator.plugins[i];
bug.value += "* " + plugin.name + " ("+plugin.description+") "+plugin.filename+"\r\n";
}
}
// learn screen resolution write them into hidden element (#additional-information)
bug.value += "\n\nSCREEN:" + separator;
if ((typeof(screen.width) != "undefined") && (screen.width && screen.height))
bug.value += "Resolution: " + screen.width + 'x' + screen.height + "\n";
// learn color depth and write them into hidden element (#additional-information)
if ((typeof(screen.colorDepth) != "undefined") && (screen.colorDepth))
bug.value += "ColorDepth: " + screen.colorDepth + "\r\n";
// platform states whether the system is Win32, 64-bit build, mac or linux
document.getElementById("OS").value = navigator.platform // default system form field value, but it is overwritten if this next thing works....
opera.extension.onmessage = function(e) {
if (e.data && e.data.system) document.getElementById("OS").value = e.data.system // ...if data arrives via messaging from the bgProcess, and it's the system info, then put it into the system field of the form.
}
var system = opera.extension.bgProcess.getOS(); // call the function
},false);
</script>
</body>
</html>