-
Notifications
You must be signed in to change notification settings - Fork 4
/
testpage.html
77 lines (73 loc) · 2.12 KB
/
testpage.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
77
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>window.ipfs test page</title>
<style>
body {
font-family: sans-serif;
height: 100vh;
background: linear-gradient(to bottom,#041727 0%,#062b3f 100%);
color: white;
text-align: center;
padding-top: 50px;
}
div {
margin-top: 50px;
}
</style>
</head>
<body>
<h1>Is IPFS in the browser yet?</h1>
<div><code>window.ipfs</code> exists? <span id="status">Loading</span></div>
<div>Your ID: <span id='peerid'>N/A</span></div>
<div>
<h2>Add content</h2>
<input class='add-input' type="text"><button class='add-button'>Add</button>
<div class="add-output"></div>
</div>
<div>
<h2>Cat content</h2>
<input class='cat-input' type="text"><button class='cat-button'>Cat</button>
<div class="cat-output"></div>
</div>
<script>
$status = document.querySelector('#status')
$peerID = document.querySelector('#peerid')
$addOutput = document.querySelector('.add-output')
$addButton = document.querySelector('.add-button')
$addInput = document.querySelector('.add-input')
$catOutput = document.querySelector('.cat-output')
$catButton = document.querySelector('.cat-button')
$catInput = document.querySelector('.cat-input')
if (typeof window.ipfs === 'undefined') {
$status.innerText = 'nope'
} else {
$status.innerText = 'YEAH!'
window.ipfs.id((err, res) => {
if (err) throw err
$peerID.innerText = res.id
})
$addButton.addEventListener('click', () => {
const content = $addInput.value
window.ipfs.add(content, (err, res) => {
if (err) throw err
console.log('Got res')
console.log(res)
$addOutput.innerText = res[0].hash
})
}, false)
$catButton.addEventListener('click', () => {
const hash = $catInput.value
console.log('cat')
window.ipfs.cat(hash, (err, res) => {
if (err) throw err
console.log('testpage', res)
$catOutput.innerText = res
})
}, false)
}
</script>
</body>
</html>