-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
76 lines (66 loc) · 2.17 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
73
74
75
76
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" name="publisher" content="QmRftzEbreVTdWSwbwSogVoNSbs4XEtX2TJewFJkh2dTvB">
<title>IBIPFS is the distributed web in browser.</title>
<link rel="icon" href="fav.png">
</head>
<body>
<!-- ibipfs usage sample -->
<script type="text/javascript">
function loadFile(file, onloadFunction) {
const fileType = (file.scriptURL || file.type === 'text/javascript') ? 'script' : (file.type === 'text/css' ? 'style' : undefined)
if (!fileType) {
return
}
let newLoadedElem
switch (fileType) {
case 'script':
newLoadedElem = document.createElement('script');
newLoadedElem.type = 'text/javascript'
document.currentScript ?
document.currentScript.parentNode.insertBefore(newLoadedElem, document.currentScript) :
document.body.append(newLoadedElem)
newLoadedElem.src = file.scriptURL || URL.createObjectURL(file.slice())
break
case 'style':
newLoadedElem = document.createElement('style');
newLoadedElem.type = 'text/css'
new Response(file.slice())
.text()
.then((content) => {
newLoadedElem.innerHTML = content
})
document.head.append(newLoadedElem)
break
}
newLoadedElem.onerror = () => {
throw new URIError("The script " + oError.target.src + " didn't load correctly.")
}
if (onloadFunction) {
newLoadedElem.onload = onloadFunction
}
}
window.onload = () => {
window.addEventListener("ibipfs", () => {
window.ibipfs && window.ibipfs.on('start', () => {
window.ibipfs
.cat('QmZCWqxc3fzvqVLhL64yweZhuWoLeqP5iUNtLqkb5rX7NR', (err, file) => {
if (err) {
console.log('Error: ' + err)
return
}
let imgElem = new Image();
imgElem.setAttribute('width', '100%')
imgElem.setAttribute('height', 'window.screen.height')
imgElem.src = 'data:image/jpg;base64,' + file.toString('base64')
document.body.prepend(imgElem)
})
})
})
loadFile({ "scriptURL": "ibipfs.js"})
}
</script>
<!-- ibipfs usage sample -->
</body>
</html>