-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
69 lines (60 loc) · 2.09 KB
/
script.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
document.addEventListener("DOMContentLoaded", function () {
const textInput = document.getElementById("text-input");
const encryptButton = document.querySelector("form button:first-of-type");
const decryptButton = document.querySelector("form button:last-of-type");
const resultHeading = document.querySelector("section:last-of-type h2");
const resultParagraph = document.querySelector("section:last-of-type p");
const resultImage = document.querySelector("section:last-of-type img");
function encrypt(text) {
const encryptedText = text
.replace(/e/g, "enter")
.replace(/i/g, "imes")
.replace(/a/g, "ai")
.replace(/o/g, "ober")
.replace(/u/g, "ufat");
return encryptedText;
}
function decrypt(text) {
const decryptedText = text
.replace(/enter/g, "e")
.replace(/imes/g, "i")
.replace(/ai/g, "a")
.replace(/ober/g, "o")
.replace(/ufat/g, "u");
return decryptedText;
}
function updateResult(text) {
if (text) {
resultHeading.textContent = "Resultado:";
resultParagraph.textContent = text;
resultImage.style.display = "none";
} else {
resultHeading.textContent = "No se encontró ningún texto";
resultParagraph.textContent =
"Ingresá el texto que quieras encriptar o desencriptar";
resultImage.style.display = "block";
}
}
encryptButton.addEventListener("click", function (event) {
event.preventDefault();
const encryptedText = encrypt(textInput.value);
updateResult(encryptedText);
});
decryptButton.addEventListener("click", function (event) {
event.preventDefault();
const decryptedText = decrypt(textInput.value);
updateResult(decryptedText);
});
updateResult("");
});
function toggleDarkMode() {
document.body.classList.toggle("dark-mode");
const isDarkMode = document.body.classList.contains("dark-mode");
localStorage.setItem("dark-mode", isDarkMode);
}
window.onload = function () {
const savedDarkMode = localStorage.getItem("dark-mode") === "true";
if (savedDarkMode) {
document.body.classList.add("dark-mode");
}
};