const ua = window.navigator.userAgent; const isIE = ua.indexOf("MSIE ") > -1 || ua.indexOf("Trident/") > -1; function changeVisiblePassword() { let input = document.getElementById('password'); let eye = document.getElementById('eye'); if (input.type == 'text') { input.type = 'password'; eye.src = 'img/eye.png'; } else { input.type = 'text'; eye.src = 'img/eye_not.png'; } } // Funcao para buscar o audio function play() { let id = document.querySelector('#idCaptcha').value; let xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { let t = 500; let json = ''; if(isIE){ json = JSON.parse(this.responseText); } else { json = this.response; } disableControlers(); for (i in json.base64) { t += 1500; setTimeout( function(index) { return function() { new Audio("data:audio/mpeg;base64," + json.base64[index]).play(); if(index == json.base64.length-1){ enableControlers(); } } }(i), t); } } }; xhttp.open("GET", 'captcha?id=' + id, true); xhttp.responseType = 'json'; xhttp.send(); } function getCaptcha() { let xhttp = new XMLHttpRequest(); disableControlers(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { let json = ''; if(isIE){ json = JSON.parse(this.responseText); } else { json = this.response; } console.log(isIE, json); document.getElementById("captcha").src = 'data:image/png;base64,' + json.base64; document.getElementById("idCaptcha").value = json.id; enableControlers(); } }; xhttp.open("GET", 'captcha', true); xhttp.responseType = 'json'; xhttp.send(); } function disableControlers(){ let p = document.querySelector("#p"); let r = document.querySelector("#r"); // disable play button p.onclick = function() {return false;} p.src='img/play-disabled.png'; //disable renew button r.onclick = function() {return false;} r.src='img/renew-disabled.png'; } function enableControlers(){ let p = document.querySelector("#p"); let r = document.querySelector("#r"); // disable play button p.onclick = play; p.src='img/play.png'; //disable renew button r.onclick = getCaptcha; r.src='img/renew.png'; }