From 73470df8e80c8c87749b29979b4b4156159962da Mon Sep 17 00:00:00 2001 From: HichemTab Date: Tue, 1 Aug 2023 15:01:32 +0100 Subject: [PATCH] some fixes --- README.md | 2 +- dist/easycaptcha.js | 22 +++++++++++++++++++++- dist/easycaptcha.min.js | 4 ++-- package-lock.json | 4 ++-- package.json | 2 +- src/easycaptcha.js | 20 ++++++++++++++++++++ webpack.config.js | 2 +- 7 files changed, 48 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 5fceca4..4d0c820 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ You can install EasyCaptchaJS via npm: You can also include EasyCaptchaJS directly from a CDN by adding the following script tag to your HTML file: ```HTML - + ``` ### Local Download diff --git a/dist/easycaptcha.js b/dist/easycaptcha.js index c9dd6a5..4fc50b1 100644 --- a/dist/easycaptcha.js +++ b/dist/easycaptcha.js @@ -1,5 +1,5 @@ /*! - * EasyCaptchaJS v1.0.1 + * EasyCaptchaJS v1.1.0 * (c) HichemTech * Released under the MIT License. * Github: https://github.com/HichemTab-tech/EasyCaptchaJS @@ -70,6 +70,26 @@ const EasyCaptcha = function (options = {}, ...args) { let results = []; const methods = { + 'getTarget': function (results, data, args) { + if (args.length !== 0) { + if (args[0].startsWith('#')) args[0] = args[0].substring(1); + if (args[0] === data.parentId) { + let res = { + parentElement: $("#" + data.parentId), + data: data + }; + results.push(res); + } + } + else{ + let res = { + parentElement: $("#" + data.parentId), + data: data + }; + results.push(res); + } + return results; + }, 'verify': function (results, data, args) { if (args.length !== 0) { if (args[0].startsWith('#')) args[0] = args[0].substring(1); diff --git a/dist/easycaptcha.min.js b/dist/easycaptcha.min.js index ad74651..6d95e86 100644 --- a/dist/easycaptcha.min.js +++ b/dist/easycaptcha.min.js @@ -1,7 +1,7 @@ /*! - * EasyCaptchaJS v1.0.1 + * EasyCaptchaJS v1.1.0 * (c) HichemTech * Released under the MIT License. * Github: https://github.com/HichemTab-tech/EasyCaptchaJS */ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.EasyCaptchaJS=t():e.EasyCaptchaJS=t()}(this,(()=>(()=>{"use strict";var e={d:(t,a)=>{for(var r in a)e.o(a,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:a[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{EasyCaptcha:()=>a});const a=function(e={},...t){let a=null===e;if(null===e&&(e={}),0===$(this).length&&!a)throw"no ReCaptcha div parent.";let n=[];const s={verify:function(e,t,a){if(0!==a.length){if(a[0].startsWith("#")&&(a[0]=a[0].substring(1)),a[0]===t.parentId){let a={verified:""!==i.getResponse(t.widgetId)};e.push(a)}}else{let a={parentElement:$("#"+t.parentId),verified:""!==i.getResponse(t.widgetId)};e.push(a)}return e},response:function(e,t,a){if(0!==a.length){if(a[0].startsWith("#")&&(a[0]=a[0].substring(1)),a[0]===t.parentId){let a={token:i.getResponse(t.widgetId)};e.push(a)}}else{let a={parentElement:$("#"+t.parentId),token:i.getResponse(t.widgetId)};e.push(a)}return e},reset:function(e,t,a){return 0!==a.length?(a[0].startsWith("#")&&(a[0]=a[0].substring(1)),a[0]===t.parentId&&i.reset(t.widgetId)):i.reset(),e},destroy:function(e,t){for(let e=0;e<$(this).length;e++)$("#"+t.parentId).empty(),$($(this)[e]).removeData("EasyCaptcha");return e}};if("object"==typeof e)r($(this),0,e,a);else for(let a=0;a<$(this).length;a++){let r=$($(this)[a]).data("EasyCaptcha");r&&void 0!==s[e]&&(n=s[e](n,r,[...t]))}return n.length>1?n:0===n.length?null:n[0]};function r(e,t,a,i){if(e.length===t)return;let s,d=$(e[t]),c=d.data("EasyCaptcha");if(c)r(e,t+1,a,i);else{c={},c.AUTO_INIT=i,s=$.extend(!0,{ReCAPTCHA_API_KEY_CLIENT:null,ReCaptchaSubmit:{success:()=>{},failed:()=>{},expired:()=>{}},autoVerification:{okBtn:null,requiredMsg:"
Please verify that you are not a robot.
"},apiScriptLoading:{loadingMsg:'
',error:()=>{},errorMsg:"
Error while loading Api Script. retry
"},theme:"light",failure:e=>{console.error(e)}},a);let p=$('meta[name="ReCAPTCHA_API_KEY_CLIENT"]');if(0!==p.length&&(s.ReCAPTCHA_API_KEY_CLIENT=p.attr("content")),l(d.attr("data-okbtn-selector"))&&(s.autoVerification.okBtn=d.attr("data-okbtn-selector")),l(d.attr("data-recaptcha-apikey"))&&(s.ReCAPTCHA_API_KEY_CLIENT=d.attr("data-recaptcha-apikey")),l(d.attr("data-required-msg-example-selector"))){let e=$(d.attr("data-required-msg-example-selector")).clone();e.removeClass("hidden"),e.removeClass("d-none"),s.autoVerification.requiredMsg=e}if(l(d.attr("data-loading-msg-example-selector"))){let e=$(d.attr("data-loading-msg-example-selector")).clone();e.removeClass("hidden"),e.removeClass("d-none"),s.apiScriptLoading.loadingMsg=e}if(l(d.attr("data-error-msg-example-selector"))){let e=$(d.attr("data-error-msg-example-selector")).clone();e.removeClass("hidden"),e.removeClass("d-none"),s.apiScriptLoading.errorMsg=e}l(d.attr("data-theme"))&&(s.theme=d.attr("data-theme")),c.settings=s,o(c,!1);let g=Math.floor(1e3*Math.random()+100);if(l(d.attr("id"))||d.attr("id",g+"_ReCaptchaTargetParent"),c.parentId=d.attr("id"),c.elementId=c.parentId+"__child",$('
').appendTo(d),$('
').appendTo(d),c.AUTO_INIT){$('').appendTo(d)}d.data("EasyCaptcha",c),n(c).then((function(){r(e,t+1,a,i)}),(function(e){s.failure(e??"Unknown error")}))}}async function n(e){await new Promise((function(t,a){!async function(e,t,a){const r="https://www.google.com/recaptcha/api.js?onload=EasyCaptchaScriptCallback&render=explicit";let i=$('script[src="'+r+'"]');if(0===i.length||"true"===i.attr("loaded")){0!==i.length&&i.remove();let s=$("#"+a.parentId).find(".alertsParent");s.empty(),$(a.settings.apiScriptLoading.loadingMsg).appendTo(s),window.EasyCaptchaScriptCallback=()=>{$('script[src="'+r+'"]').attr("loaded","true"),e(),s.empty()};let o=document.createElement("script");o.src=r,o.async=!0,o.defer=!0,o.onerror=function(){t("EasyCaptchaScript_FAILED"),s.empty();let e=$(a.settings.apiScriptLoading.errorMsg);e.appendTo(s),e.find(".retry-load-api-script").on("click",(function(){n(a)}))},$("head")[0].appendChild(o)}else e()}(t,a,e)})).then((function(){!function(e){let t;i=window.grecaptcha,"string"==typeof e.settings.theme?t=e.settings.theme:"function"==typeof e.settings.theme&&(t=e.settings.theme());"light"!==t&&"dark"!==t&&(t="light");e.widgetId=i.render(e.elementId,{sitekey:e.settings.ReCAPTCHA_API_KEY_CLIENT,callback:()=>function(e){e.settings.ReCaptchaSubmit.success(),o(e,!0),s(e,i.getResponse(e.widgetId))}(e),"expired-callback":()=>function(e){e.settings.ReCaptchaSubmit.expired(),o(e,!1),s(e,"")}(e),"error-callback":()=>function(e){e.settings.ReCaptchaSubmit.failed(),o(e,!1),s(e,"")}(e),theme:t})}(e)}),(function(t){e.settings.apiScriptLoading.error(t)}))}let i;function s(e,t){e.AUTO_INIT&&$("#"+e.parentId).find('[name="g-recaptcha-response"]').val(t)}function o(e,t){if(null!=e.settings.autoVerification.okBtn){let a=$(e.settings.autoVerification.okBtn);a.prop("disabled",!t),t?a.removeClass("disabled"):a.addClass("disabled")}}function l(e){return null!=e&&""!==e}return jQuery.fn.EasyCaptcha=a,$("[data-auto-easycaptcha]").EasyCaptcha(null),t})())); \ No newline at end of file +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.EasyCaptchaJS=t():e.EasyCaptchaJS=t()}(this,(()=>(()=>{"use strict";var e={d:(t,a)=>{for(var r in a)e.o(a,r)&&!e.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:a[r]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{EasyCaptcha:()=>a});const a=function(e={},...t){let a=null===e;if(null===e&&(e={}),0===$(this).length&&!a)throw"no ReCaptcha div parent.";let n=[];const s={getTarget:function(e,t,a){if(0!==a.length){if(a[0].startsWith("#")&&(a[0]=a[0].substring(1)),a[0]===t.parentId){let a={parentElement:$("#"+t.parentId),data:t};e.push(a)}}else{let a={parentElement:$("#"+t.parentId),data:t};e.push(a)}return e},verify:function(e,t,a){if(0!==a.length){if(a[0].startsWith("#")&&(a[0]=a[0].substring(1)),a[0]===t.parentId){let a={verified:""!==i.getResponse(t.widgetId)};e.push(a)}}else{let a={parentElement:$("#"+t.parentId),verified:""!==i.getResponse(t.widgetId)};e.push(a)}return e},response:function(e,t,a){if(0!==a.length){if(a[0].startsWith("#")&&(a[0]=a[0].substring(1)),a[0]===t.parentId){let a={token:i.getResponse(t.widgetId)};e.push(a)}}else{let a={parentElement:$("#"+t.parentId),token:i.getResponse(t.widgetId)};e.push(a)}return e},reset:function(e,t,a){return 0!==a.length?(a[0].startsWith("#")&&(a[0]=a[0].substring(1)),a[0]===t.parentId&&i.reset(t.widgetId)):i.reset(),e},destroy:function(e,t){for(let e=0;e<$(this).length;e++)$("#"+t.parentId).empty(),$($(this)[e]).removeData("EasyCaptcha");return e}};if("object"==typeof e)r($(this),0,e,a);else for(let a=0;a<$(this).length;a++){let r=$($(this)[a]).data("EasyCaptcha");r&&void 0!==s[e]&&(n=s[e](n,r,[...t]))}return n.length>1?n:0===n.length?null:n[0]};function r(e,t,a,i){if(e.length===t)return;let s,d=$(e[t]),c=d.data("EasyCaptcha");if(c)r(e,t+1,a,i);else{c={},c.AUTO_INIT=i,s=$.extend(!0,{ReCAPTCHA_API_KEY_CLIENT:null,ReCaptchaSubmit:{success:()=>{},failed:()=>{},expired:()=>{}},autoVerification:{okBtn:null,requiredMsg:"
Please verify that you are not a robot.
"},apiScriptLoading:{loadingMsg:'
',error:()=>{},errorMsg:"
Error while loading Api Script. retry
"},theme:"light",failure:e=>{console.error(e)}},a);let p=$('meta[name="ReCAPTCHA_API_KEY_CLIENT"]');if(0!==p.length&&(s.ReCAPTCHA_API_KEY_CLIENT=p.attr("content")),l(d.attr("data-okbtn-selector"))&&(s.autoVerification.okBtn=d.attr("data-okbtn-selector")),l(d.attr("data-recaptcha-apikey"))&&(s.ReCAPTCHA_API_KEY_CLIENT=d.attr("data-recaptcha-apikey")),l(d.attr("data-required-msg-example-selector"))){let e=$(d.attr("data-required-msg-example-selector")).clone();e.removeClass("hidden"),e.removeClass("d-none"),s.autoVerification.requiredMsg=e}if(l(d.attr("data-loading-msg-example-selector"))){let e=$(d.attr("data-loading-msg-example-selector")).clone();e.removeClass("hidden"),e.removeClass("d-none"),s.apiScriptLoading.loadingMsg=e}if(l(d.attr("data-error-msg-example-selector"))){let e=$(d.attr("data-error-msg-example-selector")).clone();e.removeClass("hidden"),e.removeClass("d-none"),s.apiScriptLoading.errorMsg=e}l(d.attr("data-theme"))&&(s.theme=d.attr("data-theme")),c.settings=s,o(c,!1);let g=Math.floor(1e3*Math.random()+100);if(l(d.attr("id"))||d.attr("id",g+"_ReCaptchaTargetParent"),c.parentId=d.attr("id"),c.elementId=c.parentId+"__child",$('
').appendTo(d),$('
').appendTo(d),c.AUTO_INIT){$('').appendTo(d)}d.data("EasyCaptcha",c),n(c).then((function(){r(e,t+1,a,i)}),(function(e){s.failure(e??"Unknown error")}))}}async function n(e){await new Promise((function(t,a){!async function(e,t,a){const r="https://www.google.com/recaptcha/api.js?onload=EasyCaptchaScriptCallback&render=explicit";let i=$('script[src="'+r+'"]');if(0===i.length||"true"===i.attr("loaded")){0!==i.length&&i.remove();let s=$("#"+a.parentId).find(".alertsParent");s.empty(),$(a.settings.apiScriptLoading.loadingMsg).appendTo(s),window.EasyCaptchaScriptCallback=()=>{$('script[src="'+r+'"]').attr("loaded","true"),e(),s.empty()};let o=document.createElement("script");o.src=r,o.async=!0,o.defer=!0,o.onerror=function(){t("EasyCaptchaScript_FAILED"),s.empty();let e=$(a.settings.apiScriptLoading.errorMsg);e.appendTo(s),e.find(".retry-load-api-script").on("click",(function(){n(a)}))},$("head")[0].appendChild(o)}else e()}(t,a,e)})).then((function(){!function(e){let t;i=window.grecaptcha,"string"==typeof e.settings.theme?t=e.settings.theme:"function"==typeof e.settings.theme&&(t=e.settings.theme());"light"!==t&&"dark"!==t&&(t="light");e.widgetId=i.render(e.elementId,{sitekey:e.settings.ReCAPTCHA_API_KEY_CLIENT,callback:()=>function(e){e.settings.ReCaptchaSubmit.success(),o(e,!0),s(e,i.getResponse(e.widgetId))}(e),"expired-callback":()=>function(e){e.settings.ReCaptchaSubmit.expired(),o(e,!1),s(e,"")}(e),"error-callback":()=>function(e){e.settings.ReCaptchaSubmit.failed(),o(e,!1),s(e,"")}(e),theme:t})}(e)}),(function(t){e.settings.apiScriptLoading.error(t)}))}let i;function s(e,t){e.AUTO_INIT&&$("#"+e.parentId).find('[name="g-recaptcha-response"]').val(t)}function o(e,t){if(null!=e.settings.autoVerification.okBtn){let a=$(e.settings.autoVerification.okBtn);a.prop("disabled",!t),t?a.removeClass("disabled"):a.addClass("disabled")}}function l(e){return null!=e&&""!==e}return jQuery.fn.EasyCaptcha=a,$("[data-auto-easycaptcha]").EasyCaptcha(null),t})())); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 9a344d3..b9c8370 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "easycaptchajs", - "version": "1.0.1", + "version": "1.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "easycaptchajs", - "version": "1.0.1", + "version": "1.1.0", "license": "MIT", "dependencies": { "jquery": "^3.7.0", diff --git a/package.json b/package.json index 4c7a3dc..25dba41 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "easycaptchajs", - "version": "1.0.1", + "version": "1.1.0", "description": "EasyCaptchaJS is a lightweight and user-friendly jQuery/JS library that simplifies the integration of Google reCAPTCHA API into web pages. With EasyCaptchaJS, developers can effortlessly add the security and anti-bot protection of Google reCAPTCHA to their applications. The library dynamically imports the Google reCAPTCHA API script, handles event bindings and listeners, and initiates the reCAPTCHA checkbox within a specified parent container. Developers can take advantage of powerful options, including customizable success/failure listeners, verification checks, and a getter function to access the reCAPTCHA secret code for further processing. Streamline your web application's security with EasyCaptchaJS and ensure a smooth user experience.", "main": "index.js", "scripts": { diff --git a/src/easycaptcha.js b/src/easycaptcha.js index a76fe04..fffe30a 100644 --- a/src/easycaptcha.js +++ b/src/easycaptcha.js @@ -8,6 +8,26 @@ export const EasyCaptcha = function (options = {}, ...args) { let results = []; const methods = { + 'getTarget': function (results, data, args) { + if (args.length !== 0) { + if (args[0].startsWith('#')) args[0] = args[0].substring(1); + if (args[0] === data.parentId) { + let res = { + parentElement: $("#" + data.parentId), + data: data + }; + results.push(res); + } + } + else{ + let res = { + parentElement: $("#" + data.parentId), + data: data + }; + results.push(res); + } + return results; + }, 'verify': function (results, data, args) { if (args.length !== 0) { if (args[0].startsWith('#')) args[0] = args[0].substring(1); diff --git a/webpack.config.js b/webpack.config.js index 83799bc..a8b4997 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -7,7 +7,7 @@ const webpack = require("webpack"); // noinspection JSUnresolvedReference let bannerPlugin = new webpack.BannerPlugin({ banner: `/*! - * EasyCaptchaJS v1.0.1 + * EasyCaptchaJS v1.1.0 * (c) HichemTech * Released under the MIT License. * Github: https://github.com/HichemTab-tech/EasyCaptchaJS