-
Notifications
You must be signed in to change notification settings - Fork 406
Expand file tree
/
Copy pathtable-search.js
More file actions
53 lines (44 loc) · 1.74 KB
/
table-search.js
File metadata and controls
53 lines (44 loc) · 1.74 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
(function () {
const searchInput = document.getElementById('searchInput');
const collectionTable = document.getElementById('collectionTable');
if (!searchInput || !collectionTable) {
return;
}
const rows = collectionTable.getElementsByTagName('tr');
function performSearch() {
const searchValue = searchInput.value.toLowerCase();
for (let i = 1; i < rows.length; i++) {
const name = rows[i].getElementsByTagName('td')[0].textContent.toLowerCase();
const maintainer = rows[i].getElementsByTagName('td')[1].textContent.toLowerCase();
const repository = rows[i].getElementsByTagName('td')[2] ? rows[i].getElementsByTagName('td')[2].textContent.toLowerCase() : '';
if (name.includes(searchValue) || maintainer.includes(searchValue) || repository.includes(searchValue)) {
rows[i].style.display = '';
} else {
rows[i].style.display = 'none';
}
}
}
function updateURL() {
const url = new URL(window.location);
if (searchInput.value) {
url.searchParams.set('search', searchInput.value);
} else {
url.searchParams.delete('search');
}
window.history.replaceState({}, '', url);
}
function loadSearchFromURL() {
const urlParams = new URLSearchParams(window.location.search);
const searchParam = urlParams.get('search');
if (searchParam) {
searchInput.value = searchParam;
performSearch();
}
}
searchInput.addEventListener('input', function () {
performSearch();
updateURL();
});
// Initialize search from URL on page load
loadSearchFromURL();
})();