mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Moving element getting to classes
This commit is contained in:
parent
4e4c5c723a
commit
da7eac9e56
1 changed files with 404 additions and 377 deletions
781
main.js
781
main.js
|
@ -28,19 +28,19 @@ const serverAdress = "https://qmining.tk/";
|
|||
|
||||
// forcing pages for testing. unless you test, do not set these to true!
|
||||
// only one of these should be true for testing
|
||||
const forceTestPage = false;
|
||||
const forceTestPage = true;
|
||||
const forceResultPage = false;
|
||||
const forceDefaultPage = false;
|
||||
const logElementGetting = false;
|
||||
const log = true;
|
||||
|
||||
const motdShowCount = 3;
|
||||
const motdShowCount = 3; /* Ammount of times to show motd */
|
||||
var motd = "";
|
||||
var lastestVersion = "";
|
||||
|
||||
const minMatchAmmount = 55;
|
||||
const minResultMatchPercent = 99;
|
||||
const lengthDiffMultiplier = 10;
|
||||
const minMatchAmmount = 55; /* Minimum ammount to consider that two questions match during answering */
|
||||
const minResultMatchPercent = 99; /* Minimum ammount to consider that two questions match during saving */
|
||||
const lengthDiffMultiplier = 10; /* Percent minus for length difference */
|
||||
|
||||
//: Class descriptions {{{
|
||||
class Question {
|
||||
|
@ -280,406 +280,422 @@ function Main() {
|
|||
// all dom getting stuff are in this sections, so on
|
||||
// moodle dom change, stuff breaks here
|
||||
|
||||
function GetAllQuestionsDropdown() {
|
||||
if (logElementGetting)
|
||||
Log("getting dropdown question");
|
||||
let items = document.getElementById("responseform").getElementsByTagName("p")[0].childNodes;
|
||||
let r = "";
|
||||
items.forEach((item) => {
|
||||
if (item.tagName == undefined)
|
||||
r += item.nodeValue;
|
||||
class QuestionsPageModell {
|
||||
|
||||
});
|
||||
return r;
|
||||
}
|
||||
GetAllQuestionsDropdown() {
|
||||
if (logElementGetting)
|
||||
Log("getting dropdown question");
|
||||
let items = document.getElementById("responseform").getElementsByTagName("p")[0].childNodes;
|
||||
let r = "";
|
||||
items.forEach((item) => {
|
||||
if (item.tagName == undefined)
|
||||
r += item.nodeValue;
|
||||
|
||||
function GetAllQuestionsQtext() {
|
||||
if (logElementGetting)
|
||||
Log("getting all questions qtext");
|
||||
return document.getElementById("responseform").getElementsByClassName("qtext"); // getting questions
|
||||
}
|
||||
|
||||
function GetAllQuestionsP() {
|
||||
if (logElementGetting)
|
||||
Log("getting all questions by tag p");
|
||||
return document.getElementById("responseform").getElementsByTagName("p");
|
||||
}
|
||||
|
||||
function GetFormulationClearfix() {
|
||||
if (logElementGetting)
|
||||
Log("getting formulation clearfix lol");
|
||||
return document.getElementsByClassName("formulation clearfix");
|
||||
}
|
||||
|
||||
function GetAnswerOptions() {
|
||||
if (logElementGetting)
|
||||
Log("getting all answer options");
|
||||
return GetFormulationClearfix()[0].childNodes[3].innerText;
|
||||
}
|
||||
|
||||
function GetQuestionImages() {
|
||||
if (logElementGetting)
|
||||
Log("getting question images");
|
||||
return GetFormulationClearfix()[0].getElementsByTagName("img");
|
||||
}
|
||||
|
||||
function GetCurrentSubjectName() {
|
||||
if (logElementGetting)
|
||||
Log("getting current subjects name");
|
||||
return document.getElementById("page-header").innerText.split("\n")[0];
|
||||
}
|
||||
|
||||
function GetVideo() {
|
||||
if (logElementGetting)
|
||||
Log("getting video stuff");
|
||||
return document.getElementsByTagName("video")[0];
|
||||
}
|
||||
|
||||
function GetVideoElement() {
|
||||
if (logElementGetting)
|
||||
Log("getting video element");
|
||||
return document.getElementById("videoElement").parentNode;
|
||||
}
|
||||
|
||||
function GetAllAnswer(index) {
|
||||
if (logElementGetting)
|
||||
Log("getting all answers, ind: " + index);
|
||||
return document.getElementsByClassName("answer")[index].childNodes;
|
||||
}
|
||||
|
||||
function GetInputType(answers, i) {
|
||||
if (logElementGetting)
|
||||
Log("getting input type");
|
||||
return answers[i].getElementsByTagName("input")[0].type;
|
||||
}
|
||||
|
||||
function GetFormResult() {
|
||||
if (logElementGetting)
|
||||
Log("getting form result");
|
||||
var t = document.getElementsByTagName("form")[0].childNodes[0].childNodes;
|
||||
if (t.length > 0 && t[0].tagName == undefined) // debreceni moodle
|
||||
return document.getElementsByTagName("form")[1].childNodes[0].childNodes;
|
||||
else
|
||||
return t;
|
||||
}
|
||||
|
||||
function GetQText(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting qtext by index: " + i);
|
||||
var results = GetFormResult(); // getting results element
|
||||
return results[i].getElementsByClassName("qtext");
|
||||
}
|
||||
|
||||
function GetDropboxes(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting dropboxes by index: " + i);
|
||||
var results = GetFormResult(); // getting results element
|
||||
return results[i].getElementsByTagName("select");
|
||||
}
|
||||
|
||||
function GetCurrQuestion(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting curr questions by index: " + i);
|
||||
return document.getElementsByTagName("form")[0].childNodes[0].childNodes[i].childNodes[1].childNodes[
|
||||
0].innerText;
|
||||
}
|
||||
|
||||
function GetCurrentAnswer(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting curr answer by index: " + i);
|
||||
var results = GetFormResult(); // getting results element
|
||||
var t = results[i].getElementsByClassName("formulation clearfix")[0].getElementsByTagName("span");
|
||||
if (t.length > 2)
|
||||
return t[1].innerHTML.split("<br>")[1];
|
||||
}
|
||||
|
||||
function GetSelectAnswer() {
|
||||
if (logElementGetting)
|
||||
Log("getting selected answer");
|
||||
var t = document.getElementsByTagName("select");
|
||||
if (t.length > 0)
|
||||
return t[0].options[document.getElementsByTagName("select")[
|
||||
0].selectedIndex].innerText;
|
||||
}
|
||||
|
||||
function GetAnswerNode(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting answer node");
|
||||
|
||||
var results = GetFormResult(); // getting results element
|
||||
|
||||
var r = results[i].getElementsByClassName("answer")[0].childNodes;
|
||||
var ret = [];
|
||||
for (var j = 0; j < r.length; j++)
|
||||
if (r[j].tagName != undefined && r[j].tagName.toLowerCase() == "div")
|
||||
ret.push(r[j]);
|
||||
|
||||
let qtype = DetermineQuestionType(ret);
|
||||
|
||||
return {
|
||||
nodes: ret,
|
||||
type: qtype
|
||||
};
|
||||
}
|
||||
|
||||
function DetermineQuestionType(nodes) {
|
||||
let qtype = "";
|
||||
let i = 0;
|
||||
|
||||
while (i < nodes.length && qtype == "") {
|
||||
let inps = nodes[i].getElementsByTagName("input");
|
||||
|
||||
if (inps.length > 0) {
|
||||
qtype = inps[0].type;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return qtype;
|
||||
|
||||
}
|
||||
|
||||
function GetPossibleAnswers(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting possible answers");
|
||||
var results = GetFormResult(); // getting results element
|
||||
var items = GetFormResult()[i].getElementsByTagName("label");
|
||||
var r = [];
|
||||
for (var j = 0; j < items.length; j++) {
|
||||
|
||||
function TryGetCorrect(j) {
|
||||
var cn = items[j].parentNode.className;
|
||||
if (cn.includes("correct"))
|
||||
return cn.includes("correct") && !cn.includes("incorrect");
|
||||
}
|
||||
r.push({
|
||||
value: items[j].innerText,
|
||||
iscorrect: TryGetCorrect(j)
|
||||
});
|
||||
return r;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
function GetRightAnswerIfCorrectShown(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting right answer if correct shown");
|
||||
var results = GetFormResult(); // getting results element
|
||||
return results[i].getElementsByClassName("rightanswer");
|
||||
}
|
||||
GetAllQuestionsQtext() {
|
||||
if (logElementGetting)
|
||||
Log("getting all questions qtext");
|
||||
return document.getElementById("responseform").getElementsByClassName("qtext"); // getting questions
|
||||
}
|
||||
|
||||
function GetWrongAnswerIfCorrectNotShown(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting wrong answer if correct not shown");
|
||||
var results = GetFormResult(); // getting results element
|
||||
var n = results[i].getElementsByTagName("i")[0].parentNode;
|
||||
if (n.className.includes("incorrect"))
|
||||
return results[i].getElementsByTagName("i")[0].parentNode.innerText;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
GetAllQuestionsP() {
|
||||
if (logElementGetting)
|
||||
Log("getting all questions by tag p");
|
||||
return document.getElementById("responseform").getElementsByTagName("p");
|
||||
}
|
||||
|
||||
function GetRightAnswerIfCorrectNotShown(i) {
|
||||
if (logElementGetting)
|
||||
Log("Getting right answer if correct not shown");
|
||||
var results = GetFormResult(); // getting results element
|
||||
var n = results[i].getElementsByTagName("i")[0].parentNode;
|
||||
if (n.className.includes("correct") && !n.className.includes("incorrect"))
|
||||
return results[i].getElementsByTagName("i")[0].parentNode.innerText;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
GetFormulationClearfix() {
|
||||
if (logElementGetting)
|
||||
Log("getting formulation clearfix lol");
|
||||
return document.getElementsByClassName("formulation clearfix");
|
||||
}
|
||||
|
||||
function GetFormCFOfResult(result) {
|
||||
if (logElementGetting)
|
||||
Log("getting formulation clearfix");
|
||||
return result.getElementsByClassName("formulation clearfix")[0];
|
||||
}
|
||||
GetAnswerOptions() {
|
||||
if (logElementGetting)
|
||||
Log("getting all answer options");
|
||||
return GetFormulationClearfix()[0].childNodes[3].innerText;
|
||||
}
|
||||
|
||||
function GetResultText(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting result text");
|
||||
var results = GetFormResult(); // getting results element
|
||||
return GetFormCFOfResult(results[i]).getElementsByTagName("p");
|
||||
}
|
||||
GetQuestionImages() {
|
||||
if (logElementGetting)
|
||||
Log("getting question images");
|
||||
return GetFormulationClearfix()[0].getElementsByTagName("img");
|
||||
}
|
||||
|
||||
function GetResultImage(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting result image");
|
||||
var results = GetFormResult(); // getting results element
|
||||
return GetFormCFOfResult(results[i]).getElementsByTagName("img");
|
||||
}
|
||||
|
||||
// this function should return the question, posible answers, and image names
|
||||
function GetQuestionFromTest() {
|
||||
var questions; // the important questions
|
||||
var allQuestions; // all questions
|
||||
try // trying to get tha current questions
|
||||
{
|
||||
allQuestions = GetAllQuestionsQtext(); // getting questions
|
||||
if (allQuestions.length == 0) // if there are no found questions
|
||||
// this function should return the question, posible answers, and image names
|
||||
GetQuestionFromTest() {
|
||||
var questions; // the important questions
|
||||
var allQuestions; // all questions
|
||||
try // trying to get tha current questions
|
||||
{
|
||||
var ddq = GetAllQuestionsDropdown();
|
||||
if (EmptyOrWhiteSpace(ddq)) {
|
||||
var questionData = "";
|
||||
for (var j = 0; j < allQuestions.length; j++) {
|
||||
allQuestions = GetAllQuestionsQtext()[j].childNodes;
|
||||
for (var i = 0; i < allQuestions.length; i++) {
|
||||
if (allQuestions[i].data != undefined && !EmptyOrWhiteSpace(allQuestions[i].data)) // if the current element has some text data to add
|
||||
{
|
||||
questionData += allQuestions[i].data + " "; // adding text to question data
|
||||
allQuestions = this.GetAllQuestionsQtext(); // getting questions
|
||||
if (allQuestions.length == 0) // if there are no found questions
|
||||
{
|
||||
var ddq = GetAllQuestionsDropdown();
|
||||
if (EmptyOrWhiteSpace(ddq)) {
|
||||
var questionData = "";
|
||||
for (var j = 0; j < allQuestions.length; j++) {
|
||||
allQuestions = this.GetAllQuestionsQtext()[j].childNodes;
|
||||
for (var i = 0; i < allQuestions.length; i++) {
|
||||
if (allQuestions[i].data != undefined && !EmptyOrWhiteSpace(allQuestions[i].data)) // if the current element has some text data to add
|
||||
{
|
||||
questionData += allQuestions[i].data + " "; // adding text to question data
|
||||
}
|
||||
}
|
||||
}
|
||||
questions = [questionData];
|
||||
} else
|
||||
questions = [ddq];
|
||||
} else // if there is
|
||||
{
|
||||
questions = [];
|
||||
for (var i = 0; i < allQuestions.length; i++) {
|
||||
questions.push(allQuestions[i].innerText);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Exception(e, "script error at getting question:");
|
||||
}
|
||||
var imgNodes = ""; // the image nodes for questions
|
||||
try {
|
||||
imgNodes = GetQuestionImages(); // getting question images, if there is any
|
||||
AddImageNamesToImages(imgNodes); // adding image names to images, so its easier to search for, or even guessing
|
||||
} catch (e) {
|
||||
Log(e);
|
||||
Log("Some error with images");
|
||||
}
|
||||
|
||||
questions = questions.map((item, ind) => {
|
||||
return ReplaceCharsWithSpace(item, "\n");
|
||||
});
|
||||
|
||||
return {
|
||||
imgnodes: imgNodes,
|
||||
allQ: allQuestions,
|
||||
q: questions
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class ResultsPageModell {
|
||||
|
||||
GetAllAnswer(index) {
|
||||
if (logElementGetting)
|
||||
Log("getting all answers, ind: " + index);
|
||||
return document.getElementsByClassName("answer")[index].childNodes;
|
||||
}
|
||||
|
||||
GetPossibleAnswers(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting possible answers");
|
||||
var results = GetFormResult(); // getting results element
|
||||
var items = GetFormResult()[i].getElementsByTagName("label");
|
||||
var r = [];
|
||||
for (var j = 0; j < items.length; j++) {
|
||||
|
||||
function TryGetCorrect(j) {
|
||||
var cn = items[j].parentNode.className;
|
||||
if (cn.includes("correct"))
|
||||
return cn.includes("correct") && !cn.includes("incorrect");
|
||||
}
|
||||
r.push({
|
||||
value: items[j].innerText,
|
||||
iscorrect: TryGetCorrect(j)
|
||||
});
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
GetRightAnswerIfCorrectShown(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting right answer if correct shown");
|
||||
var results = GetFormResult(); // getting results element
|
||||
return results[i].getElementsByClassName("rightanswer");
|
||||
}
|
||||
|
||||
GetWrongAnswerIfCorrectNotShown(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting wrong answer if correct not shown");
|
||||
var results = GetFormResult(); // getting results element
|
||||
var n = results[i].getElementsByTagName("i")[0].parentNode;
|
||||
if (n.className.includes("incorrect"))
|
||||
return results[i].getElementsByTagName("i")[0].parentNode.innerText;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
GetRightAnswerIfCorrectNotShown(i) {
|
||||
if (logElementGetting)
|
||||
Log("Getting right answer if correct not shown");
|
||||
var results = GetFormResult(); // getting results element
|
||||
var n = results[i].getElementsByTagName("i")[0].parentNode;
|
||||
if (n.className.includes("correct") && !n.className.includes("incorrect"))
|
||||
return results[i].getElementsByTagName("i")[0].parentNode.innerText;
|
||||
else
|
||||
return "";
|
||||
}
|
||||
|
||||
GetFormCFOfResult(result) {
|
||||
if (logElementGetting)
|
||||
Log("getting formulation clearfix");
|
||||
return result.getElementsByClassName("formulation clearfix")[0];
|
||||
}
|
||||
|
||||
GetResultText(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting result text");
|
||||
var results = GetFormResult(); // getting results element
|
||||
return GetFormCFOfResult(results[i]).getElementsByTagName("p");
|
||||
}
|
||||
|
||||
GetResultImage(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting result image");
|
||||
var results = GetFormResult(); // getting results element
|
||||
return GetFormCFOfResult(results[i]).getElementsByTagName("img");
|
||||
}
|
||||
|
||||
|
||||
// gets the question from the result page
|
||||
// i is the index of the question
|
||||
GetQuestionFromResult(i) {
|
||||
var temp = GetQText(i);
|
||||
var currQuestion = "";
|
||||
if (temp.length > 0) // if the qtext element is not 0 length
|
||||
{
|
||||
currQuestion = temp[0].innerText; // adding the question to curr question as .q
|
||||
} else {
|
||||
// this is black magic fuckery a bit
|
||||
if (GetDropboxes(i).length > 0) // if there is dropdown list in the current question
|
||||
{
|
||||
var allNodes = GetResultText(i);
|
||||
currQuestion = "";
|
||||
for (var k = 0; k < allNodes.length; k++) {
|
||||
var allQuestions = GetResultText(i)[k].childNodes;
|
||||
for (var j = 0; j < allQuestions.length; j++) {
|
||||
if (allQuestions[j].data != undefined && !EmptyOrWhiteSpace(allQuestions[j].data)) {
|
||||
currQuestion += allQuestions[j].data + " ";
|
||||
}
|
||||
}
|
||||
}
|
||||
questions = [questionData];
|
||||
} else
|
||||
questions = [ddq];
|
||||
} else // if there is
|
||||
{
|
||||
questions = [];
|
||||
for (var i = 0; i < allQuestions.length; i++) {
|
||||
questions.push(allQuestions[i].innerText);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Exception(e, "script error at getting question:");
|
||||
}
|
||||
var imgNodes = ""; // the image nodes for questions
|
||||
try {
|
||||
imgNodes = GetQuestionImages(); // getting question images, if there is any
|
||||
AddImageNamesToImages(imgNodes); // adding image names to images, so its easier to search for, or even guessing
|
||||
} catch (e) {
|
||||
Log(e);
|
||||
Log("Some error with images");
|
||||
}
|
||||
|
||||
questions = questions.map((item, ind) => {
|
||||
return ReplaceCharsWithSpace(item, "\n");
|
||||
});
|
||||
|
||||
return {
|
||||
imgnodes: imgNodes,
|
||||
allQ: allQuestions,
|
||||
q: questions
|
||||
};
|
||||
}
|
||||
|
||||
// gets the question from the result page
|
||||
// i is the index of the question
|
||||
function GetQuestionFromResult(i) {
|
||||
var temp = GetQText(i);
|
||||
var currQuestion = "";
|
||||
if (temp.length > 0) // if the qtext element is not 0 length
|
||||
{
|
||||
currQuestion = temp[0].innerText; // adding the question to curr question as .q
|
||||
} else {
|
||||
// this is black magic fuckery a bit
|
||||
if (GetDropboxes(i).length > 0) // if there is dropdown list in the current question
|
||||
{
|
||||
var allNodes = GetResultText(i);
|
||||
currQuestion = "";
|
||||
for (var k = 0; k < allNodes.length; k++) {
|
||||
var allQuestions = GetResultText(i)[k].childNodes;
|
||||
for (var j = 0; j < allQuestions.length; j++) {
|
||||
if (allQuestions[j].data != undefined && !EmptyOrWhiteSpace(allQuestions[j].data)) {
|
||||
currQuestion += allQuestions[j].data + " ";
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
currQuestion = GetCurrQuestion(i);
|
||||
} catch (e) {
|
||||
currQuestion = "REEEEEEEEEEEEEEEEEEEEE"; // this shouldnt really happen sry guys
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
currQuestion = GetCurrQuestion(i);
|
||||
} catch (e) {
|
||||
currQuestion = "REEEEEEEEEEEEEEEEEEEEE"; // this shouldnt really happen sry guys
|
||||
}
|
||||
return currQuestion;
|
||||
}
|
||||
|
||||
// tries to get right answer from result page
|
||||
// i is the index of the question
|
||||
GetRightAnswerFromResult(i) {
|
||||
var fun = [];
|
||||
|
||||
// the basic type of getting answers
|
||||
fun.push(function TryGet0(i) {
|
||||
var temp = GetRightAnswerIfCorrectShown(i); // getting risht answer
|
||||
if (temp.length > 0) // if the rightanswer element is not 0 length
|
||||
return temp[0].innerText; // adding the answer to curr question as .a
|
||||
});
|
||||
|
||||
// if there is dropdown list in the current question
|
||||
fun.push(function TryGet1(i) {
|
||||
if (GetDropboxes(i).length > 0)
|
||||
return GetCurrentAnswer(i);
|
||||
});
|
||||
|
||||
// if the correct answers are not shown, and the selected answer
|
||||
// is correct
|
||||
fun.push(function TryGet2(i) {
|
||||
return GetRightAnswerIfCorrectNotShown(i);
|
||||
});
|
||||
|
||||
// if there is dropbox in the question
|
||||
fun.push(function TryGet3(i) {
|
||||
return GetSelectAnswer();
|
||||
});
|
||||
|
||||
// if the correct answers are not shown, and the selected answer
|
||||
// is incorrect, and there are only 2 options
|
||||
fun.push(function TryGet4(i) {
|
||||
var possibleAnswers = GetPossibleAnswers(i);
|
||||
if (possibleAnswers.length == 2) {
|
||||
for (var k = 0; k < possibleAnswers.length; k++)
|
||||
if (possibleAnswers[k].iscorrect == undefined)
|
||||
return possibleAnswers[k].value;
|
||||
}
|
||||
});
|
||||
|
||||
fun.push(function TryGetFinal(i) {
|
||||
return undefined;
|
||||
});
|
||||
|
||||
var j = 0;
|
||||
var currAnswer;
|
||||
while (j < fun.length && EmptyOrWhiteSpace(currAnswer)) {
|
||||
currAnswer = fun[j](i);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
return currQuestion;
|
||||
}
|
||||
|
||||
// tries to get right answer from result page
|
||||
// i is the index of the question
|
||||
function GetRightAnswerFromResult(i) {
|
||||
var fun = [];
|
||||
|
||||
// the basic type of getting answers
|
||||
fun.push(function TryGet0(i) {
|
||||
var temp = GetRightAnswerIfCorrectShown(i); // getting risht answer
|
||||
if (temp.length > 0) // if the rightanswer element is not 0 length
|
||||
return temp[0].innerText; // adding the answer to curr question as .a
|
||||
});
|
||||
|
||||
// if there is dropdown list in the current question
|
||||
fun.push(function TryGet1(i) {
|
||||
if (GetDropboxes(i).length > 0)
|
||||
return GetCurrentAnswer(i);
|
||||
});
|
||||
|
||||
// if the correct answers are not shown, and the selected answer
|
||||
// is correct
|
||||
fun.push(function TryGet2(i) {
|
||||
return GetRightAnswerIfCorrectNotShown(i);
|
||||
});
|
||||
|
||||
// if there is dropbox in the question
|
||||
fun.push(function TryGet3(i) {
|
||||
return GetSelectAnswer();
|
||||
});
|
||||
|
||||
// if the correct answers are not shown, and the selected answer
|
||||
// is incorrect, and there are only 2 options
|
||||
fun.push(function TryGet4(i) {
|
||||
var possibleAnswers = GetPossibleAnswers(i);
|
||||
if (possibleAnswers.length == 2) {
|
||||
for (var k = 0; k < possibleAnswers.length; k++)
|
||||
if (possibleAnswers[k].iscorrect == undefined)
|
||||
return possibleAnswers[k].value;
|
||||
}
|
||||
});
|
||||
|
||||
fun.push(function TryGetFinal(i) {
|
||||
return undefined;
|
||||
});
|
||||
|
||||
var j = 0;
|
||||
var currAnswer;
|
||||
while (j < fun.length && EmptyOrWhiteSpace(currAnswer)) {
|
||||
currAnswer = fun[j](i);
|
||||
j++;
|
||||
return currAnswer;
|
||||
}
|
||||
|
||||
return currAnswer;
|
||||
}
|
||||
// version 2 of getting right answer from result page
|
||||
// i is the index of the question
|
||||
GetRightAnswerFromResultv2(i) {
|
||||
try {
|
||||
var answerNodes = GetAnswerNode(i);
|
||||
let items = answerNodes.nodes;
|
||||
|
||||
// version 2 of getting right answer from result page
|
||||
// i is the index of the question
|
||||
function GetRightAnswerFromResultv2(i) {
|
||||
try {
|
||||
var answerNodes = GetAnswerNode(i);
|
||||
let items = answerNodes.nodes;
|
||||
if (answerNodes.type == "checkbox")
|
||||
return GetRightAnswerFromResult(i);
|
||||
|
||||
if (answerNodes.type == "checkbox")
|
||||
return GetRightAnswerFromResult(i);
|
||||
|
||||
for (var j = 0; j < items.length; j++) {
|
||||
var cn = items[j].className;
|
||||
if (cn.includes("correct") && !cn.includes("incorrect"))
|
||||
return items[j].innerText;
|
||||
}
|
||||
if (items.length == 2) {
|
||||
for (var j = 0; j < items.length; j++) {
|
||||
var cn = items[j].className;
|
||||
if (!cn.includes("correct"))
|
||||
if (cn.includes("correct") && !cn.includes("incorrect"))
|
||||
return items[j].innerText;
|
||||
}
|
||||
if (items.length == 2) {
|
||||
for (var j = 0; j < items.length; j++) {
|
||||
var cn = items[j].className;
|
||||
if (!cn.includes("correct"))
|
||||
return items[j].innerText;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
Log("error at new nodegetting, trying the oldschool way");
|
||||
}
|
||||
} catch (e) {
|
||||
Log("error at new nodegetting, trying the oldschool way");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class MiscPageModell {
|
||||
|
||||
GetCurrentSubjectName() {
|
||||
if (logElementGetting)
|
||||
Log("getting current subjects name");
|
||||
return document.getElementById("page-header").innerText.split("\n")[0];
|
||||
}
|
||||
|
||||
GetVideo() {
|
||||
if (logElementGetting)
|
||||
Log("getting video stuff");
|
||||
return document.getElementsByTagName("video")[0];
|
||||
}
|
||||
|
||||
GetVideoElement() {
|
||||
if (logElementGetting)
|
||||
Log("getting video element");
|
||||
return document.getElementById("videoElement").parentNode;
|
||||
}
|
||||
|
||||
GetInputType(answers, i) {
|
||||
if (logElementGetting)
|
||||
Log("getting input type");
|
||||
return answers[i].getElementsByTagName("input")[0].type;
|
||||
}
|
||||
|
||||
GetFormResult() {
|
||||
if (logElementGetting)
|
||||
Log("getting form result");
|
||||
var t = document.getElementsByTagName("form")[0].childNodes[0].childNodes;
|
||||
if (t.length > 0 && t[0].tagName == undefined) // debreceni moodle
|
||||
return document.getElementsByTagName("form")[1].childNodes[0].childNodes;
|
||||
else
|
||||
return t;
|
||||
}
|
||||
|
||||
GetQText(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting qtext by index: " + i);
|
||||
var results = GetFormResult(); // getting results element
|
||||
return results[i].getElementsByClassName("qtext");
|
||||
}
|
||||
|
||||
GetDropboxes(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting dropboxes by index: " + i);
|
||||
var results = GetFormResult(); // getting results element
|
||||
return results[i].getElementsByTagName("select");
|
||||
}
|
||||
|
||||
GetCurrQuestion(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting curr questions by index: " + i);
|
||||
return document.getElementsByTagName("form")[0].childNodes[0].childNodes[i].childNodes[1].childNodes[
|
||||
0].innerText;
|
||||
}
|
||||
|
||||
GetCurrentAnswer(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting curr answer by index: " + i);
|
||||
var results = GetFormResult(); // getting results element
|
||||
var t = results[i].getElementsByClassName("formulation clearfix")[0].getElementsByTagName("span");
|
||||
if (t.length > 2)
|
||||
return t[1].innerHTML.split("<br>")[1];
|
||||
}
|
||||
|
||||
GetSelectAnswer() {
|
||||
if (logElementGetting)
|
||||
Log("getting selected answer");
|
||||
var t = document.getElementsByTagName("select");
|
||||
if (t.length > 0)
|
||||
return t[0].options[document.getElementsByTagName("select")[
|
||||
0].selectedIndex].innerText;
|
||||
}
|
||||
|
||||
GetAnswerNode(i) {
|
||||
if (logElementGetting)
|
||||
Log("getting answer node");
|
||||
|
||||
var results = GetFormResult(); // getting results element
|
||||
|
||||
var r = results[i].getElementsByClassName("answer")[0].childNodes;
|
||||
var ret = [];
|
||||
for (var j = 0; j < r.length; j++)
|
||||
if (r[j].tagName != undefined && r[j].tagName.toLowerCase() == "div")
|
||||
ret.push(r[j]);
|
||||
|
||||
let qtype = DetermineQuestionType(ret);
|
||||
|
||||
return {
|
||||
nodes: ret,
|
||||
type: qtype
|
||||
};
|
||||
}
|
||||
|
||||
DetermineQuestionType(nodes) {
|
||||
let qtype = "";
|
||||
let i = 0;
|
||||
|
||||
while (i < nodes.length && qtype == "") {
|
||||
let inps = nodes[i].getElementsByTagName("input");
|
||||
|
||||
if (inps.length > 0) {
|
||||
qtype = inps[0].type;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return qtype;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
//: }}}
|
||||
|
||||
var QPM = new QuestionsPageModell();
|
||||
var RPM = new ResultsPageModell();
|
||||
var MPM = new MiscPageModell();
|
||||
|
||||
//: Main logic stuff {{{
|
||||
|
||||
//: Loading {{{
|
||||
|
@ -794,10 +810,14 @@ function Version161() {
|
|||
|
||||
//: }}}
|
||||
|
||||
var GetFileData = () => {
|
||||
return GM_getResourceText("data");
|
||||
};
|
||||
|
||||
function ReadFile(cwith) {
|
||||
var resource = "";
|
||||
try {
|
||||
resource = GM_getResourceText("data"); // getting data from txt
|
||||
resource = GetFileData(); // getting data from txt
|
||||
if (resource == undefined) {
|
||||
|
||||
ShowMessage({
|
||||
|
@ -1022,8 +1042,8 @@ function NLoad(resource, cwith) {
|
|||
while (i < data.length && !GM_getValue("Is" + i + "Active")) {
|
||||
i++;
|
||||
}
|
||||
if (i >= data.length)
|
||||
document.getElementById("HelperMenuButton").style.background = "yellow";
|
||||
|
||||
AlertOnNoQuestion(i);
|
||||
|
||||
} catch (e) {
|
||||
Exception(e, "script error at loading:");
|
||||
|
@ -1032,6 +1052,13 @@ function NLoad(resource, cwith) {
|
|||
cwith(count, subjCount);
|
||||
}
|
||||
|
||||
var AlertOnNoQuestion = (i) => {
|
||||
try {
|
||||
if (i >= data.length)
|
||||
document.getElementById("HelperMenuButton").style.background = "yellow";
|
||||
} catch (e) {}
|
||||
};
|
||||
|
||||
//: }}}
|
||||
|
||||
//: UI handling {{{
|
||||
|
@ -1059,7 +1086,7 @@ function HandleUI(url, count, subjCount) {
|
|||
greetMsg = "Moodle/Elearning/KMOOC segéd v. " + GM_info.script.version + ". ";
|
||||
|
||||
if (lastestVersion != undefined && GM_info.script.version != lastestVersion) {
|
||||
greetMsg += "Új verzió elérhető: " + lastestVersion + " ";
|
||||
greetMsg += "Új verzió elérhető: " + lastestVersion + "\n";
|
||||
timeout = undefined;
|
||||
}
|
||||
greetMsg += count + " kérdés és " + subjCount + " tárgy betöltve. (click for help).";
|
||||
|
@ -1129,7 +1156,7 @@ function HandleUI(url, count, subjCount) {
|
|||
//: Answering stuffs {{{
|
||||
|
||||
function HandleQuiz() {
|
||||
var q = GetQuestionFromTest();
|
||||
var q = QPM.GetQuestionFromTest();
|
||||
var questions = q.q;
|
||||
var allQuestions = q.allQ;
|
||||
var imgNodes = q.imgnodes;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue