This repository was archived by the owner on Oct 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
64 lines (64 loc) 路 2.28 KB
/
Copy pathindex.js
File metadata and controls
64 lines (64 loc) 路 2.28 KB
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
"use strict";
const copy = document.querySelector('.copy');
copy.addEventListener('click', () => {
navigator.clipboard.writeText(result.innerText).then(() => {
copy.innerText = 'Copi茅 avec succ猫s !';
setTimeout(() => {
copy.innerText = 'Copier le r茅sultat';
}, 2000);
});
});
const translator = document.querySelector('#translator');
const result = document.querySelector('.result');
translator.addEventListener('keyup', () => {
result.textContent = '';
const words = translator.value.split(/[^A-z脌-煤]/g);
const nonWords = translator.value.replace(/[A-z脌-煤]/g, '').split('');
let resText = '';
words.forEach((word, i) => {
if (word !== '') {
if (nonWords[i] != "'") {
switch (word.charAt(word.length - 1)) {
case 'o':
break;
case 'e':
case '茅':
case '猫':
case '锚':
if (word.charAt(word.length - 2).match(/[^aeio]/g)) {
word = word.slice(0, -1) + 'o';
}
else {
word += 'o';
}
break;
case 'u':
if (word.charAt(word.length - 2) == 'q') {
break;
}
else {
word += 'o';
break;
}
case 's':
if (word.charAt(word.length - 2) == 'e' &&
word.charAt(word.length - 3).match(/[^aeiou]/g)) {
word = word.slice(0, -2) + 'os';
}
else {
word += 'o';
}
break;
default:
word += 'o';
break;
}
}
resText += word + (nonWords[i] !== undefined ? nonWords[i] : ' ');
}
else {
resText += nonWords[i] !== undefined ? nonWords[i] : ' ';
}
result.innerText = resText;
});
});