mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Fix of invalid .this usage, fix for question getting with no answers shown, basic assert add
This commit is contained in:
parent
1a710fcd42
commit
580f9d9b9c
1 changed files with 23 additions and 11 deletions
34
main.js
34
main.js
|
@ -27,7 +27,7 @@ const serverAdress = "https://qmining.tk/";
|
||||||
|
|
||||||
// forcing pages for testing. unless you test, do not set these to true!
|
// forcing pages for testing. unless you test, do not set these to true!
|
||||||
// only one of these should be true for testing
|
// only one of these should be true for testing
|
||||||
const forceTestPage = true;
|
const forceTestPage = false;
|
||||||
const forceResultPage = false;
|
const forceResultPage = false;
|
||||||
const forceDefaultPage = false;
|
const forceDefaultPage = false;
|
||||||
const logElementGetting = false;
|
const logElementGetting = false;
|
||||||
|
@ -535,32 +535,32 @@ class ResultsPageModell {
|
||||||
|
|
||||||
// the basic type of getting answers
|
// the basic type of getting answers
|
||||||
fun.push(function TryGet0(i) {
|
fun.push(function TryGet0(i) {
|
||||||
var temp = this.GetRightAnswerIfCorrectShown(i); // getting risht answer
|
var temp = RPM.GetRightAnswerIfCorrectShown(i); // getting risht answer
|
||||||
if (temp.length > 0) // if the rightanswer element is not 0 length
|
if (temp.length > 0) // if the rightanswer element is not 0 length
|
||||||
return temp[0].innerText; // adding the answer to curr question as .a
|
return temp[0].innerText; // adding the answer to curr question as .a
|
||||||
});
|
});
|
||||||
|
|
||||||
// if there is dropdown list in the current question
|
// if there is dropdown list in the current question
|
||||||
fun.push(function TryGet1(i) {
|
fun.push(function TryGet1(i) {
|
||||||
if (this.GetDropboxes(i).length > 0)
|
if (RPM.GetDropboxes(i).length > 0)
|
||||||
return this.GetCurrentAnswer(i);
|
return RPM.GetCurrentAnswer(i);
|
||||||
});
|
});
|
||||||
|
|
||||||
// if the correct answers are not shown, and the selected answer
|
// if the correct answers are not shown, and the selected answer
|
||||||
// is correct
|
// is correct
|
||||||
fun.push(function TryGet2(i) {
|
fun.push(function TryGet2(i) {
|
||||||
return this.GetRightAnswerIfCorrectNotShown(i);
|
return RPM.GetRightAnswerIfCorrectNotShown(i);
|
||||||
});
|
});
|
||||||
|
|
||||||
// if there is dropbox in the question
|
// if there is dropbox in the question
|
||||||
fun.push(function TryGet3(i) {
|
fun.push(function TryGet3(i) {
|
||||||
return this.GetSelectAnswer();
|
return RPM.GetSelectAnswer();
|
||||||
});
|
});
|
||||||
|
|
||||||
// if the correct answers are not shown, and the selected answer
|
// if the correct answers are not shown, and the selected answer
|
||||||
// is incorrect, and there are only 2 options
|
// is incorrect, and there are only 2 options
|
||||||
fun.push(function TryGet4(i) {
|
fun.push(function TryGet4(i) {
|
||||||
var possibleAnswers = this.GetPossibleAnswers(i);
|
var possibleAnswers = RPM.GetPossibleAnswers(i);
|
||||||
if (possibleAnswers.length == 2) {
|
if (possibleAnswers.length == 2) {
|
||||||
for (var k = 0; k < possibleAnswers.length; k++)
|
for (var k = 0; k < possibleAnswers.length; k++)
|
||||||
if (possibleAnswers[k].iscorrect == undefined)
|
if (possibleAnswers[k].iscorrect == undefined)
|
||||||
|
@ -691,7 +691,8 @@ function Main() {
|
||||||
console.timeEnd('main');
|
console.timeEnd('main');
|
||||||
|
|
||||||
if (forceTestPage || forceResultPage || forceDefaultPage)
|
if (forceTestPage || forceResultPage || forceDefaultPage)
|
||||||
document.getElementById("scriptMessage").style.background = "green";
|
if (document.getElementById("scriptMessage"))
|
||||||
|
document.getElementById("scriptMessage").style.background = "green";
|
||||||
}
|
}
|
||||||
//: }}}
|
//: }}}
|
||||||
|
|
||||||
|
@ -1383,14 +1384,16 @@ function GetQuiz() {
|
||||||
var img = GetImageFormResult(i);
|
var img = GetImageFormResult(i);
|
||||||
question.i = img;
|
question.i = img;
|
||||||
|
|
||||||
q = ReplaceCharsWithSpace(q, "\n");
|
if (q != undefined)
|
||||||
a = ReplaceCharsWithSpace(a, "\n");
|
q = ReplaceCharsWithSpace(q, "\n");
|
||||||
|
if (a != undefined)
|
||||||
|
a = ReplaceCharsWithSpace(a, "\n");
|
||||||
|
|
||||||
if (question.a != undefined) // adding only if has question
|
if (question.a != undefined) // adding only if has question
|
||||||
{
|
{
|
||||||
quiz.push(new Question(question.q, question.a, question.i)); // adding current question to quiz
|
quiz.push(new Question(question.q, question.a, question.i)); // adding current question to quiz
|
||||||
} else {
|
} else {
|
||||||
Log("error getting queston, or its incorrect");
|
Log("error getting queston, no correct answer given, or its incorrect");
|
||||||
Log(question);
|
Log(question);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2186,6 +2189,10 @@ function CreateNodeWithText(to, text, type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function ReplaceCharsWithSpace(val, char) {
|
function ReplaceCharsWithSpace(val, char) {
|
||||||
|
|
||||||
|
assert(val);
|
||||||
|
assert(char);
|
||||||
|
|
||||||
toremove = NormalizeSpaces(val);
|
toremove = NormalizeSpaces(val);
|
||||||
|
|
||||||
var regex = new RegExp(char, "g");
|
var regex = new RegExp(char, "g");
|
||||||
|
@ -2243,6 +2250,11 @@ function SendXHRMessage(message) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var assert = (val) => {
|
||||||
|
if (!val)
|
||||||
|
throw new Error("Assertion failed");
|
||||||
|
};
|
||||||
|
|
||||||
//: }}}
|
//: }}}
|
||||||
|
|
||||||
//: Help {{{
|
//: Help {{{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue