Created
March 25, 2024 13:13
-
-
Save guaracyalima/cb7a745508c8678d874870cde95c540b to your computer and use it in GitHub Desktop.
Ticto data capture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getFn() { | |
var _nome = document.getElementById("customer.name").value; | |
var name = _nome.substring(0, _nome.indexOf(" ")); | |
if (_nome.includes(" ")) { | |
name = _nome.substring(0, _nome.indexOf(" ")); | |
} else { | |
name = _nome; | |
} | |
name = name.toLowerCase(); | |
name = name.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); | |
return name; | |
} | |
getFn(); | |
function getLn() { | |
var _nome = document.getElementById("customer.name").value; | |
var lastnm; | |
if (_nome.includes(" ")) { | |
var nm = _nome.substring(0, _nome.indexOf(" ")); | |
lastnm = _nome.substring(nm.length, _nome.length); | |
lastnm = lastnm.replace(" ", ""); | |
} else { | |
return lastnm; | |
} | |
lastnm = lastnm.replace(/ /g, ""); | |
lastnm = lastnm.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); | |
lastnm = lastnm.toLowerCase(); | |
return lastnm; | |
} | |
getLn(); | |
function getPh() { | |
var phone = document.querySelector("input[type='tel']").value; | |
if (phone) { | |
phone = phone.replace("-", ""); | |
phone = phone.replace("(", ""); | |
phone = phone.replace(")", ""); | |
phone = phone.replace(" ", ""); | |
phone = phone.replace("+", ""); | |
phone = "55" + phone; | |
} | |
return phone; | |
} | |
getPh(); | |
function getEmail() { | |
return document.getElementById("customer.email").value; | |
} | |
getEmail(); | |
function getGender() { | |
var _nome = document.getElementById("customer.name").value; | |
var name = _nome.substring(0, _nome.indexOf(" ")); | |
if (_nome.includes(" ")) { | |
name = _nome.substring(0, _nome.indexOf(" ")); | |
} else { | |
name = _nome; | |
} | |
if (_nome) { | |
var cleanedName = _nome | |
.normalize("NFD") | |
.replace(/[\u0300-\u036f]/g, "") | |
.replace(/[^a-zA-ZÀ-ÿ ]/g, ""); | |
var firstName = cleanedName.split(" ")[0]; | |
var xhr = new XMLHttpRequest(); | |
var url = "https://api.genderize.io?name=" + encodeURIComponent(firstName); | |
xhr.open("GET", url, false); | |
xhr.send(); | |
if (xhr.readyState === 4 && xhr.status === 200) { | |
var response = JSON.parse(xhr.responseText); | |
var gender = response.gender; | |
if (gender === "male") { | |
return "62c66a7a5dd70c3146618063c344e531e6d4b59e379808443ce962b3abd63c5a"; | |
} else if (gender === "female") { | |
return "252f10c83610ebca1a059c0bae8255eba2f95be4d1d7bcfa89d7248a82d9f111"; | |
} | |
} | |
} | |
} | |
getGender(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment