forked from RealStrategy/HOSTEXTRACTOR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
78 lines (66 loc) · 2.38 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
// Extraer URL unicas sin duplicado
function extractUrlsFromText(text) {
var urlRegex = /(https?:\/\/[^\s]+)/g;
return text.match(urlRegex) || [];
}
function extractUrlsFromHref(text) {
var hrefUrls = [];
var hrefRegex = /href=["']([^"']+)["']/g;
var matches;
while ((matches = hrefRegex.exec(text)) !== null) {
var hrefUrl = matches[1];
if (hrefUrl.startsWith("http://") || hrefUrl.startsWith("https://")) {
hrefUrls.push(hrefUrl);
}
}
return hrefUrls;
}
function extractUrls() {
var inputText = document.getElementById('input-text').value;
var resultText = document.getElementById('result-text');
// Clear previous results
resultText.value = '';
// Extract URLs from text and href attributes
var urls = extractUrlsFromText(inputText);
var hrefUrls = extractUrlsFromHref(inputText);
urls = urls.concat(hrefUrls);
// Display URLs
if (urls.length > 0) {
urls = Array.from(new Set(urls));
resultText.value = urls.join('\n');
} else {
resultText.value = 'No encontrado.';
}
}
function extractUniqueUrls() {
var inputText = document.getElementById('input-text').value;
var resultText = document.getElementById('result-text');
// Clear previous results
resultText.value = '';
// Extract URLs from text and href attributes
var urls = extractUrlsFromText(inputText);
var hrefUrls = extractUrlsFromHref(inputText);
urls = urls.concat(hrefUrls);
// Remove duplicate URLs and extract domains
var uniqueDomains = [];
var domainRegex = /^(?:https?:\/\/)?(?:[^@\n]+@)?(?:www\.)?([^:\/\n?]+)/img;
var matches;
while ((matches = domainRegex.exec(urls.join('\n'))) !== null) {
var domain = matches[1];
if (!uniqueDomains.includes(domain)) {
uniqueDomains.push(domain);
}
}
// Display unique domains
if (uniqueDomains.length > 0) {
resultText.value = uniqueDomains.join('\n');
} else {
resultText.value = 'No encontrado.';
}
}
// Agrega el evento al botón de extracción
var extractButton = document.getElementById('extract-button');
extractButton.addEventListener('click', extractUrls);
// Agrega el evento al botón de extracción sin repetir
var extractUniqueButton = document.getElementById('extract-unique-button');
extractUniqueButton.addEventListener('click', extr