Skip to content
This repository has been archived by the owner on Feb 7, 2024. It is now read-only.

https://jackchilds.tech/posts/reducing_spam_from_mailto_links #11

Open
utterances-bot opened this issue Apr 28, 2022 · 7 comments
Open
Labels
post-comments A blog post comment section

Comments

@utterances-bot
Copy link

Reducing spam from mailto links

How I reduce email spam from mailto links and mail forms on my website

https://jackchilds.tech/posts/reducing_spam_from_mailto_links

Copy link

oohohoo commented Apr 28, 2022

hello, and congrats on your first post :) how do i use it in plain js/html, no components, react etc...? thank you and cheers

Copy link

It is a couple lines of code in Vanilla JavaScript; might be too short if you are used to React

<data-protect email="[email protected]"><a href="mailto:EMAIL">contact me at EMAIL</a></data-protect>
<script>
  customElements.define('data-protect', class extends HTMLElement {
    connectedCallback() {
      this.onmouseover = () => {
      	this.innerHTML = this.innerHTML.replaceAll("EMAIL",this.getAttribute("email"));
      }
    }
  });
</script>

Copy link

oohohoo commented Apr 28, 2022

thank you, it works! but, is it bot proof? cause the email is still visible in html: ?

Copy link
Owner

What I would recommend you do is to take a look at the bundle.js file in the DataProtect repository, you can grab the file from any cdn like jsdelivr, etc.

For a full example, take a look at this jsfiddle: https://jsfiddle.net/rkhxbp9c/

As well as this file here: https://github.com/JackChilds/Data-Protect/blob/main/test/demo.html

The main difference is that unlike the Next.js version, you will have to manually encode the data first as you can't encode it at build time (or on the server at runtime) in order to hide it from the source code.

Hope this helps.

Copy link

oohohoo commented Apr 28, 2022

everything works now
thank you very much :)

Copy link

gnawood commented May 12, 2022

Why bother to encode the address and tell the crawler you are using trickery.
My approach is to put a wrongly spelt address in the html which hopefully will make most crawlers happy.
Then at run time use a script decoder to correct the spelling mistake.
Adding a delay is an interesting wrinkle, but does it help if the crawler is willing to run the java and scrape the result.

Copy link
Owner

@gnawood an interesting idea!
The delay is there so that even if the crawler runs js, they will have to know that they must wait a period of time (the delay) until they can get the email address.

@JackChilds JackChilds added the post-comments A blog post comment section label May 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
post-comments A blog post comment section
Projects
None yet
Development

No branches or pull requests

5 participants