Last active
March 12, 2019 21:57
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, '.'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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