mirror of
				https://gitlab.com/MrFry/moodle-test-userscript
				synced 2025-04-01 20:22:48 +02:00 
			
		
		
		
	Fixing question answer getting on result page, and replacing some old URL-s
This commit is contained in:
		
							
								
								
									
										4
									
								
								frame.js
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								frame.js
									
									
									
									
									
								
							| @@ -34,8 +34,8 @@ | |||||||
| // @grant        GM_xmlhttpRequest | // @grant        GM_xmlhttpRequest | ||||||
| // @grant        GM_openInTab | // @grant        GM_openInTab | ||||||
| // @license      GNU General Public License v3.0 or later | // @license      GNU General Public License v3.0 or later | ||||||
| // @supportURL	 questionmining.tk | // @supportURL	 qmining.tk | ||||||
| // @contributionURL questionmining.tk | // @contributionURL qmining.tk | ||||||
| // @resource     data file:///<file path space is %20, and use "/"-s plz not "\" ty (and add .txt)// UTF-8 PLZ> | // @resource     data file:///<file path space is %20, and use "/"-s plz not "\" ty (and add .txt)// UTF-8 PLZ> | ||||||
| // @namespace    https://greasyfork.org/users/153067 | // @namespace    https://greasyfork.org/users/153067 | ||||||
| // ==/UserScript== | // ==/UserScript== | ||||||
|   | |||||||
							
								
								
									
										44
									
								
								main.js
									
									
									
									
									
								
							
							
						
						
									
										44
									
								
								main.js
									
									
									
									
									
								
							| @@ -384,13 +384,39 @@ function GetSelectAnswer() { | |||||||
| function GetAnswerNode(i) { | function GetAnswerNode(i) { | ||||||
| 	if (logElementGetting) | 	if (logElementGetting) | ||||||
| 		Log("getting answer node"); | 		Log("getting answer node"); | ||||||
|  |  | ||||||
| 	var results = GetFormResult(); // getting results element | 	var results = GetFormResult(); // getting results element | ||||||
|  |  | ||||||
| 	var r = results[i].getElementsByClassName("answer")[0].childNodes; | 	var r = results[i].getElementsByClassName("answer")[0].childNodes; | ||||||
| 	var ret = []; | 	var ret = []; | ||||||
| 	for (var j = 0; j < r.length; j++) | 	for (var j = 0; j < r.length; j++) | ||||||
| 		if (r[j].tagName != undefined && r[j].tagName.toLowerCase() == "div") | 		if (r[j].tagName != undefined && r[j].tagName.toLowerCase() == "div") | ||||||
| 			ret.push(r[j]); | 			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) { | function GetPossibleAnswers(i) { | ||||||
| @@ -548,7 +574,6 @@ function GetQuestionFromResult(i) { | |||||||
| // tries to get right answer from result page | // tries to get right answer from result page | ||||||
| // i is the index of the question | // i is the index of the question | ||||||
| function GetRightAnswerFromResult(i) { | function GetRightAnswerFromResult(i) { | ||||||
| 	var possibleAnswers = GetPossibleAnswers(i); |  | ||||||
| 	var fun = []; | 	var fun = []; | ||||||
|  |  | ||||||
| 	// the basic type of getting answers | 	// 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 | 			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) { | 	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); | 			return GetCurrentAnswer(i); | ||||||
| 	}); | 	}); | ||||||
|  |  | ||||||
| @@ -577,6 +603,7 @@ function GetRightAnswerFromResult(i) { | |||||||
| 	// 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 = 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) | ||||||
| @@ -602,7 +629,12 @@ function GetRightAnswerFromResult(i) { | |||||||
| // i is the index of the question | // i is the index of the question | ||||||
| function GetRightAnswerFromResultv2(i) { | function GetRightAnswerFromResultv2(i) { | ||||||
| 	try { | 	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++) { | 		for (var j = 0; j < items.length; j++) { | ||||||
| 			var cn = items[j].className; | 			var cn = items[j].className; | ||||||
| 			if (cn.includes("correct") && !cn.includes("incorrect")) | 			if (cn.includes("correct") && !cn.includes("incorrect")) | ||||||
| @@ -1254,9 +1286,9 @@ function GetQuiz() { | |||||||
| 			if (q != undefined) | 			if (q != undefined) | ||||||
| 				question.q = SimplifyQuery(q); | 				question.q = SimplifyQuery(q); | ||||||
| 			// RIGHTANSWER --------------------------------------------------------------------------------------------------------------------- | 			// RIGHTANSWER --------------------------------------------------------------------------------------------------------------------- | ||||||
| 			var a = GetRightAnswerFromResult(i); | 			var a = GetRightAnswerFromResultv2(i); | ||||||
| 			if (a == undefined) | 			if (a == undefined) | ||||||
| 				a = GetRightAnswerFromResultv2(i); | 				a = GetRightAnswerFromResult(i); | ||||||
| 			if (a != undefined) | 			if (a != undefined) | ||||||
| 				question.a = SimplifyQuery(a); | 				question.a = SimplifyQuery(a); | ||||||
| 			// IMG --------------------------------------------------------------------------------------------------------------------- | 			// IMG --------------------------------------------------------------------------------------------------------------------- | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user