From e71b7811649abad9af82b9e0be17f3ff5aea81ca Mon Sep 17 00:00:00 2001 From: YourFriendlyNeighborhoodDealer Date: Sat, 2 Mar 2019 08:32:39 +0100 Subject: [PATCH] Fixing question answer getting on result page, and replacing some old URL-s --- frame.js | 4 ++-- main.js | 44 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/frame.js b/frame.js index 35bd0fe..5a898b1 100644 --- a/frame.js +++ b/frame.js @@ -34,8 +34,8 @@ // @grant GM_xmlhttpRequest // @grant GM_openInTab // @license GNU General Public License v3.0 or later -// @supportURL questionmining.tk -// @contributionURL questionmining.tk +// @supportURL qmining.tk +// @contributionURL qmining.tk // @resource data file:/// // @namespace https://greasyfork.org/users/153067 // ==/UserScript== diff --git a/main.js b/main.js index 5297c62..c49a040 100644 --- a/main.js +++ b/main.js @@ -384,13 +384,39 @@ function GetSelectAnswer() { 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]); - return ret; + + 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) { @@ -548,7 +574,6 @@ function GetQuestionFromResult(i) { // tries to get right answer from result page // i is the index of the question function GetRightAnswerFromResult(i) { - var possibleAnswers = GetPossibleAnswers(i); var fun = []; // the basic type of getting answers @@ -558,8 +583,9 @@ function GetRightAnswerFromResult(i) { 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) // if there is dropdown list in the current question + if (GetDropboxes(i).length > 0) return GetCurrentAnswer(i); }); @@ -577,6 +603,7 @@ function GetRightAnswerFromResult(i) { // 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) @@ -602,7 +629,12 @@ function GetRightAnswerFromResult(i) { // i is the index of the question function GetRightAnswerFromResultv2(i) { try { - var items = GetAnswerNode(i); + var answerNodes = GetAnswerNode(i); + let items = answerNodes.nodes; + + 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")) @@ -1254,9 +1286,9 @@ function GetQuiz() { if (q != undefined) question.q = SimplifyQuery(q); // RIGHTANSWER --------------------------------------------------------------------------------------------------------------------- - var a = GetRightAnswerFromResult(i); + var a = GetRightAnswerFromResultv2(i); if (a == undefined) - a = GetRightAnswerFromResultv2(i); + a = GetRightAnswerFromResult(i); if (a != undefined) question.a = SimplifyQuery(a); // IMG ---------------------------------------------------------------------------------------------------------------------