-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
134 lines (123 loc) · 4.97 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="./styles.css">
</head>
<body>
<header>
<img src="./assets/img/Logo.png" alt="logo Alura">
</header>
<div class="main-container">
<main>
<div class="main--input-container">
<input type="text" id= "inputText" placeholder="ingrese el texto aqui...">
<p><span></span>Solo letras minúsculas y sin acentos</p>
</div>
<div class="main--button-container">
<button class="main--button encriptar" id="encriptar">Encriptar</button>
<button class="main--button desencriptar" id="desencriptar">Desencriptar</button>
</div>
</main>
<footer>
<div class="footer--container">
<h2 class="footer--title" id="titleTexto">Ningún mensaje fue encontrado</h2>
<p class="footer--text" id="texto">Ingresa el texto que desees encriptar o desencriptar.</p>
<!-- <button class="copy--button">Copiar</button> -->
</div>
</footer>
</div>
<script>
let input;
let message;
const encripta = (letra)=>{
switch(letra){
case 'a':
letra='ai';
break;
case 'e':
letra='enter';
break;
case 'i':
letra='imes';
break;
case 'o':
letra='ober';
break;
case 'u':
letra='ufat';
break;
default:
letra;
break;
}
return letra;
}
const printCoder = (m)=>{
// crear boton
const boton = document.createElement('button');
boton.setAttribute('class','copy--button');
boton.innerText='Copiar';
document.querySelector('.footer--container').remove();
const container = document.createElement('div');
container.setAttribute('class','footer--container footer--title');
document.querySelector('footer').append(container)
container.append(m,boton)
}
const copyText = ()=> {
// let texto = document.querySelector('div.footer--container.footer--title').firstChild.textContent;
// navigator.clipboard.writeText(texto)
// .then(() => {
// console.log('texto copiado'+': '+ texto)
// })
// .catch(err => {
// console.error('Error in copying text: ', err);
// });
var codigoACopiar = document.querySelector('div.footer--container.footer--title').firstChild;
var seleccion = document.createRange();
seleccion.selectNodeContents(codigoACopiar);
window.getSelection().removeAllRanges();
window.getSelection().addRange(seleccion);
var res = document.execCommand('copy');
window.getSelection().removeRange(seleccion);
}
const clickHandler = (e)=>{
input = document.querySelector('#inputText');
let message = input.value;
input.value = '';
let secret = "";
if(e.target.className === 'main--button encriptar'){
let arr = message.split('');
secret = arr.map(item=>encripta(item)).join('');
}
if(e.target.className === 'main--button desencriptar') {
String.prototype.allReplace = function(obj) {
var retStr = this;
for (var x in obj) {
retStr = retStr.replace(new RegExp(x, 'g'), obj[x]);
}
return retStr;
};
secret = message.allReplace({'ai': 'a', 'enter': 'e', 'imes':'i', 'ober':'o', 'ufat':'u'});
}
printCoder(secret);
}
let encriptar = document.querySelector('#encriptar');
let res = encriptar.addEventListener('click',clickHandler);
let btndec = document.querySelector('#desencriptar');
btndec.addEventListener('click',clickHandler)
// let btnDec = document.querySelector('#desencriptar');
// btnDec.addEventListener('click',clickHandler)
let btnCopy = document.querySelector('footer');
btnCopy.addEventListener('click',copyText);
// document.getElementById('inputText').addEventListener('paste', interceptarPegado);
// function interceptarPegado(ev) {
// alert('Has pegado el texto:' + ev.clipboardData.getData('text/plain'));
// }
</script>
</body>
</html>