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

Commit d8f75ce

Browse files
committed
Load WhichBrowser with a timeout and a backup server (fixes #510 and #463)
1 parent 9f4df5e commit d8f75ce

File tree

3 files changed

+49
-50
lines changed

3 files changed

+49
-50
lines changed

index.html

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,6 @@
1717
<script src='/scripts/9/engine.js' type='text/javascript'></script>
1818
<script src='/scripts/9/data.js' type='text/javascript'></script>
1919

20-
<script>
21-
(function(){var p=[],w=window,d=document,e=f=0;p.push('ua='+encodeURIComponent(navigator.userAgent));e|=w.ActiveXObject?1:0;e|=w.opera?2:0;e|=w.chrome?4:0;
22-
e|='getBoxObjectFor' in d || 'mozInnerScreenX' in w?8:0;e|=('WebKitCSSMatrix' in w||'WebKitPoint' in w||'webkitStorageInfo' in w||'webkitURL' in w)?16:0;
23-
e|=(e&16&&({}.toString).toString().indexOf("\n")===-1)?32:0;p.push('e='+e);f|='sandbox' in d.createElement('iframe')?1:0;f|='WebSocket' in w?2:0;
24-
f|=w.Worker?4:0;f|=w.applicationCache?8:0;f|=w.history && history.pushState?16:0;f|=d.documentElement.webkitRequestFullScreen?32:0;f|='FileReader' in w?64:0;
25-
p.push('f='+f);p.push('r='+Math.random().toString(36).substring(7));p.push('w='+screen.width);p.push('h='+screen.height);var s=d.createElement('script');
26-
s.src='//api.whichbrowser.net/rel/detect.js?' + p.join('&');d.getElementsByTagName('head')[0].appendChild(s);})();
27-
</script>
28-
2920
<meta name="application-name" content="HTML5test"/>
3021

3122
<link rel="apple-touch-icon" sizes="57x57" href="/images/icons/apple-touch-icon-57x57.png" />
@@ -194,20 +185,6 @@ <h3>Help us improve HTML5 test by donating</h3>
194185
<script>
195186
<!--
196187

197-
198-
function waitForWhichBrowser(cb) {
199-
var callback = cb;
200-
201-
function wait() {
202-
if (typeof WhichBrowser == 'undefined')
203-
window.setTimeout(wait, 100)
204-
else
205-
callback();
206-
}
207-
208-
wait();
209-
}
210-
211188
function submit(method, payload) {
212189
var httpRequest;
213190
if (window.XMLHttpRequest) {
@@ -252,9 +229,8 @@ <h3>Help us improve HTML5 test by donating</h3>
252229

253230

254231

255-
256-
257-
waitForWhichBrowser(function() {
232+
233+
loadWhichBrowser(function() {
258234

259235
Browsers = new WhichBrowser({
260236
useFeatures: true,

qr.html

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@
3939
<script src='/scripts/base.js' type='text/javascript'></script>
4040
<script src='/scripts/9/engine.js' type='text/javascript'></script>
4141
<script src='/scripts/9/data.js' type='text/javascript'></script>
42-
43-
<script>
44-
(function(){var p=[],w=window,d=document,e=f=0;p.push('ua='+encodeURIComponent(navigator.userAgent));e|=w.ActiveXObject?1:0;e|=w.opera?2:0;e|=w.chrome?4:0;
45-
e|='getBoxObjectFor' in d || 'mozInnerScreenX' in w?8:0;e|=('WebKitCSSMatrix' in w||'WebKitPoint' in w||'webkitStorageInfo' in w||'webkitURL' in w)?16:0;
46-
e|=(e&16&&({}.toString).toString().indexOf("\n")===-1)?32:0;p.push('e='+e);f|='sandbox' in d.createElement('iframe')?1:0;f|='WebSocket' in w?2:0;
47-
f|=w.Worker?4:0;f|=w.applicationCache?8:0;f|=w.history && history.pushState?16:0;f|=d.documentElement.webkitRequestFullScreen?32:0;f|='FileReader' in w?64:0;
48-
p.push('f='+f);p.push('r='+Math.random().toString(36).substring(7));p.push('w='+screen.width);p.push('h='+screen.height);var s=d.createElement('script');
49-
s.src='//api.whichbrowser.net/rel/detect.js?' + p.join('&');d.getElementsByTagName('head')[0].appendChild(s);})();
50-
</script>
5142
</head>
5243

5344

@@ -56,21 +47,7 @@
5647
<script>
5748
<!--
5849

59-
60-
function waitForWhichBrowser(cb) {
61-
var callback = cb;
62-
63-
function wait() {
64-
if (typeof WhichBrowser == 'undefined')
65-
window.setTimeout(wait, 100)
66-
else
67-
callback();
68-
}
69-
70-
wait();
71-
}
72-
73-
waitForWhichBrowser(function() {
50+
loadWhichBrowser(function() {
7451

7552
Browsers = new WhichBrowser({
7653
useFeatures: true,

scripts/base.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,52 @@
6363

6464
/* Utility functions */
6565

66+
function loadWhichBrowser(cb) {
67+
var callback = cb;
68+
69+
var p=[],w=window,d=document,e=f=0;p.push('ua='+encodeURIComponent(navigator.userAgent));e|=w.ActiveXObject?1:0;e|=w.opera?2:0;e|=w.chrome?4:0;
70+
e|='getBoxObjectFor' in d || 'mozInnerScreenX' in w?8:0;e|=('WebKitCSSMatrix' in w||'WebKitPoint' in w||'webkitStorageInfo' in w||'webkitURL' in w)?16:0;
71+
e|=(e&16&&({}.toString).toString().indexOf("\n")===-1)?32:0;p.push('e='+e);f|='sandbox' in d.createElement('iframe')?1:0;f|='WebSocket' in w?2:0;
72+
f|=w.Worker?4:0;f|=w.applicationCache?8:0;f|=w.history && history.pushState?16:0;f|=d.documentElement.webkitRequestFullScreen?32:0;f|='FileReader' in w?64:0;
73+
p.push('f='+f);p.push('r='+Math.random().toString(36).substring(7));p.push('w='+screen.width);p.push('h='+screen.height);
74+
75+
var servers = [ 'api.whichbrowser.net', 'backup.whichbrowser.net' ];
76+
77+
var timeout = null;
78+
79+
function load() {
80+
if (typeof WhichBrowser != 'undefined') {
81+
return;
82+
}
83+
84+
var server = servers.shift();
85+
if (server) {
86+
var script = document.createElement('script');
87+
script.src = '//' + server + '/rel/detect.js?' + p.join('&');
88+
document.getElementsByTagName('head')[0].appendChild(script);
89+
90+
wait();
91+
}
92+
}
93+
94+
function wait() {
95+
if (!timeout) {
96+
timeout = window.setTimeout(load, 3000);
97+
}
98+
99+
if (typeof WhichBrowser == 'undefined') {
100+
window.setTimeout(wait, 100)
101+
}
102+
else {
103+
window.clearTimeout(timeout);
104+
callback();
105+
}
106+
}
107+
108+
load();
109+
}
110+
111+
66112
var tim = (function(){
67113
var starts = "\\{\\{",
68114
ends = "\\}\\}",

0 commit comments

Comments
 (0)