-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_answers.js
31 lines (30 loc) · 1.07 KB
/
get_answers.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
(function () {
function parseCorrectAnswers() {
var results = [];
$(".que").each(function () {
var text = $(".qtext", this).text().replace(/(\s+)/gm, "");
var answer = $(".rightanswer", this).text();
if (answer.startsWith("A resposta correcta é: ")) {
answer = answer.replace("A resposta correcta é: ", "");
answer = answer.replace(/(\s+)/gm, "");
} else {
if ($("span", $(".rightanswer", this)).length > 1) {
answer = [];
$("span", $(".rightanswer", this)).each(function () {
answer.push($(this).text().replace(/(\s+)/gm, ""));
});
} else {
answer = answer.replace("As respostas correctas son: ", "");
answer = answer.split(", ");
for (var x = 0; x < answer.length; x++) {
answer[x] = answer[x].replace(/(\s+)/gm, "");
}
}
}
results.push({ question: text, answer: answer });
});
localStorage.setItem("answers", JSON.stringify(results));
alert("Parsing complete!");
}
parseCorrectAnswers();
})();