-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
280 lines (236 loc) · 8.46 KB
/
Copy pathindex.html
File metadata and controls
280 lines (236 loc) · 8.46 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<!DOCTYPE html>
<header>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"
integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<!-- Latest compiled JavaScript -->
<style>
html,
body {
height: 100%;
}
#page-content {
flex: 1 0 auto;
}
.form-box {
display: flex;
width: 100%;
}
.row-input {
display: inline-flex;
height: fit-content;
align-items: center;
width: 100%;
}
.search-input {
height: fit-content;
flex: 1;
display: block;
min-width: 0;
}
.wrong-url {
border-color: red;
}
.good-url {
border-color: green;
}
</style>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<script>
function sleep(ms = null) {
if (!ms) {
const waitTime = + $("#wait").val();
ms = waitTime * 1000;
}
return new Promise(resolve => setTimeout(resolve, ms));
}
async function test(url) {
if (window.fetch) {
// must be chrome or firefox which have native fetch
try {
await fetch(url, { 'mode': 'no-cors' })
return true;
} catch {
return false;
}
} else {
return false;
}
}
async function urlExist(url) {
try {
const res = await test(url);
return res;
}
catch (err) {
console.log("Not found", err);
}
return false;
}
async function isValidHttpUrl(string) {
let url;
try {
url = new URL("http://" + string);
} catch (_) {
return { valid: false, url: string };
}
const res = await urlExist(url);
if (!res) {
return { valid: true, url: string };
}
return { valid: url.protocol === "http:" || url.protocol === "https:", url: url };
}
async function makeSureValid(url) {
while (url) {
const res = await isValidHttpUrl(url);
if (res.valid)
return res;
url = url.substring(0, url.length - 1);
}
return { valid: false, url: url };
}
async function searchOne(busqueda, isDirect) {
if (busqueda instanceof (URL)) {
window.open(busqueda, '_blank');
return { success: true }
}
url = busqueda;
urlbk = url;
url = `https://www.google.com/search?q=${busqueda}`;
window.open(url, '_blank');
return { success: true }
}
async function searchCorreos() {
const isDirect = $("#openDomain").prop("checked");
let busquedas = (await Promise.all($("#text-area-search").val()
.split('\n')
.filter(x => x)
.map(x => x.split("@")[1])
.map(async x => {
if (!isDirect || !x)
return x;
const res = await makeSureValid(x);
if (res.valid) {
return res.url
}
return x;
})))
.filter(x => x);
const allowRepeat = $("#allowRepeat").prop("checked");
if (!allowRepeat) {
busquedas = new Set(busquedas);
}
let url;
const failed = [];
for (const busqueda of busquedas) {
const res = await searchOne(busqueda, isDirect);
if (!res.success && res.url)
failed.push(res.url);
await sleep();
}
}
function readTextBox(){
const allowRepeat = $("#allowRepeat").prop("checked");
let busquedas = $("#text-area-search").val()
.split('\n')
.map(x=>x.trim())
.filter(x => x);
if (!allowRepeat) {
busquedas = new Set(busquedas);
}
return busquedas;
}
async function searchFrases() {
let busquedas = readTextBox();
for (const busqueda of busquedas) {
window.open(`https://www.google.com/search?q=${busqueda}`, '_blank');
await sleep();
}
}
async function searchMaps() {
let busquedas = readTextBox();
for (const busqueda of busquedas) {
const url = `https://www.google.com.mx/maps/place/${busqueda}`;
window.open(url, '_blank');
await sleep();
}
}
$(document).ready(function () {
$("#search").click(async () => {
const isFrases = $("#frases").prop("checked")
const maps = $("#maps").prop("checked");
if (isFrases) {
await searchFrases();
}
else if (maps){
await searchMaps();
}
else {
await searchCorreos();
}
})
$("#frases").change(function () {
if (this.checked) {
$("#openDomain").prop('checked', false);
$("#maps").prop('checked', false);
}
});
$("#openDomain").change(function () {
if (this.checked) {
$("#frases").prop('checked', false);
$("#maps").prop('checked', false);
}
});
$("#maps").change(function () {
if (this.checked) {
$("#frases").prop('checked', false);
$("#openDomain").prop('checked', false);
}
});
});
</script>
</header>
<body class="d-flex flex-column">
<div id="page-content">
<div class="container text-center">
<div class="p-2 row">
<div class="form-group w-50 col-sm">
<h3>Buscar </h1>
<textarea class="form-control" id="text-area-search" rows="10"></textarea>
<div class="form-box">
<div class="p-2">
<a class="btn btn-primary" id="search"> Buscar</a>
</div>
<div class="p-2">
<input type="checkbox" id="openDomain" checked>
<label for="openDomain">Directo</label>
</div>
<div class="p-2">
<input type="checkbox" id="frases">
<label for="frases">Frases</label>
</div>
<div class="p-2">
<input type="checkbox" id="maps">
<label for="maps">Maps</label>
</div>
<div class="p-2">
<input type="checkbox" id="allowRepeat" checked>
<label for="allowRepeat">Repetidos</label>
</div>
<div class="p-2">
<input type="number" id="wait" value="0.5" max="3.0" min="0.1" step="0.2">
<label for="wait">Espera (segundos)</label>
</div>
</div>
</div>
</div>
</div>
</div>
<footer id="sticky-footer" class="flex-shrink-0 py-4 bg-dark text-white-50">
<div class="container text-center">
<small>Buscador V1.0.0 22-Jul-22</small>
</div>
</footer>
</body>