1/* 2 * JavaScript for La Sentinelle antispam. 3 * 4 5Copyright 2018 - 2026 Marcel Pol (email: [email protected]) 6 7This program is free software; you can redistribute it and/or modify 8it under the terms of the GNU General Public License as published by 9the Free Software Foundation; either version 2 of the License, or 10(at your option) any later version. 11 12This program is distributed in the hope that it will be useful, 13but WITHOUT ANY WARRANTY; without even the implied warranty of 14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15GNU General Public License for more details. 16 17You should have received a copy of the GNU General Public License 18along with this program; if not, write to the Free Software 19Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20*/ 21 22 23/* 24 * Mangle data for the honeypot. 25 * 26 * @since 1.0.0 27 */ 28document.addEventListener("DOMContentLoaded", () => { 29 document.querySelectorAll('form')?.forEach( function(form) { 30 31 var honeypot = la_sentinelle_frontend_script.honeypot; 32 var honeypot2 = la_sentinelle_frontend_script.honeypot2; 33 34 var honeypot_val = parseInt( form.querySelector(`input.${honeypot}`)?.value, 10 ); 35 var honeypot2_val = parseInt( form.querySelector(`input.${honeypot2}`)?.value, 10 ); 36 37 if ( ! isNaN( honeypot_val ) && (typeof honeypot_val != "undefined") && (typeof honeypot2_val != "undefined") ) { 38 la_sentinelle_honeypot( form ); 39 } 40 }); 41 42 // Hook into this.reset for Contact Form 7 refill. 43 document.querySelector('form.wpcf7-form')?.addEventListener('reset', function() { 44 var form = this; 45 setTimeout(function() { 46 la_sentinelle_honeypot( form ); 47 }, 500 ); 48 }); 49 50}); 51 52function la_sentinelle_honeypot( form ) { 53 54 var honeypot = la_sentinelle_frontend_script.honeypot; 55 var honeypot2 = la_sentinelle_frontend_script.honeypot2; 56 57 var honeypot_val = parseInt( form.querySelector(`input.${honeypot}`)?.value, 10 ); 58 var honeypot2_val = parseInt( form.querySelector(`input.${honeypot2}`)?.value, 10 ); 59 60 if ( ! isNaN( honeypot_val ) && (typeof honeypot_val != "undefined") && (typeof honeypot2_val != "undefined") ) { 61 if ( honeypot_val > 0 ) { 62 form.querySelector(`input.${honeypot2}`).value = honeypot_val; 63 form.querySelector(`input.${honeypot}`).value = ''; 64 } 65 } 66} 67 68 69/* 70 * Mangle data for the form timeout. 71 * 72 * @since 1.0.0 73 */ 74document.addEventListener("DOMContentLoaded", () => { 75 document.querySelectorAll('form')?.forEach( function(form) { 76 77 var timeout = la_sentinelle_frontend_script.timeout; 78 var timeout2 = la_sentinelle_frontend_script.timeout2; 79 80 var timer = parseInt( form.querySelector(`input.${timeout}`)?.value, 10 ); 81 var timer2 = parseInt( form.querySelector(`input.${timeout2}`)?.value, 10 ); 82 83 if ( ! isNaN( timer ) && ! isNaN( timer2 ) && (typeof timer != "undefined") && (typeof timer2 != "undefined") ) { 84 85 // Use setTimeout multiple times to avoid refill by contact form 7 when caching is used. 86 for ( var counter = 0; counter < 20; counter++ ) { 87 var timecounter = ( counter * 500 ); 88 setTimeout(function() { 89 la_sentinelle_timeout( form ); 90 }, timecounter ); 91 } 92 93 } 94 }); 95 96 // Hook into this.reset for Contact Form 7 refill. 97 document.querySelector('form.wpcf7-form')?.addEventListener('reset', function() { 98 var form = this; 99 setTimeout(function() { 100 la_sentinelle_timeout( form ); 101 }, 500 ); 102 }); 103}); 104 105function la_sentinelle_timeout( form ) { 106 107 var timeout = la_sentinelle_frontend_script.timeout; 108 var timeout2 = la_sentinelle_frontend_script.timeout2; 109 110 var timer = parseInt( form.querySelector(`input.${timeout}`)?.value, 10 ); 111 var timer2 = parseInt( form.querySelector(`input.${timeout2}`)?.value, 10 ); 112 113 if ( ! isNaN( timer ) && ! isNaN( timer2 ) && (typeof timer != "undefined") && (typeof timer2 != "undefined") ) { 114 115 var timer = timer - 1; 116 var timer2 = timer2 + 1; 117 118 form.querySelector(`input.${timeout}`).value = timer; 119 form.querySelector(`input.${timeout2}`).value = timer2; 120 121 } 122 123} 124 125 126/* 127 * AJAX spamfilter. 128 * 129 * @since 3.0.0 130 */ 131document.addEventListener("DOMContentLoaded", () => { 132 document.querySelectorAll('form')?.forEach( (form) => { 133 var ajax2_field = la_sentinelle_frontend_script.ajax2; 134 var ajax3_field = la_sentinelle_frontend_script.ajax3; 135 var ajax2_val = parseInt( form.querySelector(`input.${ajax2_field}`)?.value, 10 ); 136 137 var ajax_enabled = la_sentinelle_frontend_script.ajax_enabled; 138 if ( ajax_enabled !== 'true' ) { 139 return; 140 } 141 142 if ( (typeof ajax2_val !== 'undefined') && ( ! isNaN( ajax2_val ) ) && ajax2_val > 0 ) { 143 144 var ajax3_val = form.querySelector(`input.${ajax3_field}`).value; 145 146 // Set up data to send 147 var ajaxurl = la_sentinelle_frontend_script.ajaxurl; 148 var data = new URLSearchParams({ 149 action: 'la_sentinelle_ajax', 150 ajax2: ajax2_val, 151 ajax3: ajax3_val 152 }); 153 154 var request = new XMLHttpRequest(); 155 156 request.open('POST', ajaxurl, true); 157 request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;'); 158 request.onload = function () { 159 response = this.response.trim(); 160 // console.log( response ); // debug: should say 'reported' if we got what we wanted. 161 }; 162 request.send(data.toString()); 163 164 } 165 }); 166});
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.