-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
75 lines (72 loc) · 3.31 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="Tezos on-chain website viewer">
<title>WEBZOS</title>
<link rel="icon" type="image/svg+xml" href="favicon.svg">
<style>
@keyframes rotate {
from {transform: rotate(180deg)}
to {transform: rotate(360deg)}
}
</style>
</head>
<body>
<script>
addr = (location.search || location.hash).slice(1).split(/[^\da-z]/i)[0]
url1 = 'https://api.tzkt.io/v1/contracts/' + addr + '/storage'
url2 = 'https://api.better-call.dev/v1/contract/mainnet/' + addr + '/storage/raw'
function render(data) {
bytes = Uint8Array.from(data.match(/../g), x => parseInt(x, 16))
header = (new TextDecoder).decode(bytes.slice(0, 1024))
dom = (new DOMParser).parseFromString(header, 'text/html')
encoding = dom.getElementsByTagName('meta')[0]?.getAttribute('charset')
content = (new TextDecoder(encoding)).decode(bytes)
content = content.replace(/^data:text\/html;charset=utf-8,/, '') // Deal with my legacy prefix
document.write(content)
document.close() // Needed to ensure that any style changes added after a script are applied
}
function help() {
fetch('https://raw.githubusercontent.com/wbtz/wbtz.github.io/main/README.md')
.then(response => response.text())
.then(text => {
readme = text
fetch('https://api.github.com/markdown', {
method: 'POST',
body: JSON.stringify({text: readme})
})
.then(response => {
if (!response.ok) throw 'Error0'
return response.text()
})
.then(text => readme = text)
.catch(() => document.body.style.whiteSpace = 'pre')
.finally(() => {
with(document.body) {
style.font = '1.75vh system-ui,-apple-system,Segoe UI,Roboto,Helvetica Neue,Noto Sans,Liberation Sans,Arial,sans-serif'
style.margin = '2em'
innerHTML = readme
style.animation = 'rotate 0.5s'
}
})
})
}
if (!addr.startsWith('KT')) help()
else fetch(url1)
.then(response => {
if (!response.ok) throw 'Error1'
return response.json()
})
.then(data => render(data))
.catch(() => fetch(url2)
.then(response => {
if (!response.ok) throw 'Error2'
return response.json()
})
.then(data => render(data.slice(2))) // Discard 0x
.catch(() => help())
)
</script>
</body>
</html>