-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
64 lines (54 loc) · 2.53 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
var input1 = document.querySelector('textarea#txt-area1');
var input2 = document.querySelector('textarea#txt-area2');
var message = document.getElementById("msg");
var button1 = document.querySelector('button.btn-1');
button1.onclick = criptografar;
var button2 = document.querySelector('button.btn-2');
button2.onclick = descriptografar;
document.getElementById('none').innerHTML = '';
input1.focus();
function criptografar() {
if (input1.value.length == 0) {
document.getElementById('none').innerHTML = '<h2 id="none">Nenhuma mensagem encontrada</h2>';
input1.focus();
} else {
document.getElementById('none').innerHTML = '';
document.querySelector('img.icone').style.display = 'none';
var text = input1.value;
var txt = text.replace(/e/igm, 'enter')
.replace(/i/igm, 'imes')
.replace(/a/igm, 'ai')
.replace(/o/igm, 'ober')
.replace(/u/igm, 'ufat');
document.getElementById('txt-area2').innerHTML = `${txt}`;
document.getElementById('copiar').innerHTML = '<button class="button btn-3" onclick="copiar()">Copiar</button>';
}
}
function descriptografar() {
if (input1.value.length == 0) {
document.getElementById('none').innerHTML = ' <h2 id="none">Nenhuma mensagem encontrada</h2>';
document.querySelector('img.icone').style.display;
input1.focus();
} else {
document.getElementById('none').innerHTML = '';
document.querySelector('img.icone').style.display = 'none';
document.getElementById('txt-area1').innerHTML = '';
var text = input1.value;
var txt = text.replace(/enter/igm, 'e')
.replace(/imes/igm, 'i')
.replace(/ai/igm, 'a')
.replace(/ober/igm, 'o')
.replace(/ufat/igm, 'u');
document.getElementById('txt-area2').innerHTML = `${txt}`;
document.getElementById('copiar').innerHTML = '<button class="button btn-3" onclick="copiar()">Copiar</button>';
}
}
function copiar() {
const text = document.querySelector('#txt-area2').value;
navigator.clipboard.writeText(text).then(function() {
message.innerHTML = "O texto copiado já está na área de transferência!";
document.querySelector("#txt-area1").value = "";
}, function() {
alert('Não foi possível copiar o texto para a área de transferência');
});
}