-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
84 lines (80 loc) · 2.55 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<!DOCTYPE html>
<html>
<head>
<title>Pali Transliteration</title>
<style>
* { font-size: 115%; }
.container { display: flex; }
.input-group, .output-group {
display: flex;
flex-direction: column;
width: 50%;
}
select, textarea {
width: 100%;
padding: 15px;
box-sizing: border-box;
}
textarea { height: 100vh; resize: none; }
select {
text-align: center;
font-weight: bold;
height: auto;
min-height: 2.5em;
align-self: stretch;
}
</style>
</head>
<body>
<div class="container">
<div class="input-group">
<select id="inputSelect">
<option value="latin">Latin/Roman</option>
<option value="thai1">Thai (Colloquial) // อักษรไทย</option>
<option value="thai2">Thai (Pintu) // แบบพินทุ</option>
</select>
<textarea spellcheck="false" id="inputTextArea"></textarea>
</div>
<div class="output-group">
<select id="outputSelect">
<option value="latin">Latin/Roman</option>
<option value="thai2">Thai (Pintu) // แบบพินทุ</option>
</select>
<textarea spellcheck="false" id="outputTextArea" readonly></textarea>
</div>
</div>
<script>
const inputSelect = document.getElementById("inputSelect");
const outputSelect = document.getElementById("outputSelect");
const inputTextArea = document.getElementById("inputTextArea");
const outputTextArea = document.getElementById("outputTextArea");
const apiEndpoint = "http://localhost:8080/process";
async function callAPI() {
const inputValue = inputTextArea.value;
const inputSelection = inputSelect.value;
const outputSelection = outputSelect.value;
console.log(inputSelection+"🠮"+outputSelection);
try {
const response = await fetch(apiEndpoint, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
text: inputValue,
inputSelection: inputSelection,
outputSelection: outputSelection
})
});
if (!response.ok) throw new Error("API request failed 🤖");
const processedText = await response.text();
outputTextArea.value = processedText;
} catch (error) {
console.error(error);
outputTextArea.value = "Couldn't reach server";
}
}
inputTextArea.addEventListener("input", callAPI);
inputSelect.addEventListener("change", callAPI);
outputSelect.addEventListener("change", callAPI);
</script>
</body>
</html>