This repository has been archived on 2019-03-24. You can view files and clone it, but cannot push or open issues/pull-requests.
lighttpd/assets/listing.js

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
}
})