-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrivia.js
51 lines (44 loc) · 1.71 KB
/
trivia.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
var answers_solver = [];
var question_solver = "";
var options_solver = [];
xmlhttp=new XMLHttpRequest();
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var lines = xmlhttp.responseText.split("\n");
for (var i = 0; i < lines.length/3; i++)
{
answers_solver.push({question:lines[i*3].trim().toUpperCase(), answer:lines[i*3+1].trim().toUpperCase()});
}
getQuestionsAndOptions();
solveQuestion();
}
}
xmlhttp.open("GET","https://rawgit.com/cameroncros/tomostrivia/master/tomosanswers.txt",true);
xmlhttp.send();
function solveQuestion() {
debugger;
for (var i = 0; i < answers_solver.length; i++) {
if (answers_solver[i].question == question_solver) {
for (var j = 0; j < 4; j++) {
if (answers_solver[i].answer == options_solver[j]) {
//alert(j);
trivia_submitAnswer(j);
setTimeout(function(){
window.location = 'main.php?p=tradepost&lot=trivia&cont=1';
},1000);
return;
}
}
}
}
alert("Failed to find answer, prehaps its not in the correct format, or missing entirely from the data set, please report with a screenshot of the question")
}
function getQuestionsAndOptions() {
question_solver = document.getElementById("tomo_question").innerHTML.trim().toUpperCase();
options_solver.push(document.getElementById("answer0").innerHTML.trim().toUpperCase());
options_solver.push(document.getElementById("answer1").innerHTML.trim().toUpperCase());
options_solver.push(document.getElementById("answer2").innerHTML.trim().toUpperCase());
options_solver.push(document.getElementById("answer3").innerHTML.trim().toUpperCase());
}