Making things work on older moodle versions

This commit is contained in:
mrfry 2021-03-14 12:21:54 +01:00
parent a437f8f98d
commit 21aee8420c

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.0.3 // @version 2.1.1.0
// @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/*
@ -403,10 +403,16 @@
// TODO: dropdown in question // TODO: dropdown in question
// TODO: get possible answers too // TODO: get possible answers too
const promises = [] const promises = []
const questionNodes = Array.from( let questionNodes = Array.from(
document.getElementsByTagName('form')[0].childNodes[0].childNodes document.getElementsByTagName('form')[0].childNodes[0].childNodes
) )
if (questionNodes.length === 0) {
questionNodes = Array.from(
document.getElementsByTagName('form')[1].childNodes[0].childNodes
)
}
let i = 0 let i = 0
while ( while (
i < questionNodes.length && i < questionNodes.length &&
@ -599,9 +605,14 @@
function getQuiz() { function getQuiz() {
return new Promise(resolve => { return new Promise(resolve => {
const promises = [] const promises = []
const questionNodes = Array.from( let questionNodes = Array.from(
document.getElementsByTagName('form')[0].childNodes[0].childNodes document.getElementsByTagName('form')[0].childNodes[0].childNodes
) )
if (questionNodes.length === 0) {
questionNodes = Array.from(
document.getElementsByTagName('form')[1].childNodes[0].childNodes
)
}
let i = 0 let i = 0
while (i < questionNodes.length && questionNodes[i].tagName === 'DIV') { while (i < questionNodes.length && questionNodes[i].tagName === 'DIV') {
@ -1370,6 +1381,12 @@
answer.detailedMatch.qdb, answer.detailedMatch.qdb,
} }
}) })
} else {
return [
{
m: 'Erre a kérdésre nincs találat :c',
},
]
} }
} }
@ -1887,7 +1904,9 @@
const SetQuestionText = () => { const SetQuestionText = () => {
const relevantQuestion = GetRelevantQuestion() const relevantQuestion = GetRelevantQuestion()
headerText.innerText = relevantQuestion.header if (relevantQuestion.header) {
headerText.innerText = relevantQuestion.header
}
questionTextElement.innerText = relevantQuestion.m questionTextElement.innerText = relevantQuestion.m
if (currItem === 0 && currRelevantQuestion === 0) { if (currItem === 0 && currRelevantQuestion === 0) {
@ -1896,7 +1915,9 @@
numberTextBox.innerText = numberTextBox.innerText =
currItem + 1 + './' + (currRelevantQuestion + 1) + '.' currItem + 1 + './' + (currRelevantQuestion + 1) + '.'
} }
percentTextBox.innerText = relevantQuestion.p + '%' if (relevantQuestion.p) {
percentTextBox.innerText = relevantQuestion.p + '%'
}
} }
const buttonStyle = { const buttonStyle = {