Skip to content

Instantly share code, notes, and snippets.

@do18
Last active March 12, 2019 21:57
Show Gist options
  • Save do18/4341029 to your computer and use it in GitHub Desktop.
Save do18/4341029 to your computer and use it in GitHub Desktop.
For trivial protection against dumb email address crawlers, write <a href=mailto:me(at)example(dot)org>me(at)example(dot)org</a> and include this JS at the bottom of the page.
// jshint esversion: 6, maxlen: 80, strict: global
'use strict';
// In mailto: links, replace '(at)' with '@' and '(dot)' with '.'
{
const at = /\(at\)/gi;
const dot = /\(dot\)/gi;
const links = document.querySelectorAll('a[href^="mailto:"]');
for (let link of links) {
link.href = link.href.replace(at, '@').replace(dot, '.');
link.innerHTML = link.innerHTML.replace(at, '@').replace(dot, '.');
}
}
// jshint maxlen: 80, strict: global
'use strict';
// In mailto: links, replace '(at)' with '@' and '(dot)' with '.'
(function (d) {
var at = /\(at\)/gi;
var dot = /\(dot\)/gi;
var link;
var links = d.querySelectorAll('a[href^="mailto:"]');
var i;
var max;
for (i = 0, max = links.length; i < max; i++) {
link = links[i];
link.href = link.href.replace(at, '@').replace(dot, '.');
link.innerHTML = link.innerHTML.replace(at, '@').replace(dot, '.');
}
})(document);
(function(a){var c=/\(at\)/gi,d=/\(dot\)/gi,e=a.querySelectorAll('a[href^="mailto:"]'),f;var b=0;for(f=e.length;b<f;b++)a=e[b],a.href=a.href.replace(c,"@").replace(d,"."),a.innerHTML=a.innerHTML.replace(c,"@").replace(d,".")})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment