mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Showing answer
This commit is contained in:
parent
e7871a5ba9
commit
566321eed8
1 changed files with 64 additions and 45 deletions
109
stable.user.js
109
stable.user.js
|
@ -223,33 +223,57 @@
|
|||
// ----------------------------------------------------------------------------------------------
|
||||
|
||||
function handleQuiz() {
|
||||
// TODO: dropdown in question
|
||||
// TODO: multiple selects, img in question
|
||||
// TODO:
|
||||
const promises = []
|
||||
const subjName = getCurrentSubjectName()
|
||||
const questionNodes = Array.from(
|
||||
document.getElementsByTagName('form')[0].childNodes[0].childNodes
|
||||
)
|
||||
getQuizData().then(res => {
|
||||
const promises = []
|
||||
|
||||
let i = 0
|
||||
while (
|
||||
i < questionNodes.length &&
|
||||
questionNodes[i].tagName === 'DIV' &&
|
||||
questionNodes[i].className !== 'submitbtns'
|
||||
) {
|
||||
promises.push(getQuestionPromiseForSingleQuestion(questionNodes[i]))
|
||||
i++
|
||||
}
|
||||
res.forEach(question => {
|
||||
promises.push(
|
||||
GetXHRQuestionAnswer({
|
||||
q: question.question,
|
||||
data: question.data,
|
||||
subj: getCurrentSubjectName(),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
Promise.all(promises)
|
||||
.then(res => {
|
||||
console.log(res)
|
||||
})
|
||||
.catch(err => {
|
||||
console.warn('Error in handleQuiz()')
|
||||
console.warn(err)
|
||||
Promise.all(promises).then(res => {
|
||||
const answers = res.map(result => {
|
||||
return PrepareAnswers(result)
|
||||
})
|
||||
|
||||
// TODO: new lines in answers
|
||||
ShowAnswers(answers, res[0].question)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function getQuizData() {
|
||||
return new Promise(resolve => {
|
||||
// TODO: dropdown in question
|
||||
const promises = []
|
||||
const questionNodes = Array.from(
|
||||
document.getElementsByTagName('form')[0].childNodes[0].childNodes
|
||||
)
|
||||
|
||||
let i = 0
|
||||
while (
|
||||
i < questionNodes.length &&
|
||||
questionNodes[i].tagName === 'DIV' &&
|
||||
questionNodes[i].className !== 'submitbtns'
|
||||
) {
|
||||
promises.push(getQuestionPromiseForSingleQuestion(questionNodes[i]))
|
||||
i++
|
||||
}
|
||||
|
||||
Promise.all(promises)
|
||||
.then(res => {
|
||||
resolve(res)
|
||||
})
|
||||
.catch(err => {
|
||||
console.warn('Error in handleQuiz()')
|
||||
console.warn(err)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function getPossibleAnswersFromTest(node) {
|
||||
|
@ -1158,34 +1182,29 @@
|
|||
// : Answering stuffs {{{
|
||||
|
||||
// TODO
|
||||
function PrepareAnswers(result, j) {
|
||||
function PrepareAnswers(result) {
|
||||
assert(result)
|
||||
|
||||
if (result.length > 0) {
|
||||
var allMessages = [] // preparing all messages
|
||||
for (var k = 0; k < result.length; k++) {
|
||||
var msg = '' // the current message
|
||||
if (getVal('showQuestions') === undefined || getVal('showQuestions')) {
|
||||
msg += result[k].q.Q + '\n' // adding the question if yes
|
||||
}
|
||||
msg += result[k].q.A.replace(/, /g, '\n') // adding answer
|
||||
if (result[k].q.data.type === 'image') {
|
||||
return result.map(res => {
|
||||
let msg = res.q.Q + '\n'
|
||||
|
||||
// TODO: remove this maybe?
|
||||
msg += res.q.A.replace(/, /g, '\n') // adding answer
|
||||
|
||||
if (res.q.data.type === 'image') {
|
||||
msg +=
|
||||
'\n\nKépek fenti válaszok sorrendjében: ' +
|
||||
result[k].q.data.images.join(', ') // if it has image part, adding that too
|
||||
res.q.data.images.join(', ') // if it has image part, adding that too
|
||||
}
|
||||
if (
|
||||
result[k].detailedMatch &&
|
||||
result[k].detailedMatch.matchedSubjName
|
||||
) {
|
||||
msg += '\n(Tárgy: ' + result[k].detailedMatch.matchedSubjName + ')'
|
||||
}
|
||||
allMessages.push({
|
||||
|
||||
msg += '\n(Tárgy: ' + res.detailedMatch.matchedSubjName + ')'
|
||||
|
||||
return {
|
||||
m: msg,
|
||||
p: result[k].match,
|
||||
})
|
||||
}
|
||||
return allMessages
|
||||
p: res.match,
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue