wallart-server/web/script.mjs

35 lines
910 B
JavaScript
Raw Normal View History

2022-09-25 12:03:05 -06:00
function updateImages() {
for (let image of document.querySelectorAll('img')) {
let url = new URL(image.src)
url.searchParams.set("t", Date.now())
image.src = url.toString()
}
}
async function submit(event) {
event.preventDefault()
let form = event.target
let data = new FormData(form)
let url = form.action
let method = form.method
let headers = new Headers()
let resp = await fetch(url, {method, headers, body: data})
if (resp.ok) {
updateImages()
} else {
2023-09-02 16:10:23 -06:00
let body = await resp.text()
alert(`Error: ${resp.status} ${resp.statusText}\n\n${body}`)
2022-09-25 12:03:05 -06:00
}
}
function init() {
for (let f of document.querySelectorAll("form")) {
f.addEventListener("submit", event => submit(event))
}
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', init)
} else {
init()
}