1/* 2 * @copyright (c) 2024. 3 * @author Alan Fuller (support@fullworks) 4 * @licence GPL V3 https://www.gnu.org/licenses/gpl-3.0.en.html 5 * @link https://fullworks.net 6 * 7 * This file is part of Fullworks Anti Spam. 8 * 9 * Fullworks Anti Spam is free software: you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation, either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * Fullworks Anti Spam is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with Fullworks Anti Spam. https://www.gnu.org/licenses/gpl-3.0.en.html 21 * 22 * 23 */ 24const fas_forms = FullworksAntiSpamFELO.form_selectors; 25let activityTimer; 26let sustainedActivity = false; 27let honeyInputAdded = false; 28 29(function ($) { 30 'use strict'; 31 32 // Function to detect if the page was accessed via the back button 33 const isBackAction = () => { 34 return history.state && history.state.isBackAction; 35 }; 36 37 // Function to mark that the current state is not a back action 38 const markAsNotBackAction = () => { 39 if (!history.state || !history.state.isBackAction) { 40 history.replaceState({ isBackAction: false }, document.title, location.href); 41 } 42 }; 43 44 // Function to mark the state as a back action 45 const markAsBackAction = () => { 46 history.pushState({ isBackAction: true }, document.title, location.href); 47 }; 48 49 // Mark the current state as not a back action on page load 50 $(window).on('load', markAsNotBackAction); 51 52 /** anti spam fields */ 53 $(function () { 54 const addHoneyInput = () => { 55 if ((sustainedActivity || isBackAction()) && !honeyInputAdded) { 56 $.ajax({ 57 url: FullworksAntiSpamFELO.ajax_url, 58 type: 'POST', 59 dataType: 'json', 60 data: { action: "fwas_get_keys" }, 61 success: function (response) { 62 const fas_honeyinput = `<input type='hidden' name='${response.name}' value='${response.value}' />`; 63 $(fas_forms).each(function () { 64 if (!$(this).find(`input[name='${FullworksAntiSpamFELO.name}']`).length) { 65 $(this).prepend(fas_honeyinput); 66 } 67 }); 68 honeyInputAdded = true; 69 } 70 }); 71 } 72 }; 73 const detectActivity = () => { 74 if (!sustainedActivity) { 75 clearTimeout(activityTimer); 76 activityTimer = setTimeout(() => { 77 sustainedActivity = true; 78 addHoneyInput(); 79 }, 1000); // wait for 1 seconds of sustained activity 80 } 81 }; 82 $(document).on('mousemove keypress', detectActivity); 83 // Adding 'focus' event to catch Tab key navigation 84 $(document).on('focus', 'input, select, textarea, button, a', detectActivity); 85 // Mutation observer to ensure the form keeps the honeyinput field 86 const mutationObserver = new MutationObserver(addHoneyInput); 87 mutationObserver.observe(document.body, { childList: true, subtree: true }); 88 89 // Mark the current state as a back action before the page unloads 90 window.addEventListener('pagehide', markAsBackAction); 91 92 // Handle page restoration from back/forward cache 93 window.addEventListener('pageshow', function(event) { 94 if (event.persisted) { 95 // Page was restored from bfcache, ensure honeyinput is added 96 addHoneyInput(); 97 } 98 }); 99 }); 100})(jQuery);
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.