Skip to content
This repository was archived by the owner on Apr 11, 2024. It is now read-only.

Commit de5372a

Browse files
committed
Upgrade to HTTPS
Instead of showing a warning for users on HTTP, test if the browser can see the HTTPS version of the site and if so, redirect
1 parent 8b7ae12 commit de5372a

File tree

3 files changed

+154
-119
lines changed

3 files changed

+154
-119
lines changed

.htaccess

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ RewriteRule ^scripts/useragents http://api.whichbrowser.net/warning.js
5050
</IfModule>
5151
</FilesMatch>
5252

53+
<FilesMatch "upgrade">
54+
<IfModule mod_headers.c>
55+
Header set Access-Control-Allow-Origin "*"
56+
</IfModule>
57+
</FilesMatch>
58+
5359

5460
SetEnvIf User-Agent .*Bada.* BROKEN_CSP
5561

assets/upgrade

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
OK

index.html

Lines changed: 147 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,51 @@ <h3>Help us improve HTML5 test by donating</h3>
208208
wait();
209209
}
210210

211+
function submit(method, payload) {
212+
var httpRequest;
213+
if (window.XMLHttpRequest) {
214+
httpRequest = new XMLHttpRequest();
215+
} else if (window.ActiveXObject) {
216+
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
217+
}
218+
219+
httpRequest.open('POST','/api/' + method, true);
220+
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
221+
httpRequest.send('payload=' + encodeURIComponent(payload));
222+
}
223+
224+
function upgradeConnection(success, failure) {
225+
if (location.protocol == "http:") {
226+
var httpRequest;
227+
228+
if (window.XMLHttpRequest) {
229+
httpRequest = new XMLHttpRequest();
230+
} else if (window.ActiveXObject) {
231+
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
232+
}
233+
234+
httpRequest.onreadystatechange = function() {
235+
if (httpRequest.readyState == 4) {
236+
if (httpRequest.status >= 200 && httpRequest.status < 400) {
237+
success();
238+
} else {
239+
failure();
240+
}
241+
}
242+
}
243+
244+
httpRequest.open('GET','https://' + location.hostname + '/assets/upgrade', true);
245+
httpRequest.send();
246+
247+
return;
248+
}
249+
250+
failure();
251+
}
252+
253+
254+
255+
211256

212257
waitForWhichBrowser(function() {
213258

@@ -314,128 +359,111 @@ <h3>Help us improve HTML5 test by donating</h3>
314359
}
315360

316361

317-
/* Update total score */
318-
var container = document.getElementById('score');
319-
320-
container.innerHTML = tim(
321-
"<div class='pointsPanel'>" +
322-
"<h2><span>Your browser scores</span> <strong>{{score}}</strong> <span>out of {{maximum}} points</span></h2>" +
323-
"</div>",
324-
c);
325-
326-
/* Show box for confirming useragent detection */
327-
new Confirm(container, {
328-
id: r.uniqueid,
329-
onConfirm: function() { submit('confirm', '{"uniqueid": "' + r.uniqueid + '"}'); },
330-
onReport: function() { submit('report', '{"uniqueid": "' + r.uniqueid + '"}'); },
331-
onFeedback: function(value) { submit('feedback', JSON.stringify({ uniqueid: r.uniqueid, value: value })); }
332-
});
333-
334-
/* Show action buttons */
335-
var wrapper = document.createElement('div');
336-
wrapper.className = 'wrapper';
337-
container.appendChild(wrapper);
338-
339-
var buttons = document.createElement('div');
340-
buttons.className = 'buttons';
341-
wrapper.appendChild(buttons);
342-
343-
var button = document.createElement('span');
344-
button.className = 'button save';
345-
button.innerHTML = '<span>Save results</span>';
346-
buttons.appendChild(button);
347-
348-
new Save(button, {
349-
id: r.uniqueid,
350-
onSave: function() { submit('save', '{"uniqueid": "' + r.uniqueid + '"}'); }
351-
});
352-
353-
var button = document.createElement('a');
354-
button.className = 'button compare';
355-
button.href = '/compare/browser/mybrowser.html';
356-
button.innerHTML = '<span>Compare to...</span>';
357-
buttons.appendChild(button);
358-
359-
var button = document.createElement('span');
360-
button.className = 'button share';
361-
button.innerHTML = '<span>Share</span>';
362-
buttons.appendChild(button);
363-
364-
new Share(button, {
365-
score: c.score,
366-
browser: Browsers.toString()
367-
});
368-
369-
var button = document.createElement('a');
370-
button.className = 'button donate';
371-
button.href = 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9DNBJPQFEHYSC';
372-
button.innerHTML = '<span>Donate</span>';
373-
buttons.appendChild(button);
374-
375-
376-
if (location.protocol == "http:") {
377-
var warning = document.createElement('div');
378-
warning.className = 'upgradeWarning';
379-
warning.innerHTML =
380-
"<h4>Your browser may support even more features on a secure connection</h4>" +
381-
"<p>Modern browsers only support some advanced features using on websites that uses a secure connection. " +
382-
"This is because these features expose privacy sensitive data. Because you are now using an insecure connection, " +
383-
"these features may not be available and are not detected.</p>" +
384-
"<a href='https://html5test.com'>Try again, but using a secure connection</a>";
385-
386-
container.appendChild(warning);
387-
}
388-
389-
390-
391-
392-
/* Show detailed report of scores */
393-
var container = document.getElementById('results');
394-
var div = document.createElement('div');
395-
div.className = 'resultsTable detailsTable';
396-
container.appendChild(div);
397-
398-
var table = new ResultsTable({
399-
parent: div,
400-
tests: m.data,
401-
header: false,
402-
links: true,
403-
explainations: true,
404-
grading: true,
405-
bonus: true,
406-
distribute: true,
407-
columns: 1
408-
});
409-
410-
table.updateColumn(0, { points: c.points, maximum: c.maximum, score: c.score, results: r.results });
411-
412-
new Index({
413-
tests: tests,
414-
index: document.getElementById('index'),
415-
wrapper: document.getElementById('contentwrapper')
416-
});
417362

363+
364+
365+
366+
upgradeConnection(
367+
function() {
368+
location.protocol = 'https:';
369+
},
370+
function() {
371+
372+
/* Update total score */
373+
var container = document.getElementById('score');
374+
375+
container.innerHTML = tim(
376+
"<div class='pointsPanel'>" +
377+
"<h2><span>Your browser scores</span> <strong>{{score}}</strong> <span>out of {{maximum}} points</span></h2>" +
378+
"</div>",
379+
c);
380+
381+
/* Show box for confirming useragent detection */
382+
new Confirm(container, {
383+
id: r.uniqueid,
384+
onConfirm: function() { submit('confirm', '{"uniqueid": "' + r.uniqueid + '"}'); },
385+
onReport: function() { submit('report', '{"uniqueid": "' + r.uniqueid + '"}'); },
386+
onFeedback: function(value) { submit('feedback', JSON.stringify({ uniqueid: r.uniqueid, value: value })); }
387+
});
388+
389+
/* Show action buttons */
390+
var wrapper = document.createElement('div');
391+
wrapper.className = 'wrapper';
392+
container.appendChild(wrapper);
393+
394+
var buttons = document.createElement('div');
395+
buttons.className = 'buttons';
396+
wrapper.appendChild(buttons);
397+
398+
var button = document.createElement('span');
399+
button.className = 'button save';
400+
button.innerHTML = '<span>Save results</span>';
401+
buttons.appendChild(button);
402+
403+
new Save(button, {
404+
id: r.uniqueid,
405+
onSave: function() { submit('save', '{"uniqueid": "' + r.uniqueid + '"}'); }
406+
});
407+
408+
var button = document.createElement('a');
409+
button.className = 'button compare';
410+
button.href = '/compare/browser/mybrowser.html';
411+
button.innerHTML = '<span>Compare to...</span>';
412+
buttons.appendChild(button);
413+
414+
var button = document.createElement('span');
415+
button.className = 'button share';
416+
button.innerHTML = '<span>Share</span>';
417+
buttons.appendChild(button);
418+
419+
new Share(button, {
420+
score: c.score,
421+
browser: Browsers.toString()
422+
});
423+
424+
var button = document.createElement('a');
425+
button.className = 'button donate';
426+
button.href = 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9DNBJPQFEHYSC';
427+
button.innerHTML = '<span>Donate</span>';
428+
buttons.appendChild(button);
429+
430+
431+
/* Show detailed report of scores */
432+
var container = document.getElementById('results');
433+
var div = document.createElement('div');
434+
div.className = 'resultsTable detailsTable';
435+
container.appendChild(div);
436+
437+
var table = new ResultsTable({
438+
parent: div,
439+
tests: m.data,
440+
header: false,
441+
links: true,
442+
explainations: true,
443+
grading: true,
444+
bonus: true,
445+
distribute: true,
446+
columns: 1
447+
});
448+
449+
table.updateColumn(0, { points: c.points, maximum: c.maximum, score: c.score, results: r.results });
450+
451+
new Index({
452+
tests: tests,
453+
index: document.getElementById('index'),
454+
wrapper: document.getElementById('contentwrapper')
455+
});
456+
457+
window.setTimeout(function() {
458+
var contents = document.getElementById('contents');
459+
contents.style.visibility = 'visible';
460+
461+
var loading = document.getElementById('loading');
462+
loading.style.display = 'none';
463+
}, 100);
418464

419-
function submit(method, payload) {
420-
var httpRequest;
421-
if (window.XMLHttpRequest) {
422-
httpRequest = new XMLHttpRequest();
423-
} else if (window.ActiveXObject) {
424-
httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
425465
}
426-
427-
httpRequest.open('POST','/api/' + method, true);
428-
httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
429-
httpRequest.send('payload=' + encodeURIComponent(payload));
430-
}
431-
432-
window.setTimeout(function() {
433-
var contents = document.getElementById('contents');
434-
contents.style.visibility = 'visible';
435-
436-
var loading = document.getElementById('loading');
437-
loading.style.display = 'none';
438-
}, 100);
466+
);
439467
},
440468

441469
function(e) {

0 commit comments

Comments
 (0)