-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
73 lines (68 loc) · 2.02 KB
/
Copy pathapp.js
File metadata and controls
73 lines (68 loc) · 2.02 KB
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
const form = document.querySelector('#searchForm');
const res = document.querySelector('#resTable');
const cont = document.getElementById("allContaint");
var rec;
form.addEventListener('submit',(e)=>{
e.preventDefault();
if(rec){
clearTimeout(rec);
}
const ctype = form.elements.coinType.value;
cont.classList.add('mainClick');
cont.classList.remove('main');
fetchPrice(ctype);
});
const fetchPrice = async(ctype) =>{
const r = await axios.get(`https://api.cryptonator.com/api/ticker/${ctype}`);
console.log(r.data.ticker.price);
showPrice(r.data.ticker,r.data.timestamp);
rec = setTimeout(() => fetchPrice(`https://api.cryptonator.com/api/ticker/${ctype}`), 10000);
}
function timeConverter(UNIX_timestamp){
var a = new Date(UNIX_timestamp * 1000);
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
var year = a.getFullYear();
var month = months[a.getMonth()];
var date = a.getDate();
var hour = a.getHours();
var min = a.getMinutes();
var sec = a.getSeconds();
var time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
return time;
}
const showPrice = (ticker,timestamp)=>{
const time = timeConverter(timestamp);
const price = ticker.price;
const vol = ticker.volume;
const change = ticker.change;
const coin = ticker.base;
const curr = ticker.target;
var col= "green";
if(change<0){
col = "red";
}
res.innerHTML = `<tr class="bg-primary" style="color: white;">
<td>
Property
</td>
<td>
Value
</td>
</tr>
<tr>
<td>${coin}</td>
<td style="color:${col};"><span style="font-size: 1.3em;">${price}</span> ${curr}</td>
</tr>
<tr>
<td>Volume (24hrs)</td>
<td>${vol}</td>
</tr>
<tr>
<td>Change (24hrs)</td>
<td style="color:${col};">${change} ${curr}</td>
</tr>
<tr>
<td>Last Update</td>
<td>${time}</td>
</tr>`;
};