feat: add web editor base
This commit is contained in:
31
editor/public/index.js
Normal file
31
editor/public/index.js
Normal file
@ -0,0 +1,31 @@
|
||||
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.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)
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user