-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
74 lines (63 loc) · 1.7 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Arweave File Explorer</title>
<script src="https://unpkg.com/arweave/bundles/web.bundle.js"></script>
<!-- https://github.com/ArweaveTeam/arweave-js -->
<script>
function createTagsObject(tx){
tags = {};
tx['tags'].forEach(tag => {
const key = tag.get('name', {decode: true, string: true});
const value = tag.get('value', {decode: true, string: true});
// console.log(`${key} : ${value}`);
tags[key] = value;
});
return tags;
}
function createImage(txId){
const tmp = document.createElement('img');
tmp.src = "https://www.arweave.net/" + txId;
tmp.style = "width: 19%;";
document.body.appendChild(tmp);
}
function logTxTags(tx) {
const tags = createTagsObject(tx);
const contentType = tags["Content-Type"];
if (contentType && contentType.indexOf("image") != -1){
createImage(tx.id);
}
// image/jpeg
// image/png
}
const arweave = Arweave.init({
host: 'arweave.net',
port: 443,
protocol: 'https'
});
arweave.network.getInfo().then((info) => {
const { current: currentBlock } = info;
console.log("currentBlock: " + currentBlock);
document.getElementById("blockInfoElement").innerText = "Loading current block #" + info.height + " images";
arweave.blocks.get(currentBlock).then(blockData => {
// console.log(blockData);
const { txs } = blockData;
txs.forEach(
tx => arweave.transactions.get(tx).then(
transaction => {
logTxTags(transaction)
}
)
);
});
});
</script>
</head>
<body>
<h1>Arweave File Explorer</h1>
<span id="blockInfoElement"></span>
<br />
<br />
</body>
</html>