mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Logging fixes, adding possible answers to data, no correct answer showing in result page fix
This commit is contained in:
parent
bee662bf44
commit
969c2516c3
1 changed files with 29 additions and 18 deletions
|
@ -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.2
|
// @version 2.1.0.3
|
||||||
// @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/*
|
||||||
|
@ -606,6 +606,7 @@
|
||||||
answerGetters,
|
answerGetters,
|
||||||
node
|
node
|
||||||
)
|
)
|
||||||
|
const possibleAnswers = getPossibleAnswers(node)
|
||||||
|
|
||||||
if (!answerPromises || !questionPromises) {
|
if (!answerPromises || !questionPromises) {
|
||||||
log('Answer or question array is empty, skipping question')
|
log('Answer or question array is empty, skipping question')
|
||||||
|
@ -619,14 +620,15 @@
|
||||||
.join(' ')
|
.join(' ')
|
||||||
const answerText = answer.reduce(makeTextFromElements, []).join(' ')
|
const answerText = answer.reduce(makeTextFromElements, []).join(' ')
|
||||||
let images = getImagesFromElements([...question, ...answer])
|
let images = getImagesFromElements([...question, ...answer])
|
||||||
// images = uniq(images)
|
|
||||||
|
|
||||||
resolve({
|
const result = {
|
||||||
Q: removeUnnecesarySpaces(questionText),
|
Q: removeUnnecesarySpaces(questionText),
|
||||||
A: removeUnnecesarySpaces(answerText),
|
A: removeUnnecesarySpaces(answerText),
|
||||||
data: getDataFromResultImages(images),
|
data: getDataFromResultImages(images),
|
||||||
success: true,
|
success: true,
|
||||||
})
|
}
|
||||||
|
result.data.possibleAnswers = possibleAnswers
|
||||||
|
resolve(result)
|
||||||
})
|
})
|
||||||
.catch(err => {
|
.catch(err => {
|
||||||
warn('Error in getQuizFromNode()')
|
warn('Error in getQuizFromNode()')
|
||||||
|
@ -637,17 +639,17 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDataFromResultImages(images) {
|
function getDataFromResultImages(images) {
|
||||||
if (!images || images.length === 0) {
|
if (images && images.length > 0) {
|
||||||
return {
|
|
||||||
type: 'simple',
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return {
|
return {
|
||||||
type: 'image',
|
type: 'image',
|
||||||
hashedImages: images.map(x => {
|
hashedImages: images.map(x => {
|
||||||
return x.val
|
return x.val
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
type: 'simple',
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -698,6 +700,11 @@
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
const state = node.getElementsByClassName('state')[0]
|
||||||
|
// TODO: what if in english
|
||||||
|
if (state && state.innerText === 'Hibás') {
|
||||||
|
return false
|
||||||
|
}
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
type: 'txt',
|
type: 'txt',
|
||||||
|
@ -758,10 +765,14 @@
|
||||||
selectedByUser = answerNode.childNodes[0].checked
|
selectedByUser = answerNode.childNodes[0].checked
|
||||||
}
|
}
|
||||||
|
|
||||||
acc.push({
|
const text = removeUnnecesarySpaces(answerNode.innerText)
|
||||||
text: answerNode.innerText,
|
|
||||||
selectedByUser: selectedByUser,
|
if (text !== '') {
|
||||||
})
|
acc.push({
|
||||||
|
text: text,
|
||||||
|
selectedByUser: selectedByUser,
|
||||||
|
})
|
||||||
|
}
|
||||||
return acc
|
return acc
|
||||||
}, [])
|
}, [])
|
||||||
}
|
}
|
||||||
|
@ -1254,7 +1265,7 @@
|
||||||
}
|
}
|
||||||
if (!installedFromCorrectSource(correctSource)) {
|
if (!installedFromCorrectSource(correctSource)) {
|
||||||
greetMsg.push(texts.reinstallFromCorrectSource)
|
greetMsg.push(texts.reinstallFromCorrectSource)
|
||||||
console.log(`update url:${info().script.updateURL}`)
|
log(`update url:${info().script.updateURL}`)
|
||||||
}
|
}
|
||||||
if (showMOTD) {
|
if (showMOTD) {
|
||||||
greetMsg.push(texts.motd + motd)
|
greetMsg.push(texts.motd + motd)
|
||||||
|
@ -2270,9 +2281,9 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logHelper(logMethod, value) {
|
function logHelper(logMethod, ...value) {
|
||||||
if (logEnabled) {
|
if (logEnabled) {
|
||||||
logMethod('[Moodle Script]: ', value)
|
logMethod('[Moodle Script]: ', ...value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2280,8 +2291,8 @@
|
||||||
logHelper(console.warn, value)
|
logHelper(console.warn, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function log(value) {
|
function log() {
|
||||||
logHelper(console.log, value)
|
logHelper(console.log, ...arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
function Exception(e, msg) {
|
function Exception(e, msg) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue