diff --git a/stable.user.js b/stable.user.js index 3650aad..6c9f9fe 100755 --- a/stable.user.js +++ b/stable.user.js @@ -46,7 +46,7 @@ // : Script header {{{ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 2.1.3.4 +// @version 2.1.3.5 // @description Online Moodle/Elearning/KMOOC test help // @author MrFry // @match https://elearning.uni-obuda.hu/* @@ -1023,31 +1023,46 @@ // : }}} - // : KGK {{{ + // : AVR {{{ - function getKGKAnswerNodesFromQuiz() { + function getAVRTextFromImg(img) { + return decodeURIComponent(img.src).split('|')[1] + } + + function getAVRPossibleAnswersFromQuiz() { let i = 1 let currElem = null const elems = [] do { currElem = document.getElementsByClassName(`kvalasz${i}`)[0] if (currElem) { - elems.push(currElem) + const img = currElem.getElementsByTagName('img')[0] + if (img) { + elems.push(getAVRTextFromImg(img)) + } else { + elems.push(currElem.innerText) + } } i++ } while (currElem !== undefined) return elems } - function getKGKQuestionNodeFromQuiz() { - return document.getElementsByClassName('kkerdes')[0] + function getAVRQuestionFromQuiz() { + const q = document.getElementsByClassName('kkerdes')[0] + const img = q.getElementsByTagName('img')[0] + if (img) { + return getAVRTextFromImg(img) + } else { + return simplifyAVRQuestionString(q.innerText) + } } - function getKGKSubjName() { + function getAVRSubjName() { return document.getElementsByTagName('header')[0].innerText } - function HandleKGKResults(url) { + function HandleAVRResults(url) { const tableChilds = document.getElementsByTagName('table')[0].childNodes[0].childNodes const question = removeUnnecesarySpaces( @@ -1061,7 +1076,7 @@ ) if (correct.toLowerCase() === 'helyes') { const sentData = { - subj: getKGKSubjName(), + subj: getAVRSubjName(), version: info().script.version, id: getCid(), location: url, @@ -1089,7 +1104,7 @@ } } - function simplifyKGKQuestionString(val) { + function simplifyAVRQuestionString(val) { // FIXME: this is ugly let x = val.split('\n') x.shift() @@ -1110,7 +1125,7 @@ } } - function handleKGKSite(url) { + function handleAVRSite(url) { let prevLength = -1 const handler = () => { @@ -1119,10 +1134,13 @@ prevLength = kkerdesElements.length clearAllMessages() if (determineCurrentSite() === 'TEST') { - handleKGKQuiz(url) + log('AVR: handling test') + handleAVRQuiz(url) } else if (determineCurrentSite() === 'RESULT') { - HandleKGKResults(url) + log('AVR: handling result') + HandleAVRResults(url) } else { + log('AVR: handling UI') HandleUI() } } @@ -1132,23 +1150,21 @@ handler() } - function handleKGKQuiz(url) { + function handleAVRQuiz(url) { try { const { removeMessage: removeLoadingMessage } = ShowMessage( texts.loadingAnswer ) - const answerNodes = getKGKAnswerNodesFromQuiz() - const questionNode = getKGKQuestionNodeFromQuiz() + const possibleAnswers = getAVRPossibleAnswersFromQuiz() + const question = getAVRQuestionFromQuiz() const sentData = { questions: [ { - Q: simplifyKGKQuestionString(questionNode.innerText), + Q: question, subj: 'AVR', data: { type: 'simple' }, - possibleAnswers: answerNodes.map((node) => { - return node.innerText - }), + possibleAnswers: possibleAnswers, }, ], testUrl: url, @@ -1403,7 +1419,7 @@ // return url.includes('vizsga') // }, // action: (url) => { - // handleKGKSite(url) + // handleAVRSite(url) // }, // }, // resultPage: { @@ -1411,7 +1427,7 @@ // return false // TODO :insert real url // }, // action: (url) => { - // handleKGKSite(url) + // handleAVRSite(url) // }, // }, default: { @@ -1419,8 +1435,8 @@ return true // TODO :insert real url }, action: (url) => { - log('Handling KGK default action') - handleKGKSite(url) + log('Handling AVR default action') + handleAVRSite(url) }, }, },