-
Notifications
You must be signed in to change notification settings - Fork 0
/
Thomas-Aptitude-Test.js
380 lines (378 loc) · 16.3 KB
/
Thomas-Aptitude-Test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
globalThis.shouldExit = false;
function promptForApiKey() {
if (!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.' + "\n" + "To start the script again select a question"
+ "\n" + "type 'question1()' for Question 1 - Reasoning"
+ "\n" + "type 'question2()' for Question 2 - Perceptual Speed"
+ "\n" + "type 'question3()' for Question 3 - Number Speed and Accuracy"
+ "\n" + "type 'question4()' for Question 4 - Word Meaning"
+ "\n" + "type 'question5()' for Question 5 - Spacial Visualisation");
globalThis.shouldExit = true;
}
function runWhenChanges(mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList' || mutation.type === 'characterData' || mutation.type === 'subtree') {
observer.disconnect();
run();
return;
}
}
}
function question1() {
globalThis.shouldExit = false;
console.log("Question 1 (Reasoning) selected. " + "\n" +
"When you're ready type run() to run the script, or type exit() to exit.");
let nextQuestionObserver = new MutationObserver(runWhenChanges);
if (!globalThis.apiKey) {
promptForApiKey();
}
function run() {
if (globalThis.shouldExit) {
return;
}
globalThis.questionStatement = document.getElementById("vrStatement").textContent;
const observer = new MutationObserver((mutationsList, observer) => {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
const vrQuestionElement = document.getElementById("vrQuestion");
if (vrQuestionElement) {
observer.disconnect()
question();
}
}
}
});
const config = { attributes: false, childList: true, subtree: true };
observer.observe(document.body, config);
document.body.click()
}
function runWhenChanges(mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
const vrStatementElement = document.getElementById("vrStatement");
if (vrStatementElement) {
observer.disconnect()
run();
return
}
}
}
}
function question() {
const questionSecondStatements = document.getElementById("vrQuestion").textContent;
const answerButtons = document.querySelectorAll("button.answerButton");
let answerOptions = [];
answerButtons.forEach(button => {
answerOptions.push(button.textContent.trim());
});
console.log(globalThis.questionStatement);
console.log(questionSecondStatements);
console.log(answerOptions.join(' or '));
if (answerOptions.length){
}
let answer;
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: `This is a reasoning question. Given the statement: "${globalThis.questionStatement}", please answer the following reasoning question: "${questionSecondStatements}". Your response should be a single word response.`
}]
})
})
.then(response => response.json())
.then(({choices}) => {
if (choices && choices.length > 0 && choices[0].message) {
console.log(choices[0].message.content);
answer = choices[0].message.content;
const buttons = document.querySelectorAll(".answerButton");
buttons.forEach(button => {
if(answer.includes(button.textContent.trim())) {
button.click();
console.log(`Selected answer: '${answer}'`);
const config = { attributes: false, childList: true, subtree: true };
nextQuestionObserver.observe(document.body, config);
}
});
} else {
console.error('Unexpected response:', choices);
}
})
.catch(error => console.error('Error:', error));
commonRunOrExit();
}
globalThis.run = run;
}
function question2() {
globalThis.shouldExit = false;
console.log("Question 2 (Perceptual Speed) selected." + "\n" + "When you're ready type run() to run the script, or type exit() to exit.");
let nextQuestionObserver = new MutationObserver(globalThis.runWhenChanges);
function runWhenChanges(mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList' || mutation.type === 'characterData' || mutation.type === 'subtree') {
run();
}
}
}
function run() {
if (globalThis.shouldExit) {
return;
}
nextQuestionObserver.disconnect();
let row1 = [];
let row2 = [];
let counter= 0;
const row1psLabelElements = document.querySelectorAll("#psLettersFirstRow .psLabel");
const row2psLabelElements = document.querySelectorAll("#psLettersSecondRow .psLabel");
row1psLabelElements.forEach(element => {
row1.push(element.textContent);
});
row2psLabelElements.forEach(element => {
row2.push(element.textContent);
});
for(let i = 0; i < row1.length; i++) {
if(row1[i].toLowerCase() === row2[i].toLowerCase()) {
counter++;
}
}
console.log("Number of matching letters: " + counter);
const buttons = document.querySelectorAll(".answerButton");
buttons.forEach(button => {
if(button.textContent.trim() === counter.toString()) {
const config = { attributes: false, childList: true, subtree: true };
nextQuestionObserver.observe(document.body, config);
button.click();
console.log(`Clicked the button with text '${counter}'`);
}
});
commonRunOrExit();
}
globalThis.run = run;
}
function question3() {
globalThis.shouldExit = false;
console.log("Question 3 (Number Speed and Accuracy) selected."
+ "\n" + "When you're ready type run() to run the script."
+ "\n" + "This script will answer each question automatically, type exit() to exit the script.");
let nextQuestionObserver = new MutationObserver(runWhenButtonChanges);
function runWhenButtonChanges(mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList' || mutation.type === 'characterData' || mutation.type === 'subtree') {
let numbersArray = [];
const answerButtons = document.querySelectorAll(".answerButton");
answerButtons.forEach(button => {
const number = parseInt(button.textContent.trim(), 10);
if (!isNaN(number)) {
numbersArray.push(number);
}
});
if (numbersArray.length === 3){
nextQuestionObserver.disconnect();
run();
return;
}
}
}
}
function run() {
if (globalThis.shouldExit) {
return;
}
nextQuestionObserver.disconnect();
let numbersArray = [];
const answerButtons = document.querySelectorAll(".answerButton");
answerButtons.forEach(button => {
const number = parseInt(button.textContent.trim(), 10);
if (!isNaN(number)) {
numbersArray.push(number);
}
});
const extremes = findExtremes(numbersArray[0], numbersArray[1], numbersArray[2]);
console.log("Farthest from middle:", extremes[2]);
const buttons = document.querySelectorAll(".answerButton");
buttons.forEach(button => {
if (button.textContent.trim() === extremes[2].toString()) {
button.click();
console.log(`Clicked the button: '${extremes[2]}'`);
}
});
answerButtons.forEach(button => {
nextQuestionObserver.observe(button, { childList: true, characterData: true, subtree: true });
});
}
function findExtremes(num1, num2, num3) {
const largest = Math.max(num1, Math.max(num2, num3));
const smallest = Math.min(num1, Math.min(num2, num3));
const middle = num1 + num2 + num3 - largest - smallest;
const distanceFromMiddle1 = Math.abs(largest - middle);
const distanceFromMiddle2 = Math.abs(smallest - middle);
const farthestFromMiddle = distanceFromMiddle1 > distanceFromMiddle2 ? largest : smallest;
return [largest, smallest, farthestFromMiddle];
}
globalThis.run = run;
commonRunOrExit();
}
function question4() {
globalThis.shouldExit = false;
console.log("Question 4 selected." + "\n" + "When you're ready type run() to run the script."
+ "\n" + "This script will answer each question automatically, type exit() to exit the script.");
if (!globalThis.apiKey) {
promptForApiKey();
}
let nextQuestionObserver = new MutationObserver(runWhenButtonChanges);
function runWhenButtonChanges(mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList' || mutation.type === 'characterData') {
const buttonTexts = Array.from(document.querySelectorAll('button.answerButton'))
.map(element => element.textContent || element.innerText)
.filter(text => text && text.trim() !== '' && text !== '...');
if (buttonTexts.length === 3) {
observer.disconnect();
run();
return;
}
}
}
}
function run() {
if (globalThis.shouldExit) {
return;
}
nextQuestionObserver.disconnect();
var texts = Array.from(document.querySelectorAll('button.answerButton'))
.filter(element => window.getComputedStyle(element).getPropertyValue('opacity') === '1')
.map(element => element.textContent || element.innerText);
var textToSend = texts.join(',');
var options = texts.join(' or ');
let answer;
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 "${textToSend}", which is the odd one out? Options: ${options}. Reply with a single word from the options.`
}]
})
})
.then(response => response.json())
.then(({choices}) => {
if (choices && choices.length > 0 && choices[0].message) {
console.log(choices[0].message.content);
answer = choices[0].message.content;
const buttons = document.querySelectorAll(".answerButton");
buttons.forEach(button => {
if(button.textContent.trim() === answer) {
button.click();
console.log(`Selected answer: '${answer}'`);
const answerButtons = document.querySelectorAll(".answerButton");
if (answerButtons.length > 0) {
nextQuestionObserver.observe(answerButtons[0], { childList: true, characterData: true, subtree: true });
}
}
});
} else {
console.error('Unexpected response:', choices);
}
})
.catch(error => console.error('Error:', error));
commonRunOrExit();
}
globalThis.run = run;
}
function question5() {
globalThis.shouldExit = false;
console.log("Question 5 (Spatial Visualisation) selected." + "\n" + "When you're ready type run() to run the script."
+ "\n" + "This script will answer each question automatically, type exit() to exit the script.");
let nextQuestionObserver = new MutationObserver(runWhenStyleChanges);
function runWhenStyleChanges(mutationsList, observer) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList' || mutation.type === 'characterData' || mutation.type === 'attributes') {
const pairBoxTexts = Array.from(document.querySelectorAll('.pairBox'))
.map(element => element.textContent || element.innerText)
.filter(text => text && text.trim() !== '' && text !== '...');
if (pairBoxTexts.length === 2) {
observer.disconnect();
run();
return;
}
}
}
}
function rotate90(matrix) {
const [a, c, b, d] = matrix;
return [-c, a, -d, b];
}
function isRotationEquivalent(matrix1, matrix2) {
for (let i = 0; i < 4; ++i) {
if (matricesEqual(matrix1.slice(0, 4), matrix2.slice(0, 4))) {
return true;
}
matrix1 = rotate90(matrix1);
}
return false;
}
function matricesEqual(m1, m2) {
return m1.every((value, index) => Math.abs(value - m2[index]) < 1e-9);
}
function run() {
if (globalThis.shouldExit) {
return;
}
nextQuestionObserver.disconnect();
function convertScaleToMatrix(transform) {
if (!transform) return [1, 0, 0, 1, 0, 0];
return Array.from(transform.match(/-?\d+\.?\d*/g), Number);
}
let counter = 0;
const ids = ['svLeftPairTop', 'svLeftPairBottom', 'svRightPairTop', 'svRightPairBottom'];
const matrices = ids.map(id => {
const transform = window.getComputedStyle(document.querySelector(`div#${id}`)).getPropertyValue('transform');
return convertScaleToMatrix(transform);
});
for (let i = 0; i < matrices.length; i += 2) {
if (isRotationEquivalent(matrices[i], matrices[i + 1])) {
counter++;
}
}
console.log('Number of matching pairs:', counter);
const buttons = document.querySelectorAll(".answerButton");
buttons.forEach(button => {
if (button.textContent.trim() === counter.toString()) {
button.click();
console.log(`Selected answer: '${counter}'`);
const pairBoxes = document.querySelectorAll(".pairBox")
pairBoxes.forEach(pairBox => {
nextQuestionObserver.observe(pairBox, { childList: true, characterData: true, subtree: true });
});
}
});
commonRunOrExit();
}
globalThis.run = run;
}
promptForApiKey();
console.log(
"Type the question number to select or change question"
+ "\n" + "type 'question1()' for Question 1 - Reasoning"
+ "\n" + "type 'question2()' for Question 2 - Perceptual Speed"
+ "\n" + "type 'question3()' for Question 3 - Number Speed and Accuracy"
+ "\n" + "type 'question4()' for Question 4 - Word Meaning"
+ "\n" + "type 'question5()' for Question 5 - Spacial Visualisation"
);