28 lines
884 B
JavaScript
28 lines
884 B
JavaScript
|
let searchField = document.createElement('input')
|
||
|
searchField.id = 'search-field'
|
||
|
searchField.autofocus = true
|
||
|
document.querySelector('.list').insertBefore(searchField, document.querySelector('table'))
|
||
|
|
||
|
try {
|
||
|
document.querySelector('a[href="../"]').innerText = '..'
|
||
|
} catch (e) {}
|
||
|
|
||
|
const rows = [...document.querySelectorAll('tbody tr')]
|
||
|
|
||
|
document.querySelector('#search-field').addEventListener("input", e => {
|
||
|
const searchValue = e.target.value.toLowerCase()
|
||
|
rows.forEach(row => {
|
||
|
const file = row.querySelector('td').innerText
|
||
|
if (!file.toLowerCase().startsWith(searchValue)) {
|
||
|
row.style.display = 'none'
|
||
|
} else {
|
||
|
row.style.display = 'table-row'
|
||
|
}
|
||
|
})
|
||
|
|
||
|
const visibleRows = [...document.querySelectorAll('tr[style="display: table-row;"]')]
|
||
|
if (visibleRows.length === 1) {
|
||
|
window.location = visibleRows[0].querySelector('td a').href
|
||
|
}
|
||
|
})
|