-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thomas-Aptitude-Test.min.js
1 lines (1 loc) · 7.92 KB
/
Thomas-Aptitude-Test.min.js
1
function promptForApiKey(){globalThis.apiKey||(globalThis.apiKey=prompt("Please enter your OpenAI API key:"))}function commonRunOrExit(){console.log("Script will answer the next question automatically. Type exit() to exit the script.")}function exit(){console.log("Stopping the script.\nTo start the script again select a question\ntype 'question1()' for Question 1 - Reasoning\ntype 'question2()' for Question 2 - Perceptual Speed\ntype 'question3()' for Question 3 - Number Speed and Accuracy\ntype 'question4()' for Question 4 - Word Meaning\ntype 'question5()' for Question 5 - Spacial Visualisation"),globalThis.shouldExit=!0}function runWhenChanges(e,t){for(const o of e)if("childList"===o.type||"characterData"===o.type||"subtree"===o.type)return t.disconnect(),void run()}function question1(){globalThis.shouldExit=!1,console.log("Question 1 (Reasoning) selected. \nWhen you're ready type run() to run the script, or type exit() to exit.");let r=new MutationObserver(globalThis.runWhenChanges);globalThis.apiKey||promptForApiKey(),globalThis.run=function(){globalThis.shouldExit||(globalThis.questionStatement=document.getElementById("vrStatement").textContent,new MutationObserver((e,t)=>{for(const o of e)"childList"===o.type&&document.getElementById("vrQuestion")&&(t.disconnect(),function(){var e=document.getElementById("vrQuestion").textContent,t=document.querySelectorAll("button.answerButton");let o=[];t.forEach(e=>{o.push(e.textContent.trim())}),console.log(globalThis.questionStatement),console.log(e),console.log(o.join(" or "));let n;fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer "+globalThis.apiKey},body:JSON.stringify({model:"gpt-3.5-turbo",messages:[{role:"user",content:`Based on: "${globalThis.questionStatement}", answer: "${e}". Options: ${o.join(" or ")}. Reply with a single word from the options.`}]})}).then(e=>e.json()).then(({choices:e})=>{e&&0<e.length&&e[0].message?(console.log(e[0].message.content),n=e[0].message.content,document.querySelectorAll(".answerButton").forEach(e=>{var t;e.textContent.trim()===n&&(t={attributes:!1,childList:!0,subtree:!0},r.observe(document.body,t),e.click(),console.log(`Selected answer: '${n}'`))})):console.error("Unexpected response:",e)}).catch(e=>console.error("Error:",e)),commonRunOrExit()}())}).observe(document.body,{attributes:!1,childList:!0,subtree:!0}),document.body.click())}}function question2(){globalThis.shouldExit=!1,console.log("Question 2 (Perceptual Speed) selected.\nWhen you're ready type run() to run the script, or type exit() to exit.");let i=new MutationObserver(globalThis.runWhenChanges);function e(){if(!globalThis.shouldExit){i.disconnect();let t=[],o=[],n=0;var e=document.querySelectorAll("#psLettersFirstRow .psLabel"),r=document.querySelectorAll("#psLettersSecondRow .psLabel");e.forEach(e=>{t.push(e.textContent)}),r.forEach(e=>{o.push(e.textContent)});for(let e=0;e<t.length;e++)t[e].toLowerCase()===o[e].toLowerCase()&&n++;console.log("Number of matching letters: "+n),document.querySelectorAll(".answerButton").forEach(e=>{var t;e.textContent.trim()===n.toString()&&(t={attributes:!1,childList:!0,subtree:!0},i.observe(document.body,t),e.click(),console.log(`Clicked the button with text '${n}'`))}),commonRunOrExit()}}globalThis.run=e}function question3(){globalThis.shouldExit=!1,console.log("Question 3 (Number Speed and Accuracy) selected.\nWhen you're ready type run() to run the script.\nThis script will answer each question automatically, type exit() to exit the script.");let a=new MutationObserver(function(e,t){for(const o of e)if("childList"===o.type||"characterData"===o.type||"subtree"===o.type){let t=[];if(document.querySelectorAll(".answerButton").forEach(e=>{e=parseInt(e.textContent.trim(),10);isNaN(e)||t.push(e)}),3===t.length)return a.disconnect(),void n()}});function n(){if(!globalThis.shouldExit){a.disconnect();let t=[];var e,o,n,r,i,s=document.querySelectorAll(".answerButton");s.forEach(e=>{e=parseInt(e.textContent.trim(),10);isNaN(e)||t.push(e)});e=t[0],o=t[1],n=t[2],r=Math.max(e,Math.max(o,n)),i=Math.min(e,Math.min(o,n)),e=e+o+n-r-i,o=Math.abs(r-e),n=Math.abs(i-e);const l=[r,i,e=n<o?r:i];console.log("Farthest from middle:",l[2]),document.querySelectorAll(".answerButton").forEach(e=>{e.textContent.trim()===l[2].toString()&&(e.click(),console.log(`Clicked the button: '${l[2]}'`))}),s.forEach(e=>{a.observe(e,{childList:!0,characterData:!0,subtree:!0})})}}globalThis.run=n,commonRunOrExit()}function question4(){globalThis.shouldExit=!1,console.log("Question 4 selected.\nWhen you're ready type run() to run the script.\nThis script will answer each question automatically, type exit() to exit the script."),globalThis.apiKey||promptForApiKey();let n=new MutationObserver(function(e,t){for(const o of e)if("childList"===o.type||"characterData"===o.type)if(3===Array.from(document.querySelectorAll("button.answerButton")).map(e=>e.textContent||e.innerText).filter(e=>e&&""!==e.trim()&&"..."!==e).length)return t.disconnect(),void r()});function r(){if(!globalThis.shouldExit){n.disconnect();var e=Array.from(document.querySelectorAll("button.answerButton")).filter(e=>"1"===window.getComputedStyle(e).getPropertyValue("opacity")).map(e=>e.textContent||e.innerText),o=e.join(","),e=e.join(" or ");let t;fetch("https://api.openai.com/v1/chat/completions",{method:"POST",headers:{"Content-Type":"application/json",Authorization:"Bearer "+globalThis.apiKey},body:JSON.stringify({model:"gpt-3.5-turbo",messages:[{role:"user",content:`Given a set of three words, two words will have the same meaning or opposite meanings. Identify the word that doesn't fit the pattern. For the words "${o}", which is the odd one out? Options: ${e}. Reply with a single word from the options.`}]})}).then(e=>e.json()).then(({choices:e})=>{e&&0<e.length&&e[0].message?(console.log(e[0].message.content),t=e[0].message.content,document.querySelectorAll(".answerButton").forEach(e=>{e.textContent.trim()===t&&(e.click(),console.log(`Selected answer: '${t}'`),0<(e=document.querySelectorAll(".answerButton")).length)&&n.observe(e[0],{childList:!0,characterData:!0,subtree:!0})})):console.error("Unexpected response:",e)}).catch(e=>console.error("Error:",e)),commonRunOrExit()}}globalThis.run=r}function question5(){globalThis.shouldExit=!1,console.log("Question 5 (Spatial Visualisation) selected.\nWhen you're ready type run() to run the script.\nThis script will answer each question automatically, type exit() to exit the script.");let n=new MutationObserver(function(e,t){for(const o of e)if("childList"===o.type||"characterData"===o.type||"attributes"===o.type)if(2===Array.from(document.querySelectorAll(".pairBox")).map(e=>e.textContent||e.innerText).filter(e=>e&&""!==e.trim()&&"..."!==e).length)return t.disconnect(),void i()});function r(t,o){for(let e=0;e<4;++e){if(function(e,o){return e.every((e,t)=>Math.abs(e-o[t])<1e-9)}(t.slice(0,4),o.slice(0,4)))return 1;t=function(e){var[e,t,o,n]=e;return[-t,e,-n,o]}(t)}}function i(){if(!globalThis.shouldExit){n.disconnect();let t=0;var o=["svLeftPairTop","svLeftPairBottom","svRightPairTop","svRightPairBottom"].map(e=>{var e=window.getComputedStyle(document.querySelector("div#"+e)).getPropertyValue("transform");return(e=e)?Array.from(e.match(/-?\d+\.?\d*/g),Number):[1,0,0,1,0,0]});for(let e=0;e<o.length;e+=2)r(o[e],o[e+1])&&t++;console.log("Number of matching pairs:",t),document.querySelectorAll(".answerButton").forEach(e=>{e.textContent.trim()===t.toString()&&(e.click(),console.log(`Selected answer: '${t}'`),document.querySelectorAll(".pairBox").forEach(e=>{n.observe(e,{childList:!0,characterData:!0,subtree:!0})}))}),commonRunOrExit()}}globalThis.run=i}globalThis.shouldExit=!1,promptForApiKey(),console.log("Type the question number to select or change question\ntype 'question1()' for Question 1 - Reasoning\ntype 'question2()' for Question 2 - Perceptual Speed\ntype 'question3()' for Question 3 - Number Speed and Accuracy\ntype 'question4()' for Question 4 - Word Meaning\ntype 'question5()' for Question 5 - Spacial Visualisation");