Fetch / Read all email addresses from a web page using JavaScript

Recently I was looking some consultants mails ids and found some sites, in which the list of job consultants’ mail ids were listed with their names, address and email ids. But it was a tedious job to go thru the websites, classified portals pages to copy each and every mail id and save it to Excel sheet for further reference/process.
So I came up with this small script, which can be run from the Firebug or Chrome console.
just copy and paste this snippet into the console and call the findEmails function.
Calling the script is very easy. call the script as findEmails(). Voila. Worked as a charm.

function findEmails(){
var StrObj = document.body.innerText; var separateEmailsBy = ", ";
var email = ""; // if no match, use this
var emailsArray = StrObj.match(/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9._-]+)/gi);
if (emailsArray) {
email = "";
for (var i = 0; i < emailsArray.length; i++) { if (i != 0) email += separateEmailsBy; email += emailsArray[i]; } } return email; }

you may need to tweak a little bit to make it work for all email address patterns.