Minor logging changes, showing question db name in answer window header

This commit is contained in:
mrfry 2021-01-11 14:47:57 +01:00
parent 0d9f7df3de
commit 76c1492b85

View file

@ -112,7 +112,7 @@
// forcing pages for testing. unless you test, do not set these to true!
setVal('ISDEVEL', true)
// only one of these should be true for testing
const forceTestPage = true
const forceTestPage = false
const forceResultPage = false
const forceDefaultPage = false
@ -128,7 +128,7 @@
const minMessageOpacity = 0.2
let infoExpireTime = 60 // Every n seconds basic info should be loaded from server
var motd = ''
var userSpecificMotd = ''
var userSpecificMotd = {}
var lastestVersion = ''
var subjInfo
@ -138,7 +138,7 @@
const overlayElemUpdateInterval = 2 // seconds
if (getVal('ISDEVEL')) {
console.log('Moodle script running in developement mode!')
log('Moodle script running in developement mode!')
infoExpireTime = 1
serverAdress = 'http://localhost:8080/'
apiAdress = 'http://localhost:8080/'
@ -348,7 +348,7 @@
uid: getUid(),
}
console.log(sentData)
log(sentData)
post('ask', sentData).then(results => {
removeLoadingMessage()
@ -398,8 +398,8 @@
resolve(errorsRemoved)
})
.catch(err => {
console.warn('Error in handleQuiz()')
console.warn(err)
warn('Error in handleQuiz()')
warn(err)
})
})
}
@ -1030,7 +1030,7 @@
idInput.value = getCid()
}
} catch (e) {
console.info('Error filling client ID input', e)
warn('Error filling client ID input', e)
}
try {
const sideLinks = document.getElementById('sideBarLinks')
@ -1050,7 +1050,7 @@
.getElementsByClassName('active')[0]
)
} catch (e) {
console.info('Error filling client ID input', e)
warn('Error filling client ID input', e)
}
}
@ -1066,7 +1066,7 @@
}, 100)
}
} catch (e) {
console.info('Error filling client ID input', e)
warn('Error filling client ID input', e)
}
}
@ -1142,7 +1142,13 @@
}
lastestVersion = inf.version.replace(/\n/g, '')
motd = inf.motd
userSpecificMotd = inf.userSpecificMotd
if (getUid() !== inf.uid) {
setVal('userId', inf.uid)
}
userSpecificMotd = {
show: inf.userShouldGetUserSpecificMOTD,
text: inf.userSpecificMotd,
}
subjInfo = inf.subjinfo
setVal('userId', inf.uid)
overlay.querySelector('#infoMainDiv').innerText = `${
@ -1221,7 +1227,7 @@
function HandleUI(url) {
const newVersion = info().script.version !== getVal('lastVerson')
const showMOTD = shouldShowMotd()
const showUserSpecificMOTD = !!userSpecificMotd
const showUserSpecificMOTD = userSpecificMotd.show
const isNewVersionAvaible =
lastestVersion !== undefined && info().script.version !== lastestVersion
@ -1248,7 +1254,7 @@
timeout = null
}
if (showUserSpecificMOTD) {
greetMsg.push(texts.userMOTD + userSpecificMotd)
greetMsg.push(texts.userMOTD + userSpecificMotd.text)
timeout = null
}
@ -1283,7 +1289,10 @@
return {
m: msg,
p: answer.match,
header: answer.detailedMatch.matchedSubjName,
header:
answer.detailedMatch.matchedSubjName +
' - ' +
answer.detailedMatch.qdb,
}
})
}
@ -1305,7 +1314,7 @@
}
function ShowAnswers(results) {
console.log(results)
log(results)
const answers = results.reduce((acc, res) => {
const prepared = PrepareAnswers(res)
addImageIdsToImageNodes(res.question)
@ -1403,7 +1412,7 @@
sentData.subj = 'NOSUBJ'
log('unable to get subject name :c')
}
console.log('SENT DATA', sentData)
log('SENT DATA', sentData)
post('isAdding', sentData).then(res => {
next(res.success, sentData, res.totalNewQuestions)
})
@ -1445,8 +1454,9 @@
function registerScript() {
try {
// uncomment to re-register again every page refresh
// setVal('registeredWithCid', false)
// setVal('registeredWithUid', true)
// setVal('registeredWithUid', false)
if (getVal('registeredWithCid')) {
if (getVal('registeredWithUid')) {
@ -1466,10 +1476,11 @@
uid: getUid(),
version: info().script.version,
date: new Date(),
installSource: info().script.updateURL,
})
} catch (err) {
console.warn('Unexpected error while registering script')
console.log(err)
warn('Unexpected error while registering script')
log(err)
}
}
@ -1554,7 +1565,7 @@
function addOpacityChangeEvent(elem) {
if (!elem.id) {
console.warn('element must have ID to add opacity change event!')
warn('element must have ID to add opacity change event!')
return
}
@ -2241,11 +2252,7 @@
function logHelper(logMethod, value) {
if (logEnabled) {
if (typeof value === 'string') {
logMethod('[Moodle Script]: ' + value)
} else {
logMethod(value)
}
logMethod('[Moodle Script]: ', value)
}
}
@ -2325,9 +2332,10 @@
lastInfo = JSON.parse(getVal('lastInfo'))
} catch (e) {
if (showErrors) {
console.info(e)
warn(e)
}
}
if (
lastInfo.result !== 'success' ||
now > lastCheck + infoExpireTime * 1000
@ -2353,9 +2361,6 @@
setVal('lastInfoCheckTime', now)
const res = JSON.parse(response.responseText)
setVal('lastInfo', response.responseText)
if (getUid() !== res.uid) {
setVal('userId', res.uid)
}
resolve(res)
} catch (e) {
log('Errro paring JSON in GetXHRInfos')
@ -2384,7 +2389,7 @@
}
function GetXHRQuestionAnswer(question) {
console.log('QUESTIONS', question)
log('QUESTIONS', question)
return new Promise((resolve, reject) => {
let url = apiAdress + 'ask?'
let params = []