-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
72 lines (66 loc) · 3.3 KB
/
index.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
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BmbxuPwQa2lc/FVzBcNJ7UAyJxM6wuqIj61tLrc4wSX0szH/Ev+nYRRuWlolflfl" crossorigin="anonymous">
</head>
<body>
<script type="text/javascript">
/** Hello! There's almost nothing here.
Whole application is written in Swift, Combine, SwiftUI-like,
and compiled to single, wasm file.
Currently it takes about 10 MB to load, but it's fast, works offline,
and don't need any server side.
There are some caveats - UUID() don't work so we bridge here, and network calls are limited. https://github.com/swiftwasm/JavaScriptKit/pull/112
**/
window.uuid = function uuidv4() {
return ([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g, c =>
(c ^ crypto.getRandomValues(new Uint8Array(1))[0] & 15 >> c / 4).toString(16)
);
}
window.xpost = function(url, obj, handler) {
var text = "";
console.log('POST ' + url + ' body: ' + obj);
fetch(url, {
method: 'POST',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(obj)
})
.then(function(response) {
response.text().then(function(text) {
console.log('DONE')
console.log(text)
const obj = JSON.parse(text)
handler(obj)
})
})
.then(function(text) {
console.log('Request successful', text);
})
.catch(function(error) {
log('Request failed', error)
});
}
window.xfetch = function(url, handler) {
var text = "";
fetch(url, {mode: 'cors'})
.then(function(response) {
response.text().then(function(text) {
console.log('DONE')
console.log(text)
const obj = JSON.parse(text)
handler(obj)
})
})
.then(function(text) {
console.log('Request successful', text);
})
.catch(function(error) {
log('Request failed', error)
});
}
</script>
</body>
</html