mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
log -> debuglog, information text getter fix
This commit is contained in:
parent
58a2fce2fe
commit
03c4064de8
1 changed files with 38 additions and 33 deletions
|
@ -311,13 +311,13 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log("Couldn't get images from result (old)")
|
debugLog("Couldn't get images from result (old)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCurrentSubjectName() {
|
function getCurrentSubjectName() {
|
||||||
if (logElementGetting) {
|
if (logElementGetting) {
|
||||||
log('getting current subjects name')
|
debugLog('getting current subjects name')
|
||||||
}
|
}
|
||||||
return document.getElementById('page-header').innerText.split('\n')[0] || ''
|
return document.getElementById('page-header').innerText.split('\n')[0] || ''
|
||||||
}
|
}
|
||||||
|
@ -370,7 +370,7 @@
|
||||||
uid: getUid(),
|
uid: getUid(),
|
||||||
}
|
}
|
||||||
|
|
||||||
log('Sent data', sentData)
|
debugLog('Sent data', sentData)
|
||||||
post('ask', sentData).then((results) => {
|
post('ask', sentData).then((results) => {
|
||||||
removeLoadingMessage()
|
removeLoadingMessage()
|
||||||
ShowAnswers(
|
ShowAnswers(
|
||||||
|
@ -394,7 +394,7 @@
|
||||||
criteria: () => {
|
criteria: () => {
|
||||||
const firstChild =
|
const firstChild =
|
||||||
document.getElementsByTagName('form')[1].childNodes[0].childNodes[0]
|
document.getElementsByTagName('form')[1].childNodes[0].childNodes[0]
|
||||||
if (!firstChild.className.includes('informationitem')) {
|
if (!firstChild || !firstChild.className.includes('informationitem')) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
const questionNodes = Array.from(
|
const questionNodes = Array.from(
|
||||||
|
@ -454,7 +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}`)
|
debugLog(`Using question node getter variant: ${key}`)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -741,7 +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}`)
|
debugLog(`Using question node getter variant: ${key}`)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -796,13 +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}`)
|
debugLog(`[Question getter] Using ${key}`)
|
||||||
return true
|
return true
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(`[Question getter] ${key} failed`)
|
debugLog(`[Question getter] ${key} failed`)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log(`[Question getter] ${key} did not pass`)
|
debugLog(`[Question getter] ${key} did not pass`)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -823,10 +823,9 @@
|
||||||
const possibleAnswers = getPossibleAnswers(node)
|
const possibleAnswers = getPossibleAnswers(node)
|
||||||
|
|
||||||
if (!answerPromises || !questionPromises) {
|
if (!answerPromises || !questionPromises) {
|
||||||
log('Answer or question array is empty, skipping question')
|
debugLog('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),
|
||||||
|
@ -1123,7 +1122,7 @@
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
log(sentData)
|
debugLog(sentData)
|
||||||
post('isAdding', sentData).then((res) => {
|
post('isAdding', sentData).then((res) => {
|
||||||
ShowSaveQuizDialog(res.success, sentData, res.totalNewQuestions)
|
ShowSaveQuizDialog(res.success, sentData, res.totalNewQuestions)
|
||||||
})
|
})
|
||||||
|
@ -1162,13 +1161,13 @@
|
||||||
prevLength = kkerdesElements.length
|
prevLength = kkerdesElements.length
|
||||||
clearAllMessages()
|
clearAllMessages()
|
||||||
if (determineCurrentSite() === 'TEST') {
|
if (determineCurrentSite() === 'TEST') {
|
||||||
log('AVR: handling test')
|
debugLog('AVR: handling test')
|
||||||
handleAVRQuiz(url)
|
handleAVRQuiz(url)
|
||||||
} else if (determineCurrentSite() === 'RESULT') {
|
} else if (determineCurrentSite() === 'RESULT') {
|
||||||
log('AVR: handling result')
|
debugLog('AVR: handling result')
|
||||||
HandleAVRResults(url)
|
HandleAVRResults(url)
|
||||||
} else {
|
} else {
|
||||||
log('AVR: handling UI')
|
debugLog('AVR: handling UI')
|
||||||
HandleUI()
|
HandleUI()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1197,7 +1196,7 @@
|
||||||
testUrl: url,
|
testUrl: url,
|
||||||
}
|
}
|
||||||
|
|
||||||
log('Sent data', sentData)
|
debugLog('Sent data', sentData)
|
||||||
post('ask', sentData).then((results) => {
|
post('ask', sentData).then((results) => {
|
||||||
removeLoadingMessage()
|
removeLoadingMessage()
|
||||||
ShowAnswers(
|
ShowAnswers(
|
||||||
|
@ -1231,14 +1230,14 @@
|
||||||
|
|
||||||
function getVideo() {
|
function getVideo() {
|
||||||
if (logElementGetting) {
|
if (logElementGetting) {
|
||||||
log('getting video stuff')
|
debugLog('getting video stuff')
|
||||||
}
|
}
|
||||||
return document.getElementsByTagName('video')[0]
|
return document.getElementsByTagName('video')[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
function getVideoElement() {
|
function getVideoElement() {
|
||||||
if (logElementGetting) {
|
if (logElementGetting) {
|
||||||
log('getting video element')
|
debugLog('getting video element')
|
||||||
}
|
}
|
||||||
return document.getElementById('videoElement').parentNode
|
return document.getElementById('videoElement').parentNode
|
||||||
}
|
}
|
||||||
|
@ -1416,7 +1415,7 @@
|
||||||
return false // TODO :insert real url
|
return false // TODO :insert real url
|
||||||
},
|
},
|
||||||
action: (url) => {
|
action: (url) => {
|
||||||
log('Handling canvas quiz')
|
debugLog('Handling canvas quiz')
|
||||||
handleCanvasQuiz(url)
|
handleCanvasQuiz(url)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1425,7 +1424,7 @@
|
||||||
return false // TODO :insert real url
|
return false // TODO :insert real url
|
||||||
},
|
},
|
||||||
action: (url) => {
|
action: (url) => {
|
||||||
log('Handling canvas results')
|
debugLog('Handling canvas results')
|
||||||
HandleCanvasResults(url)
|
HandleCanvasResults(url)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1434,7 +1433,7 @@
|
||||||
return false // TODO :insert real url
|
return false // TODO :insert real url
|
||||||
},
|
},
|
||||||
action: (url) => {
|
action: (url) => {
|
||||||
log('Handling canvas default action')
|
debugLog('Handling canvas default action')
|
||||||
HandleUI(url)
|
HandleUI(url)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1462,7 +1461,7 @@
|
||||||
return true // TODO :insert real url
|
return true // TODO :insert real url
|
||||||
},
|
},
|
||||||
action: (url) => {
|
action: (url) => {
|
||||||
log('Handling AVR default action')
|
debugLog('Handling AVR default action')
|
||||||
handleAVRSite(url)
|
handleAVRSite(url)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1477,7 +1476,7 @@
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
action: () => {
|
action: () => {
|
||||||
log('Handling moodle quiz')
|
debugLog('Handling moodle quiz')
|
||||||
handleMoodleQuiz()
|
handleMoodleQuiz()
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1489,7 +1488,7 @@
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
action: (url) => {
|
action: (url) => {
|
||||||
log('Handling moodle results')
|
debugLog('Handling moodle results')
|
||||||
HandleMoodleResults(url)
|
HandleMoodleResults(url)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1503,7 +1502,7 @@
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
action: (url) => {
|
action: (url) => {
|
||||||
log('Handling moodle default action')
|
debugLog('Handling moodle default action')
|
||||||
HandleUI(url)
|
HandleUI(url)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1520,7 +1519,7 @@
|
||||||
matcher.matchString === 'default' ||
|
matcher.matchString === 'default' ||
|
||||||
matcher.matchString.includes(forcedMatchString)
|
matcher.matchString.includes(forcedMatchString)
|
||||||
) {
|
) {
|
||||||
log(`trying '${matcher.matchString}'`)
|
debugLog(`trying '${matcher.matchString}'`)
|
||||||
if (matcher.testPage && matcher.testPage.match(url)) {
|
if (matcher.testPage && matcher.testPage.match(url)) {
|
||||||
matcher.testPage.action(url)
|
matcher.testPage.action(url)
|
||||||
return true
|
return true
|
||||||
|
@ -1877,7 +1876,7 @@
|
||||||
// }
|
// }
|
||||||
// }>
|
// }>
|
||||||
function ShowAnswers(results) {
|
function ShowAnswers(results) {
|
||||||
log(results)
|
debugLog(results)
|
||||||
try {
|
try {
|
||||||
const answers = results.reduce((acc, res) => {
|
const answers = results.reduce((acc, res) => {
|
||||||
const prepared = PrepareAnswers(res)
|
const prepared = PrepareAnswers(res)
|
||||||
|
@ -1971,9 +1970,9 @@
|
||||||
sentData.subj = getCurrentSubjectName()
|
sentData.subj = getCurrentSubjectName()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
sentData.subj = 'NOSUBJ'
|
sentData.subj = 'NOSUBJ'
|
||||||
log('unable to get subject name :c')
|
debugLog('unable to get subject name :c')
|
||||||
}
|
}
|
||||||
log('SENT DATA', sentData)
|
debugLog('SENT DATA', sentData)
|
||||||
post('isAdding', sentData).then((res) => {
|
post('isAdding', sentData).then((res) => {
|
||||||
ShowSaveQuizDialog(res.success, sentData, res.totalNewQuestions)
|
ShowSaveQuizDialog(res.success, sentData, res.totalNewQuestions)
|
||||||
})
|
})
|
||||||
|
@ -2031,8 +2030,8 @@
|
||||||
installSource: info().script.updateURL,
|
installSource: info().script.updateURL,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
warn('Unexpected error while registering script')
|
debugLog('Unexpected error while registering script')
|
||||||
log(err)
|
debugLog(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2065,8 +2064,8 @@
|
||||||
video.currentTime -= seekTime
|
video.currentTime -= seekTime
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('Hotkey error.')
|
debugLog('Hotkey error.')
|
||||||
log(err.message)
|
debugLog(err.message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
var toadd = getVideoElement()
|
var toadd = getVideoElement()
|
||||||
|
@ -2678,6 +2677,12 @@
|
||||||
logHelper(console.log, ...arguments)
|
logHelper(console.log, ...arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function debugLog() {
|
||||||
|
if (isDevel) {
|
||||||
|
logHelper(console.log, ...arguments)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Exception(e, msg) {
|
function Exception(e, msg) {
|
||||||
log('------------------------------------------')
|
log('------------------------------------------')
|
||||||
log(msg)
|
log(msg)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue