Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
121 lines (104 loc) · 2.76 KB
/
Copy pathscript.js
File metadata and controls
121 lines (104 loc) · 2.76 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
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
var input = document.querySelector('#text-input');
var encrypterButton = document.querySelector('#encrypt');
var unencrypterButton = document.querySelector('#unencrypt');
var barra = document.querySelector('.barra');
var clipboard = document.querySelector('.copy');
var copyText = document.querySelector('.copy-text');
var output
var band = 0;
input.focus();
function displayDark() {
var itement = document.body;
itement.classList.toggle("dark");
band++;
if(band === 2){
band = 0;
} else{
band = 1;
}
band === 1 ? itement1.classList.add("dark") : itement1.classList.remove("dark");
}
function showOutput() {
const item = document.querySelector('#output');
const herit = document.createTextNode('');
item.innerHTML = ''
item.appendChild(herit);
output = herit;
}
showOutput();
function encrypter(item){
switch(item) {
case 'a': return 'ai'
case 'e': return 'enter'
case 'i': return 'imes'
case 'o': return 'ober'
case 'u': return 'ufat'
default: return item
}
}
function iteraCode(txt){
txt = input.value.toLowerCase();
var t = '';
for(var i = 0; i < txt.length; i++) {
t += encrypter(txt[i]);
}
return t;
}
function unencrypter(txt){
txt = input.value.toLowerCase();
return txt.replace(/ai|enter|imes|ober|ufat/gi, function(matched){
switch(matched) {
case 'ai': return 'a'
case 'enter': return 'e'
case 'imes': return 'i'
case 'ober': return 'o'
case 'ufat': return 'u'
case ' ': return ''
default: return matched
}
});
}
encrypterButton.addEventListener('click', function() {
var txt = input.value;
if(txt.length === 0) {
output.nodeValue = ''
hideResult();
} else {
output.nodeValue = iteraCode(txt).toLowerCase();
showResult();
}
});
function showResult(){
barra.classList.add('con-output');
}
function hideResult(){
barra.classList.remove('con-output');
}
unencrypterButton.addEventListener('click', function() {
var valor = input.value;
if(valor.length === 0) {
output.nodeValue= ''
hideResult();
} else {
output.nodeValue = unencrypter(valor);
showResult();
}
});
input.addEventListener('input', function() {
var valor = input.value;
if(valor.length === 0) {
output.nodeValue= ''
hideResult();
}
});
var clip = navigator.clipboard;
clipboard.addEventListener('click', function(){
var input = output.nodeValue;
if(clip){
clip.writeText(input);
copyText.classList.add('active');
setTimeout(function(){
copyText.classList.remove('active');
}, 2000);
}
})