mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
information wrapper
This commit is contained in:
parent
d213f2516b
commit
58a2fce2fe
1 changed files with 29 additions and 5 deletions
|
@ -116,7 +116,7 @@
|
||||||
// Devel vars
|
// Devel vars
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
// forcing pages for testing. unless you test, do not set these to true!
|
// forcing pages for testing. unless you test, do not set these to true!
|
||||||
const isDevel = false
|
const isDevel = true
|
||||||
const forcedMatchString = isDevel ? 'default' : null
|
const forcedMatchString = isDevel ? 'default' : null
|
||||||
// only one of these should be true for testing
|
// only one of these should be true for testing
|
||||||
const forceTestPage = isDevel && false
|
const forceTestPage = isDevel && false
|
||||||
|
@ -390,6 +390,26 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const questionNodeVariants = {
|
const questionNodeVariants = {
|
||||||
|
hasInformationText: {
|
||||||
|
criteria: () => {
|
||||||
|
const firstChild =
|
||||||
|
document.getElementsByTagName('form')[1].childNodes[0].childNodes[0]
|
||||||
|
if (!firstChild.className.includes('informationitem')) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
const questionNodes = Array.from(
|
||||||
|
document.getElementsByTagName('form')[1].childNodes[0].childNodes
|
||||||
|
)
|
||||||
|
return questionNodes.length > 0
|
||||||
|
},
|
||||||
|
getter: () => {
|
||||||
|
return Array.from(
|
||||||
|
document.getElementsByTagName('form')[1].childNodes[0].childNodes
|
||||||
|
).filter((node) => {
|
||||||
|
return !node.className.includes('informationitem')
|
||||||
|
})
|
||||||
|
},
|
||||||
|
},
|
||||||
formFirst: {
|
formFirst: {
|
||||||
criteria: () => {
|
criteria: () => {
|
||||||
const questionNodes = Array.from(
|
const questionNodes = Array.from(
|
||||||
|
@ -434,6 +454,7 @@
|
||||||
`question nodes ${key} criteria was true, but result is an empty array!`
|
`question nodes ${key} criteria was true, but result is an empty array!`
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
log(`Using question node getter variant: ${key}`)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -720,6 +741,7 @@
|
||||||
`result nodes ${key} criteria was true, but result is an empty array!`
|
`result nodes ${key} criteria was true, but result is an empty array!`
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
log(`Using question node getter variant: ${key}`)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -774,12 +796,13 @@
|
||||||
if (getter.requirement(node)) {
|
if (getter.requirement(node)) {
|
||||||
try {
|
try {
|
||||||
res = getter.getterFunction(node)
|
res = getter.getterFunction(node)
|
||||||
|
log(`[Question getter] Using ${key}`)
|
||||||
return true
|
return true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(`${key} failed`)
|
log(`[Question getter] ${key} failed`)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log(`${key} did not pass`)
|
log(`[Question getter] ${key} did not pass`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -803,6 +826,7 @@
|
||||||
log('Answer or question array is empty, skipping question')
|
log('Answer or question array is empty, skipping question')
|
||||||
resolve({ success: false })
|
resolve({ success: false })
|
||||||
}
|
}
|
||||||
|
console.log({ node: node, questionPromises: questionPromises, answerPromises: answerPromises, possibleAnswers: possibleAnswers })
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
Promise.all(questionPromises),
|
Promise.all(questionPromises),
|
||||||
|
@ -825,12 +849,12 @@
|
||||||
resolve(result)
|
resolve(result)
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
warn('Error in getQuizFromNode()')
|
warn('Error in getQuizFromNode() (creating question)')
|
||||||
warn(err)
|
warn(err)
|
||||||
resolve({ success: false })
|
resolve({ success: false })
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
warn('Error in getQuizFromNode()!')
|
warn('Error in getQuizFromNode() (creating promises)')
|
||||||
warn(e)
|
warn(e)
|
||||||
warn(node)
|
warn(node)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue