Skip to content

Instantly share code, notes, and snippets.

@jxxe
Last active September 23, 2021 20:57
Show Gist options
  • Save jxxe/34560bfbaa3d65a7e3ee39f4ce50db19 to your computer and use it in GitHub Desktop.
Save jxxe/34560bfbaa3d65a7e3ee39f4ce50db19 to your computer and use it in GitHub Desktop.
Hide email addresses from crawlers
<a email="ZW5jb2RlZEBlbWFpbC5jb20=">Enable JavaScript to view this email address</a>
<a email="YW5vdGhlckBlbWFpbC5jb20=">Enable JavaScript to view this email address</a>
<script>
document.querySelectorAll('[email]').forEach(email => {
let decodedEmail = atob(email.getAttribute('email'));
email.innerText = decodedEmail;
email.href = 'mailto:'+decodedEmail;
email.removeAttribute('email');
})
</script>
<!-- Bonus Code Golf -->
<script>q='email';document.querySelectorAll(`[${q}]`).forEach(l=>{e=atob(l.getAttribute(q));l.innerText=e;l.href='mailto:'+e;l.removeAttribute(q)});</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment