Sami Bouhussein commited on
Commit ·
be1e2ba
1
Parent(s): 9c43c90
getElems by ids
Browse files- static/script.js +20 -18
static/script.js
CHANGED
|
@@ -1,21 +1,23 @@
|
|
| 1 |
-
|
|
|
|
| 2 |
|
| 3 |
-
const translateText = async (text) => {
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
};
|
| 14 |
|
| 15 |
-
textGenForm.addEventListener("submit", async (event) => {
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
});
|
|
|
|
| 1 |
+
document.addEventListener("DOMContentLoaded", () => {
|
| 2 |
+
const textGenForm = document.querySelector(".text-gen-form");
|
| 3 |
|
| 4 |
+
const translateText = async (text) => {
|
| 5 |
+
const inferResponse = await fetch("/translate", {
|
| 6 |
+
method: "POST",
|
| 7 |
+
headers: { "Content-Type": "application/json" },
|
| 8 |
+
body: JSON.stringify({ text }),
|
| 9 |
+
});
|
| 10 |
+
console.log("Trying to translate text");
|
| 11 |
+
console.log(text)
|
| 12 |
+
const inferJson = await inferResponse.json();
|
| 13 |
+
return inferJson.translation;
|
| 14 |
+
};
|
| 15 |
|
| 16 |
+
textGenForm.addEventListener("submit", async (event) => {
|
| 17 |
+
console.log("Submit bottom tapped");
|
| 18 |
+
event.preventDefault();
|
| 19 |
+
const textGenInput = document.getElementById("text-gen-input");
|
| 20 |
+
const textGenParagraph = document.querySelector(".text-gen-output");
|
| 21 |
+
textGenParagraph.textContent = await translateText(textGenInput.value);
|
| 22 |
+
});
|
| 23 |
});
|