-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.js
58 lines (51 loc) · 1.85 KB
/
index.js
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
// foo
document.addEventListener('DOMContentLoaded', onready)
function decode_arguments_qp() {
if (window.location.search) {
var s = window.location.search.slice(1,window.location.search.length)
var parts = s.split('&')
var d = {}
for (var i=0; i<parts.length; i++) {
var sp = parts[i].split('=')
d[decodeURIComponent(sp[0])] = decodeURIComponent(sp[1])
}
}
return d
}
function onready() {
// decode uri
var params = decode_arguments_qp()
var port = params.port || 8682
//var args = "+skill 3 +map start"
if (params.disablesound == 'true') {
var args = '-nosound'
} else {
var args = "+map e1m4";
}
var startupstring = '?' + encodeURIComponent(args)
var url = 'http://127.0.0.1:'+port+'/WebQuake/Client/WebQuake.htm' + startupstring +'#delay=' +params.delay
var webview = document.createElement('webview')
webview.src = url
webview.sandbox = 'allow-pointer-lock'
webview.style.width = '100%'
webview.style.height = '100%'
document.getElementById('container').appendChild(webview)
//var webview = document.getElementById('webview')
var decidePermission = function(e) {
e.request.allow();
}
webview.addEventListener('permissionrequest', function(e) {
//console.log('permissionrequest',e)
if ( e.permission === 'pointerLock' ) {
// Calling e.preventDefault() is necessary to delay the response.
// If the default is not prevented then the default action is to
// deny the permission request.
//e.preventDefault();
//setTimeout(function() { decidePermission(e); }, 0);
// delay seems no longer necessary
decidePermission(e)
} else if (e.permission == 'fullscreen') {
decidePermission(e)
}
});
}