Hyper Lord
Mitglied
Hallo, ich hoffe es ist auch erlaubt einfach nur eine oder mehrere Meinungen einzuholen...
falls nicht, bitte ich um entschuldigung!
Ich habe versucht ein js only Loesung ohne jquery zu erstellen um Emails for den E-Mail-Harvester zu schuetzen.
Funktioniert auch erstmal soweit.
Meine Frage ist nun:
1. ist das ausreichend?
2. ist der ansatz gut oder ist die idee totaler bloedsinn?
Also hier mal der Code:
und hier der html teil ( sehr duenn gehalten )
fuer das cloaking habe ich CryptoJS.AES verwended...
Vielen Dank fuer eure Meinungen
falls nicht, bitte ich um entschuldigung!
Ich habe versucht ein js only Loesung ohne jquery zu erstellen um Emails for den E-Mail-Harvester zu schuetzen.
Funktioniert auch erstmal soweit.
Meine Frage ist nun:
1. ist das ausreichend?
2. ist der ansatz gut oder ist die idee totaler bloedsinn?
Also hier mal der Code:
Javascript:
//mailClass -> classname when is set on the specified a tags
//secString -> set own secure string
var EMAILDEFENDER = function(mailClass, secString) {
var sec = secString || 'EMailDefenderV1.0-Sicherheitsphrase'; //need to be change or set own param!!!
var tag = 'a'+((mailClass)?'.'+mailClass:'');
var self = this;
var _init = function() {
window.addEventListener("load", function(event) {
var elems = document.querySelectorAll(tag);
for(var i=0;i<elems.length;i++) {
if(elems[i].href.indexOf('mailto:')>-1){
self.Cloak(elems[i]);
}
}
});
};
var _getCurrentStyle = function(elem,prop) {
return (elem.currentStyle)? elem.currentStyle[prop]:
(window.getComputedStyle.getPropertyValue)? window.getComputedStyle(elem, null).getPropertyValue(prop) :
window.getComputedStyle(elem)[prop];
};
var _maskHtml = function(email, opts) {
var canvas = document.createElement('canvas');
canvas.width = opts['width'];
canvas.height = opts['height']+5;
if (canvas && canvas.getContext) {
var ctx = canvas.getContext("2d");
if (ctx) {
ctx.font = opts['font-weight'] + " " + opts['font-size'] + " " + opts['font-family'];
ctx.fillStyle = opts['color'];
ctx.fillText(email, 0,opts['height']-1);
if(opts['text-decoration'] == 'underline') {
var text = ctx.measureText(email);
ctx.fillRect(0, opts['height']+1, text.width, 2);
}
}
}
return canvas.toDataURL('image/png');
};
var _uncloakString = function(cloaked) {
return 'mailto:'+(CryptoJS.AES.decrypt(cloaked.replace('mailto:', '').toString(), sec)).toString(CryptoJS.enc.Utf8);
};
this.Cloak = function(elem) {
// get current width and height of the tag, neccessary to set correct picture size
var width = elem.offsetWidth, height = elem.offsetHeight;
//get href value and encrypt it, delete innerHtml
var href = elem.href.replace('mailto:','');
elem.href = 'mailto:'+CryptoJS.AES.encrypt(href, sec);
elem.innerHTML = "";
/*create the img node width it's correct src and append it to the element
copy the current style to set it in the image/png
*/
var node = document.createElement("IMG"), options = new Array();
options['font-family'] = _getCurrentStyle(elem,'font-family');
options['font-size'] = _getCurrentStyle(elem,'font-size');
options['font-weight'] = _getCurrentStyle(elem,'font-weight');
options['color'] = _getCurrentStyle(elem,'color');
options['text-decoration'] = _getCurrentStyle(elem,'text-decoration');
options['width'] = width;
options['height'] = height;
node.src = _maskHtml(href, options);
elem.appendChild(node);
//add the click event to decrypt and set the location
elem.addEventListener("click", function(ev){ ev.preventDefault(); self.redirect(this.href); return false; });
};
this.redirect = function(mail) { window.location.href = _uncloakString(mail); return false; };
_init();
};
var mailDefense = new EMAILDEFENDER();
und hier der html teil ( sehr duenn gehalten )
HTML:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<style>
* { font-family:Arial; font-weight:bold; font-size:20px; color:#B404AE; text-decoration: none; }
</style>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
</head>
<body >
<a href="mailto:alert@test-mail.de" >alert@test-mail.de</a>
<br />
<a href="mailto:Alert@test2-mail.de" >Alert@test2-mail.com</a>
</body>
</html>
fuer das cloaking habe ich CryptoJS.AES verwended...
Vielen Dank fuer eure Meinungen
Zuletzt bearbeitet: