log -> debuglog, information text getter fix

This commit is contained in:
mrfry 2022-05-15 10:23:45 +02:00
parent 58a2fce2fe
commit 03c4064de8

View file

@ -311,13 +311,13 @@
}
})
} catch (e) {
log("Couldn't get images from result (old)")
debugLog("Couldn't get images from result (old)")
}
}
function getCurrentSubjectName() {
if (logElementGetting) {
log('getting current subjects name')
debugLog('getting current subjects name')
}
return document.getElementById('page-header').innerText.split('\n')[0] || ''
}
@ -370,7 +370,7 @@
uid: getUid(),
}
log('Sent data', sentData)
debugLog('Sent data', sentData)
post('ask', sentData).then((results) => {
removeLoadingMessage()
ShowAnswers(
@ -394,7 +394,7 @@
criteria: () => {
const firstChild =
document.getElementsByTagName('form')[1].childNodes[0].childNodes[0]
if (!firstChild.className.includes('informationitem')) {
if (!firstChild || !firstChild.className.includes('informationitem')) {
return false
}
const questionNodes = Array.from(
@ -454,7 +454,7 @@
`question nodes ${key} criteria was true, but result is an empty array!`
)
} else {
log(`Using question node getter variant: ${key}`)
debugLog(`Using question node getter variant: ${key}`)
return true
}
}
@ -741,7 +741,7 @@
`result nodes ${key} criteria was true, but result is an empty array!`
)
} else {
log(`Using question node getter variant: ${key}`)
debugLog(`Using question node getter variant: ${key}`)
return true
}
}
@ -796,13 +796,13 @@
if (getter.requirement(node)) {
try {
res = getter.getterFunction(node)
log(`[Question getter] Using ${key}`)
debugLog(`[Question getter] Using ${key}`)
return true
} catch (e) {
log(`[Question getter] ${key} failed`)
debugLog(`[Question getter] ${key} failed`)
}
} else {
log(`[Question getter] ${key} did not pass`)
debugLog(`[Question getter] ${key} did not pass`)
}
})
@ -823,10 +823,9 @@
const possibleAnswers = getPossibleAnswers(node)
if (!answerPromises || !questionPromises) {
log('Answer or question array is empty, skipping question')
debugLog('Answer or question array is empty, skipping question')
resolve({ success: false })
}
console.log({ node: node, questionPromises: questionPromises, answerPromises: answerPromises, possibleAnswers: possibleAnswers })
Promise.all([
Promise.all(questionPromises),
@ -1123,7 +1122,7 @@
],
}
log(sentData)
debugLog(sentData)
post('isAdding', sentData).then((res) => {
ShowSaveQuizDialog(res.success, sentData, res.totalNewQuestions)
})
@ -1162,13 +1161,13 @@
prevLength = kkerdesElements.length
clearAllMessages()
if (determineCurrentSite() === 'TEST') {
log('AVR: handling test')
debugLog('AVR: handling test')
handleAVRQuiz(url)
} else if (determineCurrentSite() === 'RESULT') {
log('AVR: handling result')
debugLog('AVR: handling result')
HandleAVRResults(url)
} else {
log('AVR: handling UI')
debugLog('AVR: handling UI')
HandleUI()
}
}
@ -1197,7 +1196,7 @@
testUrl: url,
}
log('Sent data', sentData)
debugLog('Sent data', sentData)
post('ask', sentData).then((results) => {
removeLoadingMessage()
ShowAnswers(
@ -1231,14 +1230,14 @@
function getVideo() {
if (logElementGetting) {
log('getting video stuff')
debugLog('getting video stuff')
}
return document.getElementsByTagName('video')[0]
}
function getVideoElement() {
if (logElementGetting) {
log('getting video element')
debugLog('getting video element')
}
return document.getElementById('videoElement').parentNode
}
@ -1416,7 +1415,7 @@
return false // TODO :insert real url
},
action: (url) => {
log('Handling canvas quiz')
debugLog('Handling canvas quiz')
handleCanvasQuiz(url)
},
},
@ -1425,7 +1424,7 @@
return false // TODO :insert real url
},
action: (url) => {
log('Handling canvas results')
debugLog('Handling canvas results')
HandleCanvasResults(url)
},
},
@ -1434,7 +1433,7 @@
return false // TODO :insert real url
},
action: (url) => {
log('Handling canvas default action')
debugLog('Handling canvas default action')
HandleUI(url)
},
},
@ -1462,7 +1461,7 @@
return true // TODO :insert real url
},
action: (url) => {
log('Handling AVR default action')
debugLog('Handling AVR default action')
handleAVRSite(url)
},
},
@ -1477,7 +1476,7 @@
)
},
action: () => {
log('Handling moodle quiz')
debugLog('Handling moodle quiz')
handleMoodleQuiz()
},
},
@ -1489,7 +1488,7 @@
)
},
action: (url) => {
log('Handling moodle results')
debugLog('Handling moodle results')
HandleMoodleResults(url)
},
},
@ -1503,7 +1502,7 @@
)
},
action: (url) => {
log('Handling moodle default action')
debugLog('Handling moodle default action')
HandleUI(url)
},
},
@ -1520,7 +1519,7 @@
matcher.matchString === 'default' ||
matcher.matchString.includes(forcedMatchString)
) {
log(`trying '${matcher.matchString}'`)
debugLog(`trying '${matcher.matchString}'`)
if (matcher.testPage && matcher.testPage.match(url)) {
matcher.testPage.action(url)
return true
@ -1877,7 +1876,7 @@
// }
// }>
function ShowAnswers(results) {
log(results)
debugLog(results)
try {
const answers = results.reduce((acc, res) => {
const prepared = PrepareAnswers(res)
@ -1971,9 +1970,9 @@
sentData.subj = getCurrentSubjectName()
} catch (e) {
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) => {
ShowSaveQuizDialog(res.success, sentData, res.totalNewQuestions)
})
@ -2031,8 +2030,8 @@
installSource: info().script.updateURL,
})
} catch (err) {
warn('Unexpected error while registering script')
log(err)
debugLog('Unexpected error while registering script')
debugLog(err)
}
}
@ -2065,8 +2064,8 @@
video.currentTime -= seekTime
}
} catch (err) {
log('Hotkey error.')
log(err.message)
debugLog('Hotkey error.')
debugLog(err.message)
}
})
var toadd = getVideoElement()
@ -2678,6 +2677,12 @@
logHelper(console.log, ...arguments)
}
function debugLog() {
if (isDevel) {
logHelper(console.log, ...arguments)
}
}
function Exception(e, msg) {
log('------------------------------------------')
log(msg)