2019-01-28 17:32:07 +01:00

98 lines
2.3 KiB
JavaScript

$(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: "/dones",
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)}});
}
$(".test").click(function() {
movePurchases();
});
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");
movePurchases();
$(".determinate").css("width", "0%");
});
}
setInterval(updateProgress(), 500);
function updateProgress(percent) {
if(loading == true) {
$(".determinate").css("width", progress.progress * 100 + "%");
}
}
});
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%");
});
}
*/