dioarafii commited on
Commit
e73c1d7
1 Parent(s): d001f99

Delete script.js

Browse files
Files changed (1) hide show
  1. script.js +0 -495
script.js DELETED
@@ -1,495 +0,0 @@
1
- var sourceLangModal = document.getElementById('sourceLangModal');
2
- var targetLangModal = document.getElementById('targetLangModal');
3
- var selectedSourceLangSpan = document.getElementById('selected_source_language');
4
- var selectedTargetLangSpan = document.getElementById('selected_target_language');
5
- var sourceLangInput = document.getElementById('source_lang');
6
- var targetLangInput = document.getElementById('target_lang');
7
- var textInput = document.getElementById('text');
8
- var translatedText = document.getElementById('translated_text');
9
- var speakButton = document.getElementById('speak_button');
10
- var copyElements = document.querySelectorAll('.copy');
11
- var copyButton = document.getElementById('copyButton');
12
- var successButton = document.getElementById('successButton');
13
-
14
-
15
-
16
-
17
-
18
- function searchLanguages(inputId, modalId) {
19
- var searchInput = document.getElementById(inputId);
20
- var searchKeyword = searchInput.value.toLowerCase();
21
-
22
- var languageList = document.getElementById(modalId).getElementsByTagName('li');
23
-
24
- for (var i = 0; i < languageList.length; i++) {
25
- var language = languageList[i].textContent.toLowerCase();
26
- if (language.includes(searchKeyword)) {
27
- languageList[i].style.display = 'block';
28
- } else {
29
- languageList[i].style.display = 'none';
30
- }
31
- }
32
- }
33
-
34
-
35
-
36
- function copy() {
37
- var copiedValues = [];
38
-
39
- for (var i = 0; i < copyElements.length; i++) {
40
- var value = copyElements[i].value;
41
- copiedValues.push(value);
42
- }
43
-
44
- var copiedString = copiedValues.join('\n');
45
-
46
- // Salin nilai yang disalin ke clipboard hanya jika tersedia izin
47
- if (navigator.clipboard && navigator.clipboard.writeText) {
48
- navigator.clipboard.writeText(copiedString)
49
- .then(function() {
50
- console.log('Nilai input telah disalin ke clipboard.');
51
- // Sembunyikan tombol "Copy" dan tampilkan tombol "Success"
52
- copyButton.style.display = 'none';
53
- successButton.style.display = 'block';
54
- // Kembalikan tampilan tombol seperti semula setelah beberapa waktu (misalnya 2 detik)
55
- setTimeout(function() {
56
- copyButton.style.display = 'block';
57
- successButton.style.display = 'none';
58
- }, 2000);
59
- })
60
- .catch(function(error) {
61
- console.error('Gagal menyalin nilai input:', error);
62
- });
63
- } else {
64
- console.error('Penyalinan ke clipboard tidak didukung pada browser ini.');
65
- }
66
- }
67
-
68
- copyButton.addEventListener('click', copy);
69
-
70
-
71
- function swapLanguages() {
72
- var sourceLang = sourceLangInput.value;
73
- var targetLang = targetLangInput.value;
74
-
75
- // Menukar nilai bahasa sumber dan bahasa target
76
- sourceLangInput.value = targetLang;
77
- targetLangInput.value = sourceLang;
78
-
79
- // Menukar teks di dalam textarea
80
- var sourceText = document.getElementById('text').value;
81
- var targetText = document.getElementById('translated_text').value;
82
- document.getElementById('text').value = targetText;
83
- document.getElementById('translated_text').value = sourceText;
84
-
85
- // Menampilkan nama bahasa di dalam elemen span
86
- selectedSourceLangSpan.textContent = getLanguageName(targetLang);
87
- selectedTargetLangSpan.textContent = getLanguageName(sourceLang);
88
- }
89
-
90
-
91
- function openLanguageModal(type) {
92
- if (type === 'source') {
93
- targetLangModal.style.display = 'none';
94
- sourceLangModal.style.display = 'block';
95
- } else if (type === 'target') {
96
- sourceLangModal.style.display = 'none';
97
- targetLangModal.style.display = 'block';
98
- }
99
- }
100
-
101
- function selectLanguage(language, type) {
102
- if (type === 'source') {
103
- sourceLangInput.value = language;
104
- selectedSourceLangSpan.textContent = getLanguageName(language);
105
- sourceLangModal.style.display = 'none';
106
- } else if (type === 'target') {
107
- targetLangInput.value = language;
108
- selectedTargetLangSpan.textContent = getLanguageName(language) || 'English';
109
- targetLangModal.style.display = 'none';
110
- }
111
- }
112
-
113
- function getLanguageName(language) {
114
-
115
- switch (language) {
116
- case 'en':
117
- return 'English';
118
- case 'id':
119
- return 'Indonesia';
120
- case 'jv':
121
- return 'Jawa';
122
- case 'su':
123
- return 'Sunda';
124
- case 'ja':
125
- return 'Jepang';
126
- case 'is':
127
- return 'Islan';
128
- case 'it':
129
- return 'Italia';
130
- case 'de':
131
- return 'Jerman';
132
- case 'kn':
133
- return 'Kannada';
134
- case 'ko':
135
- return 'Korea';
136
- case 'co':
137
- return 'Korsika';
138
- case 'ht':
139
- return 'Kreol Haiti';
140
- case 'kri':
141
- return 'Krio';
142
- case 'hr':
143
- return 'Kroat';
144
- case 'ku':
145
- return 'Kurdi (Kurmanji)';
146
- case 'ckb':
147
- return 'Kurdi (Sorani)';
148
- case 'lo':
149
- return 'Laos';
150
- case 'la':
151
- return 'Latin';
152
- case 'lv':
153
- return 'Latvia';
154
- case 'ln':
155
- return 'Lingala';
156
- case 'lt':
157
- return 'Lituania';
158
- case 'lg':
159
- return 'Luganda';
160
- case 'lb':
161
- return 'Luksemburg';
162
- case 'hu':
163
- return 'Magyar';
164
- case 'mai':
165
- return 'Maithili';
166
- case 'mk':
167
- return 'Makedonia';
168
- case 'mg':
169
- return 'Malagasi';
170
- case 'ml':
171
- return 'Malayalam';
172
- case 'mt':
173
- return 'Malta';
174
- case 'mi':
175
- return 'Maori';
176
- case 'mr':
177
- return 'Marathi';
178
- case 'mni':
179
- return 'Meiteilon (Manipuri)';
180
- case 'ms':
181
- return 'Melayu';
182
- case 'lus':
183
- return 'Mizo';
184
- case 'mn':
185
- return 'Mongol';
186
- case 'ne':
187
- return 'Nepal';
188
- case 'no':
189
- return 'Norsk';
190
- case 'or':
191
- return 'Odia (Oriya)';
192
- case 'om':
193
- return 'Oromo';
194
- case 'ps':
195
- return 'Pashto';
196
- case 'pl':
197
- return 'Polandia';
198
- case 'pt':
199
- return 'Portugis';
200
- case 'fr':
201
- return 'Prancis';
202
- case 'pa':
203
- return 'Punjabi';
204
- case 'qu':
205
- return 'Quechua';
206
- case 'ro':
207
- return 'Rumania';
208
- case 'ru':
209
- return 'Rusia';
210
- case 'sm':
211
- return 'Samoa';
212
- case 'sa':
213
- return 'Sanskerta';
214
- case 'nso':
215
- return 'Sepedi';
216
- case 'sr':
217
- return 'Serb';
218
- case 'st':
219
- return 'Sesotho';
220
- case 'sn':
221
- return 'Shona';
222
- case 'sd':
223
- return 'Sindhi';
224
- case 'si':
225
- return 'Sinhala';
226
- case 'sk':
227
- return 'Slovakia';
228
- case 'sl':
229
- return 'Slovenia';
230
- case 'so':
231
- return 'Somali';
232
- case 'es':
233
- return 'Spanyol';
234
- case 'sw':
235
- return 'Swahili';
236
- case 'sv':
237
- return 'Swensk';
238
- case 'tl':
239
- return 'Tagalog';
240
- case 'tg':
241
- return 'Tajik';
242
- case 'ta':
243
- return 'Tamil';
244
- case 'tt':
245
- return 'Tatar';
246
- case 'te':
247
- return 'Telugu';
248
- case 'th':
249
- return 'Thai';
250
- case 'ti':
251
- return 'Tigrinya';
252
- case 'ts':
253
- return 'Tsonga';
254
- case 'tr':
255
- return 'Turki';
256
- case 'tk':
257
- return 'Turkmen';
258
- case 'tw':
259
- return 'Twi';
260
- case 'uk':
261
- return 'Ukraina';
262
- case 'ur':
263
- return 'Urdu';
264
- case 'ug':
265
- return 'Uyghur';
266
- case 'uz':
267
- return 'Uzbek';
268
- case 'vi':
269
- return 'Vietnam';
270
- case 'cy':
271
- return 'Wales';
272
- case 'xh':
273
- return 'Xhosa';
274
- case 'yi':
275
- return 'Yiddi';
276
- case 'yo':
277
- return 'Yoruba';
278
- case 'el':
279
- return 'Yunani';
280
- case 'zu':
281
- return 'Zulu';
282
- case 'af':
283
- return 'Afrikans';
284
- case 'sq':
285
- return 'Albania';
286
- case 'am':
287
- return 'Amhara';
288
- case 'ar':
289
- return 'Arab';
290
- case 'hy':
291
- return 'Armenia';
292
- case 'as':
293
- return 'Assam';
294
- case 'ay':
295
- return 'Aymara';
296
- case 'az':
297
- return 'Azerbaijan';
298
- case 'bm':
299
- return 'Bambara';
300
- case 'eu':
301
- return 'Basque';
302
- case 'nl':
303
- return 'Belanda';
304
- case 'be':
305
- return 'Belarussia';
306
- case 'bn':
307
- return 'Bengali';
308
- case 'bho':
309
- return 'Bhojpuri';
310
- case 'bs':
311
- return 'Bosnia';
312
- case 'bg':
313
- return 'Bulgaria';
314
- case 'my':
315
- return 'Burma';
316
- case 'ceb':
317
- return 'Cebuano';
318
- case 'cs':
319
- return 'Ceko';
320
- case 'ny':
321
- return 'Chichewa';
322
- case 'zh-CN':
323
- return 'China (Aks. Sederhana)';
324
- case 'zh-TW':
325
- return 'China (Aks. Tradisional)';
326
- case 'da':
327
- return 'Denmark';
328
- case 'dv':
329
- return 'Divehi';
330
- case 'doi':
331
- return 'Dogri';
332
- case 'eo':
333
- return 'Esperanto';
334
- case 'et':
335
- return 'Estonia';
336
- case 'ee':
337
- return 'Ewe';
338
- case 'fa':
339
- return 'Farsi';
340
- case 'fi':
341
- return 'Finlandia';
342
- case 'fy':
343
- return 'Frisia';
344
- case 'gd':
345
- return 'Gaelig';
346
- case 'gd':
347
- return 'Gaelik Skotlandia';
348
- case 'gl':
349
- return 'Galisia';
350
- case 'ka':
351
- return 'Georgia';
352
- case 'gn':
353
- return 'Guarani';
354
- case 'gu':
355
- return 'Gujarati';
356
- case 'ha':
357
- return 'Hausa';
358
- case 'haw':
359
- return 'Hawaii';
360
- case 'hi':
361
- return 'Hindi';
362
- case 'hmn':
363
- return 'Hmong';
364
- case 'he':
365
- return 'Ibrani';
366
- case 'ig':
367
- return 'Igbo';
368
- case 'ilo':
369
- return 'Ilocano';
370
- case 'ca':
371
- return 'Katala';
372
- case 'kk':
373
- return 'Kazak';
374
- case 'km':
375
- return 'Khmer';
376
- case 'rw':
377
- return 'Kinyarwanda';
378
- case 'ky':
379
- return 'Kirghiz';
380
- case 'kok':
381
- return 'Konkani';
382
-
383
-
384
- default:
385
- return language;
386
- }
387
- }
388
-
389
-
390
- function translateText() {
391
- var text = textInput.value;
392
- var targetLang = targetLangInput.value;
393
-
394
- var data = {
395
- text: text,
396
- target_lang: targetLang
397
- };
398
-
399
-
400
- var xhr = new XMLHttpRequest();
401
- xhr.open('POST', '/translate', true);
402
- xhr.setRequestHeader('Content-Type', 'application/json');
403
-
404
- xhr.onload = function () {
405
- if (xhr.status === 200) {
406
- var response = JSON.parse(xhr.responseText);
407
- document.getElementById('translated_text').textContent = response.translated_text;
408
- } else {
409
- console.log('Error:', xhr.status);
410
- }
411
- };
412
-
413
- xhr.onerror = function () {
414
- console.log('Request error');
415
- };
416
-
417
- xhr.send(JSON.stringify(data));
418
- }
419
-
420
-
421
- // Add event listener to the text input
422
- textInput.addEventListener('textarea', translateText);
423
-
424
-
425
- var recognition; // Variable to hold the recognition object
426
-
427
- function toggleRecognition() {
428
- if (!recognition) {
429
- startRecognition();
430
- } else {
431
- stopRecognition();
432
- }
433
- }
434
-
435
- function startRecognition() {
436
- recognition = new webkitSpeechRecognition();
437
- recognition.continuous = false;
438
- recognition.interimResults = false;
439
- recognition.lang = "id-ID";
440
- recognition.start();
441
-
442
- recognition.onresult = function (event) {
443
- var speechResult = event.results[0][0].transcript;
444
- const chatboxInput = document.querySelector('textarea');
445
- chatboxInput.value = speechResult;
446
- translateText();
447
- };
448
-
449
- recognition.onend = function () {
450
- // Reset the recognition variable and button display
451
- recognition = null;
452
- var startRecognitionButton = document.getElementById('startRecognitionButton');
453
- var stopRecognitionButton = document.getElementById('stopRecognitionButton');
454
- startRecognitionButton.style.display = "inline-block";
455
- stopRecognitionButton.style.display = "none";
456
- };
457
-
458
- // Set button display
459
- var startRecognitionButton = document.getElementById('startRecognitionButton');
460
- var stopRecognitionButton = document.getElementById('stopRecognitionButton');
461
- startRecognitionButton.style.display = "none";
462
- stopRecognitionButton.style.display = "inline-block";
463
- }
464
-
465
- function stopRecognition() {
466
- recognition.stop();
467
- }
468
-
469
-
470
- var isSpeaking = false;
471
-
472
- function speakText(text) {
473
- if (!isSpeaking) {
474
- isSpeaking = true;
475
-
476
- const speechSynthesis = window.speechSynthesis;
477
- const utterance = new SpeechSynthesisUtterance(text);
478
-
479
- utterance.lang = 'id-ID';
480
- utterance.volume = 1;
481
- utterance.rate = 1;
482
- utterance.pitch = 1;
483
-
484
- utterance.onend = function (event) {
485
- isSpeaking = false;
486
- };
487
-
488
- speechSynthesis.speak(utterance);
489
- }
490
- }
491
-
492
- speakButton.addEventListener('click', function () {
493
- var translatedText = document.getElementById('translated_text').textContent;
494
- speakText(translatedText);
495
- });