mirror of
				https://gitlab.com/MrFry/moodle-test-userscript
				synced 2025-04-01 20:22:48 +02:00 
			
		
		
		
	Fixed question results, where there are 2 questions, and none of them are marked incorrect
This commit is contained in:
		| @@ -21,13 +21,14 @@ | ||||
|  | ||||
| // ==UserScript== | ||||
| // @name         Moodle/Elearning/KMOOC test help | ||||
| // @version      2.0.0.6 | ||||
| // @version      2.0.0.10 | ||||
| // @description  Online Moodle/Elearning/KMOOC test help | ||||
| // @author       MrFry | ||||
| // @match        https://elearning.uni-obuda.hu/main/* | ||||
| // @match        https://elearning.uni-obuda.hu/kmooc/* | ||||
| // @match        https://mooc.unideb.hu/* | ||||
| // @match        https://qmining.frylabs.net/* | ||||
| // @noframes | ||||
| // @match        http://qmining.frylabs.net/* | ||||
| // @grant        GM_getResourceText | ||||
| // @grant        GM_info | ||||
| @@ -61,14 +62,14 @@ | ||||
|   var addEventListener // add event listener function | ||||
|   const serverAdress = 'https://qmining.frylabs.net/' | ||||
|   // const serverAdress = 'http://localhost:8080/' | ||||
|   const apiAdress = 'https://api.frylabs.net/' | ||||
|   // const apiAdress = 'http://localhost:8080/' | ||||
|   // const apiAdress = 'https://api.frylabs.net/' | ||||
|   const apiAdress = 'http://localhost:8080/' | ||||
|   const ircAddress = 'https://kiwiirc.com/nextclient/irc.sub.fm/#qmining' | ||||
|  | ||||
|   // 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 forceResultPage = false | ||||
|   const forceResultPage = true | ||||
|   const forceDefaultPage = false | ||||
|   const logElementGetting = false | ||||
|   const log = true | ||||
| @@ -288,6 +289,17 @@ | ||||
|   } | ||||
|  | ||||
|   class ResultsPageModell { | ||||
|     GetFormulationClearfix () { | ||||
|       if (logElementGetting) { Log('getting formulation clearfix lol') } | ||||
|       return document.getElementsByClassName('formulation clearfix') | ||||
|     } | ||||
|  | ||||
|     GetGrade (i) { | ||||
|       if (logElementGetting) { Log('getting grade') } | ||||
|       const fcf = QPM.GetFormulationClearfix()[i] | ||||
|       return fcf.parentNode.parentNode.childNodes[0].childNodes[2].innerText | ||||
|     } | ||||
|  | ||||
|     DetermineQuestionType (nodes) { | ||||
|       let qtype = '' | ||||
|       let i = 0 | ||||
| @@ -546,6 +558,52 @@ | ||||
|       return currAnswer | ||||
|     } | ||||
|  | ||||
|     GuessCorrectIn2LengthAnswersByIncorrect (items) { | ||||
|       const first = items[0] | ||||
|       const second = items[1] | ||||
|       if (first.className.includes('incorrect')) { | ||||
|         return second.innerText | ||||
|       } | ||||
|       if (second.className.includes('incorrect')) { | ||||
|         return first.innerText | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     GuessCorrectIn2LengthAnswersByPoints (i, items) { | ||||
|       const first = { | ||||
|         elem: items[0], | ||||
|         val: parseInt(items[0].childNodes[0].value), | ||||
|         text: items[0].innerText | ||||
|       } | ||||
|       const second = { | ||||
|         elem: items[1], | ||||
|         val: parseInt(items[1].childNodes[0].value), | ||||
|         text: items[1].innerText | ||||
|       } | ||||
|  | ||||
|       const grade = RPM.GetGrade(i) // 1,00 közül 1,00 leosztályozva | ||||
|       const grades = grade.split(' ').reduce((acc, text) => { | ||||
|         if (text.includes(',')) { // FIXME: fancy regexp | ||||
|           acc.push(parseInt(text)) | ||||
|         } | ||||
|         return acc | ||||
|       }, []) | ||||
|  | ||||
|       if (grades[0] === 1) { | ||||
|         if (first.val === 1) { | ||||
|           return first.text | ||||
|         } else { | ||||
|           return second.text | ||||
|         } | ||||
|       } else { | ||||
|         if (first.val === 0) { | ||||
|           return first.txt | ||||
|         } else { | ||||
|           return second.text | ||||
|         } | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     // version 2 of getting right answer from result page | ||||
|     // i is the index of the question | ||||
|     GetRightAnswerFromResultv2 (i) { | ||||
| @@ -562,10 +620,12 @@ | ||||
|           } | ||||
|         } | ||||
|         if (items.length === 2) { | ||||
|           for (let j = 0; j < items.length; j++) { | ||||
|             let cn = items[j].className | ||||
|             if (!cn.includes('correct')) { return items[j].innerText } | ||||
|           const resByIncorrect = this.GuessCorrectIn2LengthAnswersByIncorrect(items) | ||||
|           if (!resByIncorrect) { | ||||
|             const resPoints = this.GuessCorrectIn2LengthAnswersByPoints(i, items) | ||||
|             return resPoints | ||||
|           } | ||||
|           return resByIncorrect | ||||
|         } | ||||
|       } catch (e) { | ||||
|         Log('error at new nodegetting, trying the oldschool way') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user