mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Variable depth nodes fix
This commit is contained in:
parent
03c4064de8
commit
6213c1a7b8
1 changed files with 37 additions and 18 deletions
|
@ -116,11 +116,11 @@
|
|||
// Devel vars
|
||||
// ------------------------------------------------------------------------------
|
||||
// forcing pages for testing. unless you test, do not set these to true!
|
||||
const isDevel = true
|
||||
const isDevel = false
|
||||
const forcedMatchString = isDevel ? 'default' : null
|
||||
// only one of these should be true for testing
|
||||
const forceTestPage = isDevel && false
|
||||
const forceResultPage = isDevel && true
|
||||
const forceResultPage = isDevel && false
|
||||
const forceDefaultPage = isDevel && false
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
|
@ -218,8 +218,12 @@
|
|||
|
||||
// : Basic processing helpers {{{
|
||||
|
||||
function getTextPromisesFromNode(node) {
|
||||
return Array.from(node.childNodes).reduce((promises, elem) => {
|
||||
function getTextPromisesFromNode(inputNode) {
|
||||
const nodes = Array.from(inputNode.childNodes)
|
||||
.map((x) => flattenNode(x))
|
||||
.flat()
|
||||
|
||||
return nodes.reduce((promises, elem) => {
|
||||
let img = elem
|
||||
if (elem.tagName !== 'IMG') {
|
||||
const t = elem.tagName ? elem.getElementsByTagName('img') : []
|
||||
|
@ -246,6 +250,9 @@
|
|||
}
|
||||
|
||||
if (img.tagName === 'IMG') {
|
||||
if (img.title) {
|
||||
promises.push({ type: 'txt', val: img.title, node: elem })
|
||||
} else {
|
||||
promises.push(
|
||||
new Promise((resolve) => {
|
||||
digestMessage(getBase64Image(img)).then((res) => {
|
||||
|
@ -257,6 +264,7 @@
|
|||
})
|
||||
})
|
||||
)
|
||||
}
|
||||
} else if (elem.tagName === undefined) {
|
||||
promises.push({ type: 'txt', val: elem.nodeValue, node: elem })
|
||||
} else {
|
||||
|
@ -267,6 +275,16 @@
|
|||
}, [])
|
||||
}
|
||||
|
||||
function flattenNode(node) {
|
||||
if (node.childNodes && node.childNodes.length > 0) {
|
||||
return Array.from(node.childNodes)
|
||||
.map((x) => flattenNode(x))
|
||||
.flat()
|
||||
} else {
|
||||
return node
|
||||
}
|
||||
}
|
||||
|
||||
function makeTextFromElements(acc, item) {
|
||||
if (emptyOrWhiteSpace(item.val)) {
|
||||
return acc
|
||||
|
@ -1209,7 +1227,8 @@
|
|||
)
|
||||
})
|
||||
} catch (e) {
|
||||
console.warn(e)
|
||||
debugLog('Error in handleAVRQuiz')
|
||||
debugLog(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1905,8 +1924,8 @@
|
|||
)
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Error showing answers')
|
||||
console.warn(e)
|
||||
debugLog('Error showing answers')
|
||||
debugLog(e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2410,8 +2429,8 @@
|
|||
|
||||
result.msgContainer.child.msgDiv.elem.innerText = getCurrMsg().m
|
||||
} catch (e) {
|
||||
console.warn('Error in message updating')
|
||||
console.warn(e)
|
||||
debugLog('Error in message updating')
|
||||
debugLog(e)
|
||||
}
|
||||
}
|
||||
updateMessageText()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue