$(document).ready(function() { //initialize all modals $('.modal').modal(); $('.materialboxed').materialbox(); $(".btnanalyze").click(function() { analyzeUploaded(); }); //AJAX // Initialize Firebase var config = { apiKey: "AIzaSyCuvwf78cmSDoZ2yS4XxHZhnjUn7yIHYfw", authDomain: "test-667ca.firebaseapp.com", databaseURL: "https://test-667ca.firebaseio.com", projectId: "test-667ca", storageBucket: "test-667ca.appspot.com", messagingSenderId: "221332577314" }; firebase.initializeApp(config); function movePurchases() { firebase.auth().onAuthStateChanged(function(user){if(user){firebase.auth().currentUser.getIdToken(/* forceRefresh */ true).then(function(idtoken) { $.ajax({ type: "POST", url: "/donepurchases", data:{ idtoken: idtoken, sl_id: "BplQ5lFU", billcontent: "fsfs" }, success(result){ console.log(result); }, error(err){ console.error("Error: " + err); } }); }).catch((error) => console.error("Get id token client error: ", error));}else{console.log("Check Auth error", user)}}); } }); var loading = false; function analyze() { var img = document.getElementById("canvas").toDataURL(); Tesseract.recognize(img).progress((progress) => { if (progress.status == "recognizing text") { loading = true; } }).then((result) => { loading = false; $(".output").text(result.text); $('.modal').modal("open"); $(".determinate").css("width", "0%"); }); } function analyzeUploaded() { var img = document.getElementById("blah"); Tesseract.recognize(img).progress((progress) => { if (progress.status == "recognizing text") { loading = true; } }).then((result) => { loading = false; $(".output").text(result.text); $('#modal1').modal("open"); $(".determinate").css("width", "0%"); }); } setInterval(updateProgress(), 500); function updateProgress(percent) { if(loading == true) { $(".determinate").css("width", progress.progress * 100 + "%"); } } $(".test").click(function() { movePurchases(); })