-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathscript.js
33 lines (30 loc) · 1.23 KB
/
script.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
function bitcoinSet(currency, country) {
const value = document.getElementById(`value-${currency}`);
fetch(`https://api.coinbase.com/v2/prices/spot?currency=${currency}`, {
method: 'GET',
})
.then(response => response.json())
.then((result) => {
const params = Object.fromEntries(new URLSearchParams(location.search));
if (params.bgcolor) {
const test = document.getElementById("bitcoin");
test.style.backgroundColor = `#${params.bgcolor}`
}
if (params.color) {
const test = document.getElementById("bitcoin");
test.style.color = `#${params.color}`
}
const quantity = params.quantity || 1
const parseValue = parseFloat(result.data.amount);
const total = parseValue * quantity;
const info = total.toLocaleString(country, { style: 'currency', currency });
value.innerHTML = info
})
.catch(error => console.log('error', error));
setTimeout(function() {
bitcoinSet(currency, country)
}, 30000);
}
bitcoinSet("eur", "eur")
bitcoinSet("usd", "usd")
bitcoinSet("brl", "pt-br")