1/** 2 * RecaptchaV3 Handler 3 */ 4const RecaptchaV3Handler = function() {}; 5RecaptchaV3Handler.prototype = { 6 field: null, 7 configuration: { action: 'submit' }, 8 siteKey: '', 9 threshold: 30000, 10 // Initiate 11 init: function(options) { 12 if(!options.siteKey) { 13 throw new Error('no site key present'); 14 } 15 this.siteKey = options.siteKey; 16 if(options.configuration) { 17 this.configuration = options.configuration; 18 } 19 if(options.threshold > 0) { 20 this.threshold = options.threshold; 21 } 22 this.field = null; 23 if(options.id) { 24 this.field = document.getElementById(options.id); 25 } 26 if(!this.field) { 27 throw new Error('field ' + options.id + ' does not exist'); 28 } 29 return this; 30 }, 31 // determine if the token needs a refresh 32 requireRefresh: function() { 33 if(this.field.dataset.isPending == '1') { 34 return false; 35 } 36 if(this.field.value == '') { 37 return true; 38 } 39 let iv = 0; 40 let dlc = this.field.dataset.lastcheck; 41 if(dlc) { 42 iv = Date.now() - dlc; 43 } 44 return iv > this.threshold; 45 }, 46 // Attempt to retrieve a token 47 execute: function(evt) { 48 if(!this.requireRefresh()) { 49 return null; 50 } 51 this.field.dataset.isPending = '1'; 52 let _self = this; 53 grecaptcha.execute( 54 this.siteKey, 55 this.configuration 56 ).then( 57 function(token) { 58 _self.field.value = token; 59 _self.field.dataset.lastcheck = Date.now(); 60 }, 61 function(r) { 62 console.warn('rejected'); 63 } 64 ).catch( 65 function(fail) { 66 console.warn('catch in promise:' + fail); 67 } 68 ).then( 69 function() { 70 delete _self.field.dataset.isPending; 71 } 72 ); 73 return true; 74 }, 75 // Bind events on form fields that would retrieve a token 76 bindEvents: function() { 77 let _self = this; 78 Array.from(this.field.form.elements).filter( 79 (input) => { 80 return input.type != 'submit' && input.type != 'fieldset'; 81 } 82 ).forEach( 83 (input) => { 84 input.addEventListener( 85 'focus', 86 function(evt) { 87 _self.execute(evt); 88 } 89 ); 90 input.addEventListener( 91 'change', 92 function(evt) { 93 _self.execute(evt); 94 } 95 ); 96 } 97 ); 98 return this; 99 } 100};
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.