Created
September 28, 2023 06:45
-
-
Save betillogalvanfbc/a3f263cefe9d04e56b32048336309de5 to your computer and use it in GitHub Desktop.
extract-emails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
const regex = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g; | |
const results = new Set(); | |
async function fetchAndExtractEmails(url) { | |
try { | |
const response = await fetch(url); | |
const text = await response.text(); | |
const matches = text.matchAll(regex); | |
for (const match of matches) { | |
results.add(match[0]); | |
} | |
} catch (error) { | |
console.log("An error occurred:", error); | |
} | |
} | |
async function extractEmailsFromScripts() { | |
const scripts = document.getElementsByTagName("script"); | |
const scriptUrls = Array.from(scripts).map(script => script.src).filter(Boolean); | |
await Promise.all(scriptUrls.map(fetchAndExtractEmails)); | |
} | |
async function extractEmailsFromPage() { | |
const pageContent = document.documentElement.outerHTML; | |
const matches = pageContent.matchAll(regex); | |
for (const match of matches) { | |
results.add(match[0]); | |
} | |
} | |
async function writeEmails() { | |
await Promise.all([extractEmailsFromScripts(), extractEmailsFromPage()]); | |
results.forEach(function(email) { | |
document.write(email + "<br>"); | |
}); | |
} | |
setTimeout(writeEmails, 3000); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment