-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
366 lines (330 loc) · 13.9 KB
/
index.php
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script
src="https://kit.fontawesome.com/64d58efce2.js"
crossorigin="anonymous"
></script>
<link rel="stylesheet" href="css/style.css" />
<link rel="stylesheet" href="css/modal.css" />
<link href="img/logo.ico" rel="icon">
<title>Beta Translate</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css"/>
<style type="text/css">
.autocomplete-suggestions { border: 1px solid #999; background: #FFF; overflow: auto; }
.autocomplete-suggestion { padding: 2px 5px; white-space: nowrap; overflow: hidden; }
.autocomplete-selected { background: #F0F0F0; }
.autocomplete-suggestions strong { font-weight: normal; color: #3399FF; }
.autocomplete-group { padding: 2px 5px; }
.autocomplete-group strong { display: block; border-bottom: 1px solid #000; }
input {
width: 100%;
padding: 1em !important;
margin: 0em !important;
}
.input-container {
padding-bottom: 10px;
}
.left-and-right-inner-addon {
position: relative;
max-width: 380px;
width: 100%;
}
.left-and-right-inner-addon input {
padding-right: 35px !important;
padding-left: 60px !important;
background-color: #f0f0f0;
border-radius: 55px;
border: none;
height: 55px;
outline: none;
border: none;
line-height: 1;
font-weight: 600;
font-size: 1.1rem;
color: #333;
}
.left-and-right-inner-addon i.left {
position: absolute;
color: #acacac;
padding: 15px 15px;
padding-left: 25px;
padding-top: 18px;
cursor: pointer;
font-size: 1.1rem;
}
.left-and-right-inner-addon i.right {
position: absolute;
right: 0px;
color: #acacac;
padding: 15px 15px;
padding-right: 25px;
padding-top: 19px;
cursor: pointer;
font-size: 1rem;
}
.button-feed {
display: inline-block;
border-radius: 30px;
background-color: #289cfc;
border: none;
color: #FFFFFF;
text-align: center;
font-size: 15px;
padding: 8px;
width: 140px;
transition: all 0.5s;
cursor: pointer;
margin: 5px;
}
</style>
<!-- Script Connection to translate.php -->
<script>
function getXMLHttpRequest() {
if (window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else alert("Status : Can not create XMLHttpRequest Object");
}
var xmlhttp = getXMLHttpRequest();
function sendRequest(pageURL, bahasa) {
if (xmlhttp.readyState == 4 || xmlhttp.readyState == 0) {
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
// console.log(xmlhttp);
resp = JSON.parse(xmlhttp.responseText);
console.log(resp);
if (bahasa == 'indonesia') {
document.getElementById('konversumbawa').value = resp.kata;
if(resp.status == true) {
document.getElementById('info-data1').innerHTML = resp.ket;
document.getElementById('id01-icon').style = '';
}
} else if (bahasa == 'sumbawa') {
document.getElementById('konverindonesia').value = resp.kata;
if(resp.status == true) {
document.getElementById('info-data2').innerHTML = resp.ket;
document.getElementById('id02-icon').style = '';
}
}
}
}
xmlhttp.open('GET', pageURL, true);
xmlhttp.send(null);
}
}
function konversi(bahasa) {
if (bahasa == 'indonesia') {
sendRequest('translate.php?kata=' + document.getElementById('bahasaindonesia').value + '&bahasa=indonesia', 'indonesia');
} else if (bahasa == 'sumbawa') {
sendRequest('translate.php?kata=' + document.getElementById('bahasasumbawa').value + '&bahasa=sumbawa', 'sumbawa');
}
}
</script>
</head>
<body>
<div class="container">
<div class="forms-container">
<div class="signin-signup">
<form action="#" class="sign-in-form">
<h2 class="title">Terjemahin!</h2>
<div class="left-and-right-inner-addon input-container">
<i id="volSpeak" onclick="volSpeak(this)" class="fas fa-volume-up left"></i>
<input type="text" name="bahasaindonesia" id="bahasaindonesia" placeholder="Indonesia" />
</div>
<input type="button" name="Submit" value="Artinya" onclick="konversi('indonesia');" class="btn solid" />
<div class="left-and-right-inner-addon input-container" style="margin: 10px 0;">
<i id="volSpeak" onclick="volSpeak2(this)" class="fas fa-volume-up left"></i>
<i onclick="document.getElementById('id01').style.display='block'" id="id01-icon" style="display: none;" class="fa-solid fa-circle-info right"></i>
<input type="text" name="konversumbawa" id="konversumbawa" placeholder="Sumbawa" disabled/>
</div>
<p class="social-text">Creator</p>
<div class="social-media">
<a href="https://github.com/irfan7o" target="_blank" class="social-icon">
<i class="fab fa-github"></i>
</a>
<a href="https://www.instagram.com/irfan.0z" target="_blank" class="social-icon">
<i class="fab fa-instagram"></i>
</a>
<a href="https://www.linkedin.com/in/irfan0z" target="_blank" class="social-icon">
<i class="fab fa-linkedin-in"></i>
</a>
</div>
<br style="margin-top: 20px">
<a href="https://forms.office.com/r/Kxjq5HsnsS" class="button-feed" target="_blank" style="vertical-align:middle; text-decoration:none;">
feedback <i class="fas fa-comment-dots"></i>
</a>
</form>
<form action="#" class="sign-up-form">
<h2 class="title">Terjemahin!</h2>
<div class="left-and-right-inner-addon input-container">
<i id="volSpeak" onclick="volSpeak2(this)" class="fas fa-volume-up left"></i>
<input type="text" name="bahasasumbawa" id="bahasasumbawa" placeholder="Sumbawa" />
</div>
<input type="button" name="Submit" class="btn" value="Artinya" onclick="konversi('sumbawa');" />
<div class="left-and-right-inner-addon input-container" style="margin: 10px 0;">
<i id="volSpeak" onclick="volSpeak(this)" class="fas fa-volume-up left"></i>
<i onclick="document.getElementById('id02').style.display='block'" id="id02-icon" style="display: none;" class="fa-solid fa-circle-info right"></i>
<input type="text" name="konverindonesia" id="konverindonesia" placeholder="Indonesia" disabled/>
</div>
<p class="social-text">Creator</p>
<div class="social-media">
<a href="https://github.com/irfan7o" target="_blank" class="social-icon">
<i class="fab fa-github"></i>
</a>
<a href="https://www.instagram.com/irfan.0z" target="_blank" class="social-icon">
<i class="fab fa-instagram"></i>
</a>
<a href="https://www.linkedin.com/in/irfan0z" target="_blank" class="social-icon">
<i class="fab fa-linkedin-in"></i>
</a>
</div>
<br style="margin-top: 20px">
<a href="https://forms.office.com/r/Kxjq5HsnsS" class="button-feed" target="_blank" style="vertical-align:middle; text-decoration:none;">
feedback <i class="fas fa-comment-dots"></i>
</a>
</form>
</div>
</div>
<div class="panels-container">
<div class="panel left-panel">
<!-- Modal 1 -->
<div id="id01" class="modal-info">
<span onclick="document.getElementById('id01').style.display='none'" class="close" title="Close Modal">×</span>
<form class="modal-info-content" action="#">
<div class="container-info">
<i class="fa-solid fa-circle-info" style="font-size: 5em;"></i>
<h2 style="color: #444; padding-bottom: 5px;">Info</h2>
<p id="info-data1" class="modal-1">Muncul info disini! indo</p>
<button type="button" onclick="document.getElementById('id01').style.display='none'" class="cancelbtn" style="padding-top: 10px;">Oke, paham</button>
</div>
</form>
</div>
<!-- End of Modal 1 -->
<div class="content">
<h3>Beta Translate</h3>
<p>
Yuk! Coba terjamahin arti kata bahasa indonesia ke bahasa sumbawa. Pasti asik!
</p>
<button class="btn transparent" id="sign-up-btn">
Switch
</button>
</div>
<img src="img/gambar-indonesia.svg" class="image" alt="" />
</div>
<div class="panel right-panel">
<!-- Modal 2 -->
<div id="id02" class="modal-info">
<span onclick="document.getElementById('id02').style.display='none'" class="close" title="Close Modal">×</span>
<form class="modal-info-content" action="#">
<div class="container-info">
<i class="fa-solid fa-circle-info"></i>
<h2 style="color: #444; padding-bottom: 5px;">Info</h2>
<p id="info-data2">Muncul info disini! sumbaw</p>
<button type="button" onclick="document.getElementById('id02').style.display='none'" class="cancelbtn">Oke, paham</button>
</div>
</form>
</div>
<!-- End of Modal 2 -->
<div class="content">
<h3>Beta Translate</h3>
<p>
Tem tu coba terjamah arti kata bahasa semawa ko bahasa indonesia. Pasti maras!
</p>
<button class="btn transparent" id="sign-in-btn">
Switch
</button>
</div>
<img src="img/gambar-sumbawa.svg" class="image" alt="" />
</div>
</div>
</div>
<!-- Script for Autocomplete -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.devbridge-autocomplete/1.4.11/jquery.autocomplete.min.js"></script>
<!-- TTS Voice -->
<script type="text/javascript">
function volSpeak(e) {
let kata = document.getElementById('bahasaindonesia').value;
let fileName = (Math.random() + 1).toString(36).substring(7);
if(localStorage.getItem(kata)) {
console.log('local localStorage use');
new Audio(`audio/${localStorage.getItem(kata)}`).play();
} else {
fetch( `http://127.0.0.1:3000/generate?text=${kata}&lang=id&fileName=${fileName}`).then(data => data.json()).then((resp) => {
if(resp.success) {
console.log('api use');
new Audio(`audio/${resp.audioName}`).play();
localStorage.clear();
localStorage.setItem(kata, resp.audioName);
}
});
}
}
function volSpeak2(e) {
let kata = document.getElementById('konversumbawa').value;
let fileName = (Math.random() + 1).toString(36).substring(7);
if(localStorage.getItem(kata)) {
console.log('local localStorage use');
new Audio(`audio/${localStorage.getItem(kata)}`).play();
} else {
fetch( `http://127.0.0.1:3000/generate?text=${kata}&lang=id&fileName=${fileName}`).then(data => data.json()).then((resp) => {
if(resp.success) {
console.log('api use');
new Audio(`audio/${resp.audioName}`).play();
localStorage.clear();
localStorage.setItem(kata, resp.audioName);
}
});
}
}
</script>
<!-- Autocomplete Indonesia -->
<script type="text/javascript">
$(document).ready(function() {
$( "#bahasaindonesia" ).autocomplete({
serviceUrl: "data-indonesia.php",
dataType: "JSON",
onSelect: function (suggestion) {
$( "#bahasaindonesia" ).val(suggestion.indonesia);
}
});
})
</script>
<!-- Autocomplete Sumbawa -->
<script type="text/javascript">
$(document).ready(function() {
$( "#bahasasumbawa" ).autocomplete({
serviceUrl: "data-sumbawa.php",
dataType: "JSON",
onSelect: function (suggestion) {
$( "#bahasasumbawa" ).val(suggestion.sumbawa);
}
});
})
</script>
<!-- Get Modal 1 -->
<script>
var modal = document.getElementById('id01');
window.onclick = function(event) {
if (event.target == modal) {
modal.style.display = "none";
}
}
</script>
<!-- Get modal 2 -->
<script>
var modal2 = document.getElementById('id02');
window.onclick = function(event) {
if (event.target == modal2) {
modal.style.display = "none";
}
}
</script>
<!-- Switch -->
<script src="js/app.js"></script>
</body>
</html>