diff options
author | altaf-creator <dev@altafcreator.com> | 2025-06-30 20:55:53 +0800 |
---|---|---|
committer | altaf-creator <dev@altafcreator.com> | 2025-06-30 20:55:53 +0800 |
commit | 2780072a278fa5128cf961284e5c04312d5e6119 (patch) | |
tree | e971fb7a47d768de69b31feebc72993e49b229dc /frontend/script.js |
initial commit
Diffstat (limited to 'frontend/script.js')
-rw-r--r-- | frontend/script.js | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/frontend/script.js b/frontend/script.js new file mode 100644 index 0000000..5af0c08 --- /dev/null +++ b/frontend/script.js @@ -0,0 +1,56 @@ +document.addEventListener('DOMContentLoaded', () => { + const fileInput = document.getElementById('file-input'); + const fileList = document.getElementById('file-list'); + const btn = document.getElementById('doit-btn'); + const cont = document.getElementById('mindmap'); + + var files; + + fileInput.addEventListener('change', (event) => { + fileList.innerHTML = ""; + + files = event.target.files; + + for (let i = 0; i < files.length; i++) { + fileList.innerHTML += `<li>${files[i].name}</li>`; + } + }); + + btn.addEventListener('click', async () => { + if (files.length == 0) return; + + const formData = new FormData(); + + for (let i = 0; i < files.length; i++) { + formData.append('files', files[i]); + } + + cont.innerHTML = "Generating..."; + + const response = await fetch("http://127.0.0.1:9000/yeah", { + method: "POST", + body: formData + }) + + + const data = await response.json(); + + lines = data.map.split('\n') + + cont.innerHTML = ""; + + for (let i = 0; i < lines.length; i++) { + if (lines.length == 0) return; + + let depth = 0; + for (let j = 0; j < lines[i].length; j++) { + if (lines[i][j] == ">") { + depth++; + } else {break;} + } +console.log(lines[i].slice(depth, lines[i].length)) + cont.innerHTML += `<div style="display: flex; gap: 1rem;"><span style="opacity: 50%; margin-left: ${(depth - 1) * 2}rem"> ▸ </span><span>${lines[i].slice(depth, lines[i].length)}</span></div>`; + console.log(cont.innerHTML); + } + }); +}); |