1/** 2 * Ðлагин, коÑоÑÑй иниÑиализиÑÑÐµÑ Ð½ÐµÐ²Ð¸Ð´Ð¸Ð¼ÑÑ Google Recaptcha V3 3 * Ð ÑоÑме бÑÐ´ÐµÑ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½ клаÑÑ not-initialized, пока иниÑиализиÑÑеÑÑÑ reCaptcha и оÑпÑавиÑÑ ÑоÑÐ¼Ñ Ð½ÐµÐ²Ð¾Ð·Ð¼Ð¾Ð¶Ð½Ð¾ 4 * Ð ÑоÑме бÑÐ´ÐµÑ Ð´Ð¾Ð±Ð°Ð²Ð»ÐµÐ½ клаÑÑ submiting, пока бÑÐ´ÐµÑ Ð¸Ð´Ñи запÑÐ¾Ñ Ð½Ð° полÑÑение Ñокена и повÑоÑно оÑпÑавиÑÑ ÑоÑÐ¼Ñ Ð±ÑÐ´ÐµÑ Ð½ÐµÐ²Ð¾Ð·Ð¼Ð¾Ð¶Ð½Ð¾ 5 * ÐаннÑе клаÑÑÑ Ð¼Ð¾Ð¶Ð½Ð¾ иÑполÑзоваÑÑ Ð´Ð»Ñ ÑÑилизаÑии кнопки ÐÑпÑавки. 6 * 7 * @author ReadyScript lab. 8 */ 9 10(function() { 11 /** 12 * ÐлаÑÑ Ð¾Ð±ÐµÑпеÑÐ¸Ð²Ð°ÐµÑ ÑабоÑÑ Ð¾Ð´Ð½Ð¾Ð¹ ÑоÑÐ¼Ñ Ñ ReCaptchaV3 13 */ 14 class reCaptchaV3 { 15 16 constructor(form) { 17 this.form = form; 18 this.submitButton = this.form.querySelector('[type="submit"]'); 19 this.canSubmit = false; 20 21 this.bindForm(); 22 } 23 24 setCanSubmit(bool) { 25 this.canSubmit = bool; 26 this.submitButton.disabled = !bool; 27 } 28 29 bindForm() { 30 if (typeof(grecaptcha) != 'undefined') { 31 if (this.form) { 32 this.setCanSubmit(false); 33 34 this.form.classList.add('not-initialized'); 35 36 //ÐбÑабаÑÑваем ÑобÑÑие оÑпÑавки ÑоÑмÑ. ÐÑÐ¾Ñ Ð¾Ð±ÑабоÑÑик бÑÐ´ÐµÑ Ð²Ñегда пеÑвÑй 37 this.form.addEventListener('submit', (event) => { 38 39 if (!this.form.reCaptchaSubmit) { 40 let captchaInput = this.form.querySelector('.recaptcha-v3'); 41 if (captchaInput) { 42 let action = captchaInput.dataset.context ? captchaInput.dataset.context : 'default'; 43 action = action.replace(/[^A-Za-z/_]/g, ''); 44 45 event.preventDefault(); //ÐапÑеÑаем оÑпÑавлÑÑÑ ÑоÑÐ¼Ñ Ð»ÑбÑм еÑÑеÑÑвеннÑм обÑазом. 46 event.stopPropagation(); 47 // ФоÑÐ¼Ñ Ð¼Ð¾Ð¶Ð½Ð¾ бÑÐ´ÐµÑ Ð¾ÑпÑавиÑÑ ÑолÑко поÑле полÑÑÐµÐ½Ð¸Ñ Ñокена ReCaptcha. 48 49 if (this.canSubmit) { 50 this.setCanSubmit(false); 51 this.form.classList.add('submiting'); 52 53 //ÐобавлÑем Ñокен reCaptcha, а заÑем повÑоÑÑем попÑÑÐºÑ Ð¾ÑпÑавки ÑоÑÐ¼Ñ 54 grecaptcha.execute(global.reCaptchaV3SiteKey, {action: action}) 55 .then((token) => { 56 captchaInput.value = token; 57 console.log('call'); 58 this.form.reCaptchaSubmit = true; 59 this.form.submit(); 60 this.form.classList.remove('submiting'); 61 this.setCanSubmit(true); 62 }, (error) => { 63 console.error('ReCaptcha V3 Error' + error); 64 this.form.classList.remove('submiting'); 65 this.setCanSubmit(true); 66 }); 67 } 68 } 69 } 70 }, true); //Ðовим ÑобÑÑие в Ñежиме capture 71 72 grecaptcha.ready(() => { 73 //УбиÑаем клаÑÑ Ñ ÑоÑмÑ, когда загÑÑзиÑÑÑ ReCaptcha 74 this.form.classList.remove('not-initialized'); 75 this.setCanSubmit(true); 76 }); 77 } 78 } else { 79 alert('Ðе подклÑÑен Google ReCaptcha API.js ÑкÑипÑ'); 80 } 81 } 82 83 static init(context) { 84 context.querySelectorAll('form .recaptcha-v3').forEach(it => { 85 let form = it.closest('form'); 86 if (form) { 87 if (!form.reCaptchaV3) { 88 form.reCaptchaV3 = new reCaptchaV3(form); 89 } 90 } 91 }); 92 } 93 } 94 95 document.addEventListener('DOMContentLoaded', (event) => { 96 reCaptchaV3.init(event.target); 97 }); 98 99 document.addEventListener('new-content', (event) => { 100 reCaptchaV3.init(event.target); 101 }); 102})();
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.