-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.html
67 lines (55 loc) · 2.07 KB
/
test.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
<!DOCTYPE html>
<html>
<head>
<title>test translation</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
</head>
<body>
<script>
var server = "127.0.0.1:3000"
async function checkServer(fqdn, imagepath="/favicon.ico") {
let img = new Image();
img.onload = function() { //console.log("online");
return true;
};
img.onerror = function() { //console.log("offline");
return false;
};
img.src = "http://" + fqdn + imagepath + '?r=' + Math.random(); /* avoids caching */
}
async function translate(input) {
console.log("translating ...");
var original = input;
$.ajax({
url: "http://" + server + "/api/translate",
type: 'GET',
data: {
original: original
},
success: function () {
console.log('Successfully connected to the server');
},
error: function () {
console.log('Something went wrong');
}
})
.done(function (data) {
console.log("returned data:", data);
return data;
});
}
function translateText() {
if (checkServer(server)) {
var textbox = document.getElementById("textbox");
var input = textbox.value;
translate(input);
} else { console.log("unavailable")}
}
</script>
<input type="text" id="textbox" placeholder="Enter text here">
<button onclick="translateText()">tranlate</button>
<p>example: age: vintage</p>
<p>mitake: 120 cm (center back)</p>
<p>color: green, red (hakkake)</p>
</body>
</html>