diff --git a/express/asset/frontend.min.js b/express/asset/frontend.min.js new file mode 100644 index 0000000..25bc7ef --- /dev/null +++ b/express/asset/frontend.min.js @@ -0,0 +1 @@ +let sessionStartTime;let lastButtonClickTime;function generateSessionId(){return Math.random().toString(36).substring(2,15)+Math.random().toString(36).substring(2,15)}async function getNextAnimal(){try{const response=await fetch("/getNextAnimal");const data=await response.json();document.getElementById("animal-name").textContent=data.animalName}catch(error){console.error("Error fetching data:",error)}}function getSessionId(){const sessionId=document.cookie.replace(/(?:(?:^|.*;\s*)sessionId\s*=\s*([^;]*).*$)|^.*$/,"$1");if(!sessionId){const newSessionId=generateSessionId();document.cookie=`sessionId=${newSessionId}`;return newSessionId}return sessionId}function clearSessionId(){const newSessionId=generateSessionId();document.cookie=`sessionId=${newSessionId}`;setSessionStartTime();getSessionId()}function setSessionStartTime(){sessionStartTime=new Date}function displayTimeDifference(){if(sessionStartTime&&lastButtonClickTime){const timeDifference=lastButtonClickTime-sessionStartTime;console.log(`Time since session start: ${timeDifference} milliseconds`)}}document.getElementById("isCritterButton").addEventListener("click",()=>{recordButtonClick("is critter",getSessionId())});document.getElementById("isNotCritterButton").addEventListener("click",()=>{recordButtonClick("is not critter",getSessionId())});document.getElementById("startOverButton").addEventListener("click",()=>{clearSessionId();getNextAnimal()});async function recordButtonClick(buttonName,sessionId){try{const currentTime=new Date;if(lastButtonClickTime){const timeDifference=currentTime-lastButtonClickTime;const animal=document.getElementById("animal-name").textContent;const bodyData=JSON.stringify({animal:animal,button:buttonName,session:sessionId,difference:timeDifference,time:sessionStartTime});await fetch("/recordButtonClick",{method:"POST",headers:{"Content-Type":"application/json"},body:bodyData})}lastButtonClickTime=currentTime;displayTimeDifference();getNextAnimal()}catch(error){console.error("Error recording button click:",error)}}getNextAnimal();setSessionStartTime(); \ No newline at end of file diff --git a/express/package-lock.json b/express/package-lock.json index 142bbc6..531be4b 100644 --- a/express/package-lock.json +++ b/express/package-lock.json @@ -12,7 +12,8 @@ "body-parser": "^1.20.2", "express": "^4.18.2", "morgan": "^1.10.0", - "sqlite3": "^5.1.6" + "sqlite3": "^5.1.6", + "uglify-js": "^3.17.4" } }, "node_modules/@gar/promisify": { @@ -1716,6 +1717,17 @@ "node": ">= 0.6" } }, + "node_modules/uglify-js": { + "version": "3.17.4", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.17.4.tgz", + "integrity": "sha512-T9q82TJI9e/C1TAxYvfb16xO120tMVFZrGA3f9/P4424DNu6ypK103y0GPFVa17yotwSyZW5iYXgjYHkGrJW/g==", + "bin": { + "uglifyjs": "bin/uglifyjs" + }, + "engines": { + "node": ">=0.8.0" + } + }, "node_modules/unique-filename": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-1.1.1.tgz", diff --git a/express/package.json b/express/package.json index d1f369b..a15ab4d 100644 --- a/express/package.json +++ b/express/package.json @@ -17,6 +17,7 @@ "body-parser": "^1.20.2", "express": "^4.18.2", "morgan": "^1.10.0", - "sqlite3": "^5.1.6" + "sqlite3": "^5.1.6", + "uglify-js": "^3.17.4" } }