-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonero.html
136 lines (122 loc) · 3.62 KB
/
monero.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8' >
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<meta name='viewport' content='width=device-width, initial-scale=1'>
<title>Bitcoin clock</title>
<meta name='author' content='4x0'>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:wght@500&display=swap" rel="stylesheet">
<style>
body {
--bg-color: #222;
--fg-color: #444;
background: linear-gradient(
var(--bg-color) calc(50% - 10vw),
var(--fg-color) calc(50% - 10vw),
var(--fg-color) calc(50% + 10vw),
var(--bg-color) calc(50% + 10vw)
);
font-family: 'Roboto Mono', monospace;
margin: 0;
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
#height {
font-size: 9vw;
word-spacing: -3vw;
background: linear-gradient(
-45deg,
hsl(20.2, 88.9%, 54.1%),
white
);
background-clip: text;
color: transparent;
}
#volume {
position: fixed;
bottom: 0;
right: 0;
margin: 32px;
display: block;
appearance: slider-vertical;
}
</style>
</head>
<body>
<div id="height">0 000 000</div>
<input
id="volume"
type="range"
min="0"
max="100"
orient="vertical"
/>
<p style="display: none;">I made this to make it easier to know when my transactions have confirmed</p>
<script>
const createPlay = () => {
const tickAudio = new Audio('./tick.m4a');
return volume => {
tickAudio.volume = volume;
tickAudio
.play()
.catch(() => alert("You need to enable autoplay permission for this app to work"));
};
};
const r = v => v.split("").reverse().join("")
const formatHeight = height => (
r(r(String(height)).replace(/(...)/g, "$1 "))
)
const setHeight = height => {
document.querySelector("#height").textContent = formatHeight(height);
};
const getVolume = () => +document.querySelector("#volume").value / 100;
const createVolumeListener = cb => {
const volumeElem = document.querySelector("#volume");
const cbb = () => { cb(); }
volumeElem.addEventListener("change", cb);
return () => volumeElem.addEventListener("change", cb);
};
const getBlockHeight = async () => {
const res = await fetch("https://api.blockchair.com/monero/stats");
if (!res.ok) { throw new Error("res is not ok"); }
const blocks = (await res.json())?.data?.blocks;
if (!blocks) { throw new Error("res gave no blocks"); }
return blocks;
}
const createBlockHeightListener = cb => {
let lastBlockHeight;
const pingIntervalId = setInterval(async () => {
const blockHeight = await getBlockHeight();
if (lastBlockHeight && lastBlockHeight === blockHeight) {
return;
}
lastBlockHeight = blockHeight;
cb(blockHeight);
}, 1000 * 5);
return () => {
clearInterval(pingIntervalId);
};
};
window.addEventListener("load", event => {
setTimeout(() => {
const play = createPlay();
createBlockHeightListener(height => {
play(getVolume());
setHeight(height);
});
createVolumeListener(() => {
play(getVolume());
});
play(0.0001);
getBlockHeight().then(height => { setHeight(height); });
}, 500);
});
</script>
</body>
</html>