Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save DanielOberg/613436 to your computer and use it in GitHub Desktop.
Save DanielOberg/613436 to your computer and use it in GitHub Desktop.
Rot13
/*
Put your "encrypted" (ROT13) email address in a link and this script will decrypt it.
This helps against SPAM-bots (they almost never have a javascript engine running,
it's to computationally expensive to be worthwhile).
Useage:
<a href="mailto:qrzb@qrzb.pbz">qrzb@qrzb.pbz</a>
Becomes
<a href="mailto:demo@demo.com">demo@demo.com</a>
Requires use of a standard ROT13 converter, for example:
http://rot13.de/index.php
Modified from:
http://github.com/buckwilson/jquery-grab-bag
*/
$.fn.rot13 = function() {
this.each(function() {
var rot13fn = function(chr) {
var cc = chr.charCodeAt(0);
if (cc >= 65 && cc <= 90) cc = 65 + ((cc - 52) % 26);
else if (cc >= 97 && cc <= 122) cc = 97 + ((cc - 84) % 26);
else if (cc >= 48 && cc <= 57) cc = 48 + ((cc - 43) % 10);
return String.fromCharCode(cc);
};
$(this).text($(this).text().replace(/[a-z0-9]/ig, function(chr) {return rot13fn(chr)}));
$(this).attr("href", "mailto:" + $(this).attr("href").replace("mailto:", "").replace(/[a-z0-9]/ig, function(chr) {return rot13fn(chr)}));
});
return this;
};
$(document).ready(function () {
$("a[href^=mailto]").rot13();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment