Skip to content

Instantly share code, notes, and snippets.

@tomhodgins
Created January 7, 2020 01:53
Show Gist options
  • Save tomhodgins/f4d4f060c0df43629222230f1ad2d76d to your computer and use it in GitHub Desktop.
Save tomhodgins/f4d4f060c0df43629222230f1ad2d76d to your computer and use it in GitHub Desktop.
document.documentElement.textContent // Get all of the text content on the web page.
.replace(/\b(\s*\[at\]\s*)\b/g, '@') // Replace any ' [at] ' with '@'.
.split(/\s+/) // Split text content by whitespace between words.
.filter(Boolean) // Eliminate any empty words.
.filter(string => { // Filter list of words:
const input = document.createElement('input') // by creating an <input> element,
input.type = 'email' // setting the input type to email,
input.value = string.trim() // setting its value to the current word,
return input.checkValidity() // and checking if it's a valid email address.
}) // Result: a list of all valid emails on the page.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment