require(['jquery'], function ($) { window.formToProtectOnPage = []; formsToProtect = ["form[action*=\"customer\/account\/createpost\"]","form[action*=\"newsletter\/subscriber\/new\"]","form[action*=\"review\/product\/post\"]","form[action*=\"customer\/account\/forgotpassword\"]","form[action*=\"customer\/account\/login\"]","form[action*=\"checkout\/cart\/couponPost\"]"]; formsToProtect.forEach(function(item) { formToProtect = $(item)[0]; if (formToProtect) { window.formToProtectOnPage.push(formToProtect); } }); if (window.formToProtectOnPage.length) { var recaptchaScript = document.createElement('script'); recaptchaScript.src = 'https://www.google.com/recaptcha/api.js?onload=amInvisibleCaptchaOnloadCallback&render=explicit'; recaptchaScript.attributes = 'async defer'; document.body.appendChild(recaptchaScript); } window.amInvisibleCaptchaOnloadCallback = function () { for (var i = 0; i < window.formToProtectOnPage.length; i++) { window.formToProtectOnPage[i].innerHTML += ''; } var id = ""; if (id) { var additionalForm = document.getElementById(id).form; if (additionalForm) { window.formToProtectOnPage.push(additionalForm); } } for (var i = 0; i < window.formToProtectOnPage.length; i++) { var form = window.formToProtectOnPage[i]; if (form.tagName.toLowerCase() != 'form') { continue; } id = form.querySelector("[type='submit']"); (function(form, id) { grecaptcha.render(id, { 'sitekey': '6Lc_GUAUAAAAABZ7DenHpbr62mJznM1DoUFeLUIL', 'callback': function(token) { if ($(form).valid()){ form.querySelector("[name='amasty_invisible_token']").setAttribute('value', token) form.submit(); } else { grecaptcha.reset(); } } }); })(form, id); } }; });