1/** 2 * @file 3 * Unlock protected forms. 4 * 5 * This works by resetting the form action to the path that It should be as well 6 * as injecting the secret form key, only if the current user is verified to be 7 * human which is done by waiting for a mousemove, swipe, or tab/enter key to be 8 * pressed. 9 */ 10 11(function (Drupal, drupalSettings) { 12 "use strict"; 13 14 drupalSettings.antibot = drupalSettings.antibot || {}; 15 Drupal.antibot = {}; 16 17 Drupal.behaviors.antibot = { 18 attach: function (context, settings) { 19 drupalSettings = settings; 20 // Assume the user is not human, despite JS being enabled. 21 drupalSettings.antibot.human = false; 22 23 // Wait for a mouse to move, indicating they are human. 24 document.body.addEventListener('mousemove', function () { 25 // Unlock the forms. 26 Drupal.antibot.unlockForms(); 27 }); 28 29 // Wait for a touch move event, indicating that they are human. 30 document.body.addEventListener('touchmove', function () { 31 // Unlock the forms. 32 Drupal.antibot.unlockForms(); 33 }); 34 35 // A tab or enter key pressed can also indicate they are human. 36 document.body.addEventListener('keydown', function (e) { 37 if ((e.code == 'Tab') || (e.code == 'Enter')) { 38 // Unlock the forms. 39 Drupal.antibot.unlockForms(); 40 } 41 }); 42 } 43 }; 44 45 /** 46 * Unlock all locked forms. 47 */ 48 Drupal.antibot.unlockForms = function () { 49 // Act only if we haven't yet verified this user as being human. 50 if (!drupalSettings.antibot.human) { 51 // Check if there are forms to unlock. 52 if (drupalSettings.antibot.forms != undefined) { 53 // Iterate all antibot forms that we need to unlock. 54 Object.values(drupalSettings.antibot.forms).forEach(function (config) { 55 // Switch the action. 56 const form = document.getElementById(config.id); 57 if (form) { 58 form.setAttribute('action', form.getAttribute('data-action')); 59 60 // Set the key. 61 const input = form.querySelector('input[name="antibot_key"]'); 62 if (input) { 63 input.value = config.key.split("").reverse().join("").match(/.{1,2}/g).map((value) => value.split("").reverse().join("")).join(""); 64 } 65 } 66 }); 67 } 68 // Mark this user as being human. 69 drupalSettings.antibot.human = true; 70 } 71 }; 72})(Drupal, drupalSettings);
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.