-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
131 lines (115 loc) · 5.73 KB
/
app.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
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
import { generateAleatoryEmails, generateCustomEmails, generateHumanEmails } from "./modules/generateEmail.js";
const d = document;
const $ = (e) => d.querySelector(e);
const $a = (e) => d.querySelectorAll(e);
export const app = (e) => {
let path = window.location.pathname.split(".")[0];
if (path === "/email-generator/index" || path === "/email-generator/") {
document.title = "Generador Correos";
if ($("#aleatory_email").checked) {
$("#form-container").insertAdjacentHTML("beforeend", "<aleatory-email-component></aleatory-email-component>");
}
d.addEventListener("submit", async (e) => {
// ALEATORY EMAILS
if (e.target.matches("#generate-aleatory-emails")) {
e.preventDefault();
$("#email-response").innerHTML = "";
let data = Object.fromEntries(new FormData(e.target));
if (!data.length_email && !isNaN(data.length_email)) {
alert("Longitud del email es requerido");
} else if (!data.quantity_email && !isNaN(data.length_email)) {
alert("Cantidad es requerida");
} else {
if (!(Number(data.length_email) > 3 && Number(data.length_email) <= 40)) {
alert("Longitud no valida");
} else if (!(Number(data.quantity_email) <= 100)) {
alert("Cantidad no valida");
} else if (!(/^[a-z0-9.-]+\.[a-z]{2,6}$/.test(data.domain_email))) {
alert("Dominio invalido, no agregues @");
} else {
let correos = generateAleatoryEmails(data);
correos.forEach((e) => {
$("#email-response").insertAdjacentHTML("beforeend", `<li class="list-group-item">${e}</li>`);
})
}
}
}
// HUMAN EMAILS
if (e.target.matches("#generate-human-emails")) {
e.preventDefault();
$("#email-response").innerHTML = "";
let data = Object.fromEntries(new FormData(e.target));
if (!data.quantity_email && !isNaN(data.length_email)) {
alert("Cantidad es requerida");
} else {
if (!(Number(data.quantity_email) <= 100)) {
alert("Cantidad no valida");
} else {
let correos = await generateHumanEmails(data);
correos.forEach((e) => {
$("#email-response").insertAdjacentHTML("beforeend", `<li class="list-group-item">${e}</li>`);
})
}
}
}
// CUSTOM EMAILS
if (e.target.matches("#generate-custom-emails")) {
e.preventDefault();
$("#email-response").innerHTML = "";
let data = Object.fromEntries(new FormData(e.target));
if (!data.quantity_email && !isNaN(data.length_email)) {
alert("Cantidad es requerida");
} else {
if (!(/^[a-zA-Z0-9.]+$/.test(data.user_email))) {
alert("Usuario email no es valido");
} else if (!(/^[a-z0-9.-]+\.[a-z]{2,6}$/.test(data.domain_email))) {
alert("Dominio invalido, no agregues @");
} else if (!(Number(data.quantity_email) <= 100)) {
alert("Cantidad no valida");
} else {
let correos = generateCustomEmails(data);
correos.forEach((e) => {
$("#email-response").insertAdjacentHTML("beforeend", `<li class="list-group-item">${e}</li>`);
})
}
}
}
})
d.addEventListener("input", (e) => {
if (e.target.matches("[name='type_email']")) {
$("#form-container").innerHTML = "";
$("#email-response").innerHTML = "";
if (e.target.matches("#aleatory_email")) {
$("#form-container").insertAdjacentHTML("beforeend", "<aleatory-email-component></aleatory-email-component>")
}
if (e.target.matches("#human_email")) {
$("#form-container").insertAdjacentHTML("beforeend", "<human-email-component></human-email-component>")
}
if (e.target.matches("#custom_email")) {
$("#form-container").insertAdjacentHTML("beforeend", "<custom-email-component></custom-email-component>")
}
}
})
d.addEventListener("click", (e) => {
if (e.target.matches("#settings input[type='checkbox']")) {
let checkSelected = [...$a("#settings input[type='checkbox']")].filter((checkbox) => checkbox.checked);
if (checkSelected.length === 0) {
e.target.checked = true;
}
}
if (e.target.matches("#copy-emails, #copy-emails *")) {
const elementosLi = $a('li');
let contenidoCopiado = '';
for (let i = 0; i < elementosLi.length; i++) {
contenidoCopiado += elementosLi[i].textContent + '\n';
}
const temp = document.createElement('textarea');
temp.value = contenidoCopiado;
document.body.appendChild(temp);
temp.select();
document.execCommand('copy');
document.body.removeChild(temp);
}
})
}
}