forked from iWarpBTC/iWarpBTC.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
49 lines (42 loc) · 1.2 KB
/
functions.js
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
const api_url = 'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=czk';
async function getapi(url) {
const response = await fetch(url);
var data = await response.json();
//console.log(data);
if (response) {
show(data);
}
}
getapi(api_url);
function show(data) {
satsperczk = (1 / data.bitcoin.czk * 100000000).toFixed(0);
czkpersats = (data.bitcoin.czk / 100000000).toFixed(0);
h2 = document.createElement('h2');
h2.className = 'price';
if (czkpersats >= 1)
{
mena = 'korun';
if (czkpersats == 1)
mena = 'koruna';
else if (czkpersats < 5)
mena = 'koruny';
h2.innerHTML = `<span>${czkpersats} ${mena} za satoshi</span>`;
}
else
{
h2.innerHTML = `<span>${satsperczk} satoshi za korunu</span>`;
}
div = document.getElementById('satoshidiv');
before = document.getElementById('satoshi');
div.insertBefore(h2, before);
img = document.createElement('img');
img.src = 'https://btc-slovnik.cz/img/tag.png';
img.height = 25;
img.alt = "cena";
img.className = "pricetag";
h2.insertBefore(img, h2.firstChild);
}
function clipboardLink(val) {
text = 'https://btc-slovnik.cz/#'+val
navigator.clipboard.writeText(text)
}