diff --git a/index.js b/index.js index e25ba82..94950c0 100644 --- a/index.js +++ b/index.js @@ -2,13 +2,7 @@ var tokenCaptcha; var scriptCaptcha = document.createElement('script'); scriptCaptcha.setAttribute('src', `https://www.google.com/recaptcha/api.js?render=6LcCMl4qAAAAAMLgG-uhh5lRFswvMEDzIlxG1IOC`) -document.head.appendChild(scriptCaptcha); -grecaptcha.ready(function() { - grecaptcha.execute('6LcCMl4qAAAAAMLgG-uhh5lRFswvMEDzIlxG1IOC', {action: 'submit'}).then(function(token) { - tokenCaptcha = token; - }); - }); -console.log(tokenCaptcha); + //Setup uuid as device_key var localKeyId = localStorage.getItem('deviceId'); @@ -172,29 +166,51 @@ if (null != appendingNode) { null != t[0].value && null != t[1].value && n.push(`${t[0].value}${t[1].value}`); }), n.length > 0 && (n = n.join(",")), - document.querySelector("#gdprConsentAds-input").checked ? t = 1 : t = 0; + document.querySelector("#gdprConsentAds-input").checked ? t = 1 : t = 0; + scriptCaptcha.innerHTML = ` + grecaptcha.ready(function() { + grecaptcha.execute('6LcCMl4qAAAAAMLgG-uhh5lRFswvMEDzIlxG1IOC',{action:'submit'}).then(function(token) { + // Append the reCAPTCHA token to the form data + data['TOKEN'] = token; + data['SOURCE'] = '${a}' + data['PLATFORM'] = '${c}' + data['SUB'] = ${t} + data['EMAIL'] = ${e} + data['PHONE'] = '${n}' + data['LAST-NAME'] = '${document.querySelector("input[id$='PersonalInfolastName']").value}' + data['FIRST-NAME'] = '${document.querySelector("input[id$='PersonalInfofirstName']").value}' + // Send the data to your API using fetch (or you can use axios) + var xhr = new XMLHttpRequest(); + xhr.open("POST", "https://mssf.vietnamairlines.com:9001/consent-refx", true); + xhr.setRequestHeader("Content-Type", "application/json"); + + xhr.send(JSON.stringify(data)); + }) + }); + `; + document.head.appendChild(scriptCaptcha); // var token = await fetch('https://www.google.com/recaptcha/api.js?render=6LcCMl4qAAAAAMLgG-uhh5lRFswvMEDzIlxG1IOC'); - await fetch("https://mssf.vietnamairlines.com:4443/api/v1.0/consent", { - method: "POST", - headers: { - "Content-Type": "application/json", - Authorization: "Bearer bc3e3afb-f4ec-31ae-9570-f961b2f1fe75" - }, - body: JSON.stringify({ - SOURCE: a, - PLATFORM: c, - SUB: t, - EMAIL: e, - PHONE: n, - "LAST-NAME": document.querySelector("input[id$='PersonalInfolastName']").value, - "FIRST-NAME": document.querySelector("input[id$='PersonalInfofirstName']").value, - VENDOR: "GMS", - LANGUAGE: len, - COUNTRY: countryCode, - "DEVICE-ID": localKeyId, - "GA-ID": gaGlobal ? gaGlobal.vid : '', - token: token - }), - }); + // await fetch("https://mssf.vietnamairlines.com:4443/api/v1.0/consent", { + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // Authorization: "Bearer bc3e3afb-f4ec-31ae-9570-f961b2f1fe75" + // }, + // body: JSON.stringify({ + // SOURCE: a, + // PLATFORM: c, + // SUB: t, + // EMAIL: e, + // PHONE: n, + // "LAST-NAME": document.querySelector("input[id$='PersonalInfolastName']").value, + // "FIRST-NAME": document.querySelector("input[id$='PersonalInfofirstName']").value, + // VENDOR: "GMS", + // LANGUAGE: len, + // COUNTRY: countryCode, + // "DEVICE-ID": localKeyId, + // "GA-ID": gaGlobal ? gaGlobal.vid : '', + // token: token + // }), + // }); }); }