is-critter/express/asset/frontend.min.js

2 lines
1.3 KiB
JavaScript
Raw Normal View History

let a;let b;function c(){return (Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15))}async function d(){try {var A=await fetch('/getNextAnimal');var _=await A.json();document.getElementById('animal-name').textContent=_.animalName} catch (B) {console.error('Error fetching data:',B)}}function e(){var A=document.cookie.replace(/(?:(?:^|.*;\s*)sessionId\s*=\s*([^;]*).*$)|^.*$/,'$1');if(!A){var _=c();document.cookie=`sessionId=${_}`;return _}return A}function f(){var A=c();document.cookie=`sessionId=${A}`;g();e()}function g(){a=new Date()}function h(){if(a&&b){var A=b-a;console.log(`Time since session start: ${A} milliseconds`)}}document.getElementById('isCritterButton').addEventListener('click',()=>i('is critter',e()));document.getElementById('isNotCritterButton').addEventListener('click',()=>i('is not critter',e()));document.getElementById('startOverButton').addEventListener('click',()=>{f();d()});async function i(A,_){try {var B=new Date();if(b){var C=B-b,_b=document.getElementById('animal-name').textContent,_c=JSON.stringify({animal:_b,button:A,session:_,difference:C,time:a});await fetch('/recordButtonClick',{method:'POST',headers:{'Content-Type':'application/json'},body:_c})}b=B;h();d()} catch (_a) {console.error('Error recording button click:',_a)}}d();g();