-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
83 lines (65 loc) · 2.6 KB
/
app.js
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
// app.js
function convertToLowercase(text) {
return text.toLowerCase();
}
function validateInput(text) {
const pattern = /^[a-z ]+$/;
return pattern.test(text);
}
function encrypt(text) {
text = convertToLowercase(text);
if (!validateInput(text)) {
return "Error: El texto contiene caracteres no permitidos. Solo letras minúsculas y espacios son válidos.";
}
const vocales = { "a": "ai", "e": "enter", "i": "imes", "o": "ober", "u": "ufat" };
return text.replace(/[aeiou]/g, match => vocales[match]);
}
function decrypt(text) {
text = convertToLowercase(text);
if (!validateInput(text)) {
return "Error: El texto contiene caracteres no permitidos. Solo letras minúsculas y espacios son válidos.";
}
const vocalesInvertidas = { "ai": "a", "enter": "e", "imes": "i", "ober": "o", "ufat": "u" };
return text.replace(/ai|enter|imes|ober|ufat/g, match => vocalesInvertidas[match]);
}
function showCopyMessage() {
const copyMessage = document.createElement("div");
copyMessage.textContent = "Texto copiado al portapapeles";
copyMessage.style.position = "fixed";
copyMessage.style.bottom = "20px";
copyMessage.style.right = "20px";
copyMessage.style.padding = "10px";
copyMessage.style.backgroundColor = "#4CAF50";
copyMessage.style.color = "white";
copyMessage.style.borderRadius = "5px";
copyMessage.style.zIndex = "1000";
document.body.appendChild(copyMessage);
setTimeout(() => {
document.body.removeChild(copyMessage);
}, 3000);
}
document.getElementById("copyBtn").addEventListener("click", function() {
const outputText = document.getElementById("txtInfo").value;
navigator.clipboard.writeText(outputText).then(() => {
showCopyMessage();
}).catch(err => {
console.error("Error al copiar el texto", err);
});
});
function handleTextConversion(conversionFunction) {
const inputText = document.getElementById("inputText").value;
const outputText = conversionFunction(inputText);
document.getElementById("txtInfo").value = outputText;
if (outputText) {
document.getElementById("mensajeAdv").classList.add("hide");
document.getElementById("imgDer").classList.add("hide");
document.getElementById("txtInfo").classList.add("ajustar");
document.getElementById("copyBtn").classList.remove("hide");
}
}
document.getElementById("encryptBtn").addEventListener("click", function() {
handleTextConversion(encrypt);
});
document.getElementById("decryptBtn").addEventListener("click", function() {
handleTextConversion(decrypt);
});