1function HumansNotBots(replacement_method, strAT, strDOT) { 2 if (document.getElementsByTagName) { 3 if (strAT == null || strDOT == null) { 4 strAT = "AT"; 5 strDOT = "DOT"; 6 } 7 var disguisedForm = "([a-zA-Z0-9._%+-]+)\\s" + strAT + "\\s([a-zA-Z0-9.-]+)\\s" + strDOT + "\\s(co\.uk|[a-zA-Z]{2,4})"; 8 var htmlbody = document.getElementsByTagName('body')[0]; 9 if (replacement_method == 'innerhtml') 10 HumansNotBots_innerhtml(htmlbody, disguisedForm); 11 else if (replacement_method == 'dom') 12 HumansNotBots_dom(htmlbody, disguisedForm); 13 } 14} 15 16/* innerHTML replacement method */ 17function HumansNotBots_innerhtml(htmlbody, disguisedForm) { 18 var matchexp = new RegExp(disguisedForm, "g"); 19 var replacement = '<a href="mailto:$1@$2.$3">$1@$2.$3</a>'; 20 var newInnerHTML = htmlbody.innerHTML.replace(matchexp, replacement); 21 htmlbody.innerHTML = newInnerHTML; 22} 23 24/* Walk the DOM replacement method */ 25function HumansNotBots_dom(element, disguisedForm) { 26 if (element) { 27 if (element.hasChildNodes()) { 28 var child = element.firstChild; 29 while (child) { 30 HumansNotBots_dom(child, disguisedForm); 31 child = child.nextSibling; 32 } 33 } 34 else if (element.nodeValue) { 35 var matchexp = new RegExp(disguisedForm, "g"); 36 var disguisedEmailAddresses = element.nodeValue.match(matchexp); 37 if (disguisedEmailAddresses !== null) { 38 var unprocessedText = element.nodeValue; 39 var newParentsChildren = new Array(); 40 for (var i = 0; i < disguisedEmailAddresses.length; i++) { 41 var disguisedEmailAddress = disguisedEmailAddresses[i]; 42 43 /* textBefore is the text in unprocessedText that comes before the first disguised email address in unprocessedText */ 44 var textBefore = unprocessedText.substring(0,unprocessedText.search(new RegExp(disguisedEmailAddress))); 45 if (textBefore) { 46 newParentsChildren.push(document.createTextNode(textBefore)); 47 } 48 var matchexp1 = new RegExp(disguisedForm); 49 var realEmailAddress = disguisedEmailAddress.replace(matchexp1, '$1@$2.$3'); 50 var a = document.createElement('a'); 51 a.setAttribute('href', 'mailto:' + realEmailAddress); 52 a.appendChild(document.createTextNode(realEmailAddress)); 53 54 newParentsChildren.push(a); 55 56 unprocessedText = unprocessedText.substring(textBefore.length + disguisedEmailAddress.length); 57 } 58 59 if (unprocessedText) { 60 // there is some text after the last disguised email address 61 newParentsChildren.push(document.createTextNode(unprocessedText)); 62 } 63 64 /* replace element with newParentsChildren */ 65 var parent = element.parentNode; 66 var child = newParentsChildren.shift(); 67 while (child) { 68 parent.insertBefore(child, element); 69 child = newParentsChildren.shift(); 70 } 71 parent.removeChild(element); 72 } 73 } 74 } 75} 76
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.