// Upload files uploadBtn.addEventListener('click', async () => { if (!files.length) return; const form = new FormData(); files.forEach(f => form.append("files", f)); try { const res = await fetch("http://127.0.0.1:8000/upload", { method: "POST", body: form }); const data = await res.json(); // Clear old output output.innerHTML = ""; // Assuming backend returns { ids: ["abc123", "def456"] } data.ids.forEach((id, index) => { const snippet = `${files[index]?.name || `; // Create wrapper const wrapper = document.createElement("div"); wrapper.style.marginBottom = "20px"; // Pre block const pre = document.createElement("pre"); pre.textContent = snippet; // Copy button const copyBtn = document.createElement("button"); copyBtn.textContent = "Copy"; copyBtn.className = "btn"; copyBtn.style.marginTop = "8px"; copyBtn.addEventListener("click", () => { navigator.clipboard.writeText(snippet).then(() => { copyBtn.textContent = "Copied!"; setTimeout(() => (copyBtn.textContent = "Copy"), 1500); }); }); wrapper.appendChild(pre); wrapper.appendChild(copyBtn); output.appendChild(wrapper); }); } catch (err) { output.textContent = "Upload failed: " + err; } });