31 lines
879 B
JavaScript
31 lines
879 B
JavaScript
function addOptions(files) {
|
|
const select = document.getElementById("file-sel")
|
|
select.innerHTML = ""
|
|
const defaultOpt = document.createElement("option")
|
|
defaultOpt.innerText = "----- Select a file -----"
|
|
defaultOpt.value = ""
|
|
select.appendChild(defaultOpt)
|
|
files.sort().forEach(file => {
|
|
const option = document.createElement("option")
|
|
option.innerText = file
|
|
option.value = file
|
|
select.appendChild(option)
|
|
})
|
|
}
|
|
|
|
function selectFile(event) {
|
|
const file = event.target.value
|
|
if (file !== "") {
|
|
const url = new URL("/edit/", window.location.origin)
|
|
url.searchParams.set("f", file)
|
|
window.location.href = url.href
|
|
}
|
|
}
|
|
|
|
window.addEventListener("load", () => {
|
|
fetch("/api/files").then(res => {
|
|
return res.json()
|
|
}).then(files => {
|
|
addOptions(files)
|
|
})
|
|
}) |