Skip to content

Commit f19ee3e

Browse files
committed
restored button
1 parent 50e4976 commit f19ee3e

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

code/functions.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ const isLower = /^[a-z\s]+$/g
22
const regSign = /^[a-z\s¡!,.;¿?]+$/g
33
const alertReg = /(animate__animated\sanimate__headShake)/g
44
const interReg = /(fa-solid)/g
5-
const regAlert = /(copiado|agregada|eliminada)/g
5+
const regAlert = /(copi|agre|elim|rest)/g
66
const regSpace = /[^\s]/g
7-
keys = [ 'ai', 'enter', 'imes', 'ober', 'ufat' ]
7+
8+
let keys = window.localStorage.getItem('keys').split(',')
9+
if (!window.localStorage.getItem('keys')) restaurar()
810

911
function encriptar(e) {
1012
let word = document.querySelector("#input").value;
@@ -90,6 +92,8 @@ function agregar(e) {
9092
if (!keys[keys.indexOf(valor)] && clave.match(isLower) && valor.match(isLower)
9193
&& clave.match(regSpace) && valor.match(regSpace) && valor.match(RegExp('^'+clave))) {
9294
keys.push(valor)
95+
window.localStorage.removeItem('keys')
96+
window.localStorage.setItem('keys', keys)
9397
alerta(e, 'Clave agregada!')
9498
} else if (!(clave.match(regSpace) && valor.match(regSpace))) alerta(e, 'Campo vacio!')
9599
else if (!(clave.match(regSpace) && valor.match(regSpace))) alerta(e, 'Solo usa minusculas!')
@@ -104,6 +108,8 @@ function eliminar(e) {
104108
let valor = document.getElementById('cvalor').value
105109
if (clave.match(regSpace) && clave.match(isLower) && keys[keys.indexOf(valor)] && valor.match(RegExp('^'+clave))) {
106110
keys.splice(keys[keys.indexOf(valor)], 1)
111+
window.localStorage.removeItem('keys')
112+
window.localStorage.setItem('keys', keys)
107113
alerta(e, 'Clave eliminada!')
108114
} else if (!clave.match(regSpace)) alerta(e, 'Campo vacio!')
109115
else if (!clave.match(isLower)) alerta(e, 'Solo usa minusculas!')
@@ -113,6 +119,14 @@ function eliminar(e) {
113119
document.getElementById('cvalor').value = ''
114120
}
115121

122+
function restaurar(e) {
123+
let key = [ 'ai', 'enter', 'imes', 'ober', 'ufat' ]
124+
window.localStorage.clear()
125+
window.localStorage.setItem('keys', key)
126+
keys = key
127+
if (e) alerta(e, 'Claves restauradas!')
128+
}
129+
116130
document.querySelector('#limpiarb').addEventListener('click', e => limpiar())
117131
document.querySelector('#encripb').addEventListener('click',e => encriptar(e))
118132
document.querySelector('#desencripb').addEventListener('click',e => desencriptar(e))
@@ -122,4 +136,5 @@ document.querySelector('#modob').addEventListener('click', e => modo())
122136
document.querySelector('#configb').addEventListener('click', e => configp())
123137
document.querySelector('#salirb').addEventListener('click', e => configp())
124138
document.querySelector('#agb').addEventListener('click', e => agregar(e))
125-
document.querySelector('#elimb').addEventListener('click', e => eliminar(e))
139+
document.querySelector('#elimb').addEventListener('click', e => eliminar(e))
140+
document.querySelector('#restb').addEventListener('click', e => restaurar(e))

index.html

+4-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@
8383
<input title="clave" id="cclave" class="cinput" type="text" maxlength="1">
8484
<input title="valor" id="cvalor" class="cinput" type="text" maxlength="6">
8585
</div>
86-
<div class="boton ccinput">
86+
<div class="boton cboton">
87+
<div id="restaurar">
88+
<button type="button" title="restaurar" id="restb" ><i class="fa-solid fa-repeat"></i></i></button>
89+
</div>
8790
<div id="agregar">
8891
<button type="button" title="agregar" id="agb" ><i class="fa-solid fa-plus"></i></button>
8992
</div>

0 commit comments

Comments
 (0)