-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
29 lines (25 loc) · 1 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
document.getElementById('loadStars').addEventListener('click', function() {
fetchData('https://api.opensauced.pizza/v2/histogram/top/stars', 'starRows');
});
document.getElementById('loadForks').addEventListener('click', function() {
fetchData('https://api.opensauced.pizza/v2/histogram/top/forks', 'forkRows');
});
function fetchData(url, elementId) {
fetch(url)
.then(response => response.json())
.then(data => {
const tableBody = document.getElementById(elementId);
tableBody.innerHTML = ''; // Clear existing data
// Slice the data to display only the first 10 items
data.slice(0, 10).forEach(item => {
const row = `<tr>
<td>${item.repo_name}</td>
<td>${item.star_count || item.fork_count}</td>
</tr>`;
tableBody.innerHTML += row;
});
})
.catch(error => {
console.error('Error fetching data:', error);
});
}