-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript2.js
More file actions
149 lines (78 loc) · 2.96 KB
/
script2.js
File metadata and controls
149 lines (78 loc) · 2.96 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
const searchInput = document.querySelector("[data-search]")
function numberWithCommas(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
const options = {
headers: {
'x-access-token': 'coinrankingff642de6922ea15f6e86ee101fed8be6fc77756262b8eec2',
},
};
const apiUrl = 'https://api.coinranking.com/v2/coins'
setInterval(() => {
async function fetchData() {
const non_json = await fetch(apiUrl, options)
const json = await non_json.json()
const apiData = json.data
const coinData = apiData.coins
// console.log(coinData)
var Content = document.getElementById('content')
Content.innerHTML=''
coinData.forEach(user => {
var marketcap = numberWithCommas(user.marketCap)
var price = numberWithCommas(user.price)
var logo = user.iconUrl
var name = user.name
var symbol = user.symbol
var rank = user.rank
var color = user.color
const trow = document.createElement("tr")
trow.classList.add("box")
trow.innerHTML = `
<td>${rank}</td>
<td><img src="${logo}" alt="logo" width="30vw"></td>
<td class="coinName">${name} <span id="symbol">${symbol}</span></td>
<td>$ ${marketcap}</td>
<td>$ ${price}</td>
`
trow.color = color
trow.addEventListener("click", () => {
window.location.href = `${name}.html`
// return {name: user.name, symbol: user.symbol, element: trow}
})
Content.appendChild(trow);
// function searcherFunc(){
// searcher=coinData.map(element =>{
// // var naam = element.name
// // var symbo = element.symbol
// return {name: element.name, symbol: element.symbol }
// })
// }
// searcherFunc()
});
}
fetchData()
}, 2000);
// for(let i=0; i<searcher.length; i++){
// trow.classlist.add("krypto(i)")
// }
// const searchvalue = document.getElementsByClassName('search').value
searchInput.addEventListener("input", (e) => {
var value = e.target.value.toLowerCase();
var searcher = document.querySelectorAll('.box'); // All rows with class 'box'
var coinNames = document.getElementsByClassName('coinName'); // All elements with class 'coinName'
for (let i = 0; i <=coinNames.length; i++) {
var coinNameElement = searcher[i].querySelector('.coinName'); // Get the element with class 'coinName' inside each row
if (coinNameElement) {
var intext = coinNameElement.innerHTML || coinNameElement.innerText || coinNameElement.textContent;
if (intext.toLowerCase().indexOf(value) > -1) {
searcher[i].style.display = "table-row"; // Show matching rows
} else {
searcher[i].style.display = "none"; // Hide non-matching rows
}
}
}
});
// function colorFadeOut(b){
// b.style.color='green'
// var opacity =
// }