|
| 1 | +(function () { |
| 2 | + const searchInput = document.getElementById('searchInput'); |
| 3 | + const collectionTable = document.getElementById('collectionTable'); |
| 4 | + |
| 5 | + if (!searchInput || !collectionTable) { |
| 6 | + return; |
| 7 | + } |
| 8 | + |
| 9 | + const rows = collectionTable.getElementsByTagName('tr'); |
| 10 | + |
| 11 | + function performSearch() { |
| 12 | + const searchValue = searchInput.value.toLowerCase(); |
| 13 | + |
| 14 | + for (let i = 1; i < rows.length; i++) { |
| 15 | + const name = rows[i].getElementsByTagName('td')[0].textContent.toLowerCase(); |
| 16 | + const maintainer = rows[i].getElementsByTagName('td')[1].textContent.toLowerCase(); |
| 17 | + const repository = rows[i].getElementsByTagName('td')[2] ? rows[i].getElementsByTagName('td')[2].textContent.toLowerCase() : ''; |
| 18 | + |
| 19 | + if (name.includes(searchValue) || maintainer.includes(searchValue) || repository.includes(searchValue)) { |
| 20 | + rows[i].style.display = ''; |
| 21 | + } else { |
| 22 | + rows[i].style.display = 'none'; |
| 23 | + } |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + function updateURL() { |
| 28 | + const url = new URL(window.location); |
| 29 | + if (searchInput.value) { |
| 30 | + url.searchParams.set('search', searchInput.value); |
| 31 | + } else { |
| 32 | + url.searchParams.delete('search'); |
| 33 | + } |
| 34 | + window.history.replaceState({}, '', url); |
| 35 | + } |
| 36 | + |
| 37 | + function loadSearchFromURL() { |
| 38 | + const urlParams = new URLSearchParams(window.location.search); |
| 39 | + const searchParam = urlParams.get('search'); |
| 40 | + if (searchParam) { |
| 41 | + searchInput.value = searchParam; |
| 42 | + performSearch(); |
| 43 | + } |
| 44 | + } |
| 45 | + |
| 46 | + searchInput.addEventListener('input', function () { |
| 47 | + performSearch(); |
| 48 | + updateURL(); |
| 49 | + }); |
| 50 | + |
| 51 | + // Initialize search from URL on page load |
| 52 | + loadSearchFromURL(); |
| 53 | +})(); |
0 commit comments