';}
document.getElementById('results').innerHTML=outputs;removeLoader('.main #submit');isProcessing=false;}catch(error){console.error(error);removeLoader('.main #submit');isProcessing=false;}}
function ai(prompt){return new Promise((resolve,reject)=>{fetch("/ai",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({prompt})}).then(response=>response.json()).then(data=>{let taskStatus="PENDING";const{task_id}=data;const interval=setInterval(()=>{fetch(`/task_status/${task_id}`).then(response=>response.json()).then(statusData=>{taskStatus=statusData.state;if(taskStatus!=="PENDING"){clearInterval(interval);if(taskStatus==="SUCCESS"){const result=statusData.result;resolve(result);}else{reject(new Error(`Task failed with status ${taskStatus}`));}}}).catch(error=>{clearInterval(interval);reject(error);});},1000);}).catch(error=>{reject(error);});});}
$('#passwordless').submit(function(e){e.preventDefault();var email=$('#passwordless input[name="email"]').val();loader('#passwordless button');if(email.indexOf('@')==-1||email.indexOf('.')==-1){trayAlert('Please enter a valid email address.');removeLoader('#passwordless button');return;}
$.ajax({url:"/passwordless",method:"POST",data:{email:email},success:function(data){if(data.status=='success'){$('#passwordless').hide();$('.form-flash').html('Click the link in your email to login.');$('.form-flash').addClass('preauth');}else{formFlash(data.error,'error');}
removeLoader('#passwordless button');}});});function formFlash(message,type){var formFlashElement=$('.form-flash');formFlashElement.addClass(type);formFlashElement.html(message);formFlashElement.show();setTimeout(function(){formFlashElement.fadeOut(400,function(){formFlashElement.removeClass(type);});},2500);}
function logout(){$.ajax({url:"/logout",method:"POST",success:function(data){getUser();}});};function closeModal(){var modal=document.getElementById("loginModal");modal.style.display="none";$('.form-flash').html('');$('#passwordless').show();$('.form-flash').removeClass('preauth');}
function loginModal(){var modal=document.getElementById("loginModal");modal.style.display="block";window.onclick=function(event){if(event.target==modal){modal.style.display="none";$('.form-flash').html('');$('#passwordless').show();$('.form-flash').removeClass('preauth');}}}
function search(){$('.faves-container').html('');$('.favorites').hide();$('.search').show();$('.results').html('');}
function getUser(){return fetch('/get-user').then(response=>response.json()).then(user=>{if(user.email){window.user.logged_in=user.logged_in;window.user.verified=user.verified;$('.account').hide();$('.logout').show();$('.showfaves').show();$('.search-nav').show();}else{window.user.logged_in=false;window.user.verified=false;$('.account').show();$('.logout').hide();$('.showfaves').hide();$('.search-nav').hide();$('.favorites').hide();$('.search').show();$('.results').html('');}});}
function trayAlert(message){var trayAlert=$('#trayAlert');trayAlert.html(message);trayAlert.addClass('show');setTimeout(function(){trayAlert.removeClass('show');},2500);}
function showFaves(){$('.search').hide();$('.favorites').show();loader('.faves-container');$.ajax({url:"/get-favorites",method:"get",success:function(data){var html='';var favorites=data.favorites;if(favorites.length==0){html+='