A useful trick: copy email on the screen

A useful trick: copy email on the screen

I was working on something, and I have a website that has multiple emails with anchor tag and mailto action. I need to copy all those mails for sending an email. The idea of one by one copying all those emails terrified me, So I produced a Pure JavaScript solution to copy all those email/phone numbers within a few clicks. Copy the below code in the console of whichever website you want emails to be copied:

var links = document.getElementsByTagName('a'), hrefs = [], sendIt = '';
for (var i = 0; i<links.length; i++)
{   
    if(links[i].href.includes('mailto')) {
      var email = links[i].href.replace('mailto:','');
      //If you want to use this as array
      hrefs.push(email);

      //If you want to copy all email ids in one string (usually to send mail to multiple ids at once)
      sendIt += email + ', ';
    }
}

// Auto-Copy e-mail from string
var el = document.createElement('textarea');
el.value = sendIt;
el.setAttribute('readonly', '');
el.style = {display: 'none'};
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);

Now, just hit enter on console and Bazinga!! All the emails will be copied into your clipboard.
I am also trying to make a chrome extension for this, so it can be handy for non-tech people also. I’ll update when it's done. I might write another post on how to make chrome extensions too.