Renamed kgk stuff to avr, handling avr img tags in questions

This commit is contained in:
mrfry 2022-02-19 10:25:52 +01:00
parent 21f4377cfe
commit c4e01b1750

View file

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