Hanaz Writers

Expand Your Story

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
document.getElementById("expandBtn").addEventListener("click", expandStory); async function expandStory() { const prompt = document.getElementById("storyPromptInput").value.trim(); const chapters = document.getElementById("chapterSelect").value; const resultBox = document.getElementById("storyResultBox"); if (!prompt) { resultBox.innerHTML = "

Please enter a prompt.

"; return; } resultBox.innerHTML = "

Expanding story...

"; try { const response = await fetch("https://cd0b-2603-3-610c-620-00.ngrok-free.app/expand", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ prompt, chapters }) // send chapters too }); if (!response.ok) { throw new Error("Server responded with an error"); } const data = await response.json(); resultBox.innerHTML = `Expanded Story:
${data.expandedStory}`; } catch (err) { resultBox.innerHTML = `

Error: ${err.message}

`; } }