-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplorers.js
128 lines (111 loc) · 4.21 KB
/
explorers.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
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
document.addEventListener('DOMContentLoaded', function() {
const searchInput = document.getElementById('search');
const listContainer = document.getElementById('list');
const paginationContainer = document.getElementById('pagination-buttons');
const prevPageButton = document.getElementById('prevPage');
const nextPageButton = document.getElementById('nextPage');
const firstPageButton = document.getElementById('firstPage');
const lastPageButton = document.getElementById('lastPage');
const loadingIndicator = document.getElementById('loading');
const itemsPerPage = 20; // Updated to 20 items per page to match grid
let currentPage = 1;
let totalPages = 1;
let allData = [];
let filteredData = [];
const webPageUrl = 'https://docs.google.com/spreadsheets/u/1/d/e/2PACX-1vSTKLXEgIRbqLvXOSEOyHxPTkQyND5YfBBLLce-mNxR7f-WIDEAyuy0SrB1u_p2DDVmnCx1413RWIsn/pubhtml?gid=1520699041&single=true'; // Replace with your published web page URL
function fetchBlockchainData() {
showLoading(true);
fetch(webPageUrl)
.then(response => response.text())
.then(data => {
const parser = new DOMParser();
const doc = parser.parseFromString(data, 'text/html');
const rows = Array.from(doc.querySelectorAll('table tbody tr')).slice(1); // Skip the first row
allData = rows.map(row => {
const cells = row.querySelectorAll('td');
return {
name: cells[0].innerText.trim(),
link: cells[1].innerText.trim(),
category: cells[2].innerText.trim()
};
});
filterAndRender();
showLoading(false);
})
.catch(error => {
console.error('<span class="alert-negative"">Error fetching data from the web page:</span>', error);
showLoading(false);
});
}
function renderList(data, page = 1) {
listContainer.innerHTML = '';
const start = (page - 1) * itemsPerPage;
const end = start + itemsPerPage;
const paginatedItems = data.slice(start, end);
paginatedItems.forEach(item => {
const listItem = document.createElement(item.link ? 'a' : 'div');
listItem.className = 'list-item';
if (item.link) {
listItem.href = item.link;
listItem.target = '_blank';
}
listItem.innerHTML = `
<div>${item.name}</div>`;
listContainer.appendChild(listItem);
});
renderPagination(data.length, page);
}
function renderPagination(totalItems, page) {
paginationContainer.innerHTML = '';
totalPages = Math.ceil(totalItems / itemsPerPage);
for (let i = 1; i <= totalPages; i++) {
const pageItem = document.createElement('button');
pageItem.innerText = i;
pageItem.className = i === page ? 'active' : '';
pageItem.addEventListener('click', () => {
currentPage = i;
renderList(filteredData, currentPage);
});
paginationContainer.appendChild(pageItem);
}
prevPageButton.disabled = currentPage === 1;
nextPageButton.disabled = currentPage === totalPages;
firstPageButton.disabled = currentPage === 1;
lastPageButton.disabled = currentPage === totalPages;
}
function filterAndRender() {
const searchTerm = searchInput.value.toLowerCase();
filteredData = allData.filter(item => item.name.toLowerCase().includes(searchTerm));
renderList(filteredData, currentPage);
}
function showLoading(isLoading) {
loadingIndicator.style.display = isLoading ? 'block' : 'none';
listContainer.style.display = isLoading ? 'none' : 'grid';
}
searchInput.addEventListener('input', () => {
currentPage = 1;
filterAndRender();
});
prevPageButton.addEventListener('click', () => {
if (currentPage > 1) {
currentPage--;
renderList(filteredData, currentPage);
}
});
nextPageButton.addEventListener('click', () => {
if (currentPage < totalPages) {
currentPage++;
renderList(filteredData, currentPage);
}
});
firstPageButton.addEventListener('click', () => {
currentPage = 1;
renderList(filteredData, currentPage);
});
lastPageButton.addEventListener('click', () => {
currentPage = totalPages;
renderList(filteredData, currentPage);
});
// Initial fetch and render
fetchBlockchainData();
});