Opening error page now passes question as query, and autofills question search field on site

This commit is contained in:
mrfry 2020-11-07 14:38:35 +01:00
parent 146e352411
commit 37b7d43115

View file

@ -84,6 +84,7 @@
// 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!
// only one of these should be true for testing // only one of these should be true for testing
setVal('ISDEVEL', false)
const forceTestPage = false const forceTestPage = false
const forceResultPage = false const forceResultPage = false
const forceDefaultPage = false const forceDefaultPage = false
@ -92,13 +93,13 @@
const motdShowCount = 3 /* Ammount of times to show motd */ const motdShowCount = 3 /* Ammount of times to show motd */
let infoExpireTime = 60 // Every n seconds basic info should be loaded from server let infoExpireTime = 60 // Every n seconds basic info should be loaded from server
var uid = 0
var cid = 0
var motd = '' var motd = ''
var userSpecificMotd = '' var userSpecificMotd = ''
var lastestVersion = '' var lastestVersion = ''
var subjInfo var subjInfo
setVal('ISDEVEL', false)
if (getVal('ISDEVEL')) { if (getVal('ISDEVEL')) {
console.log('Moodle script running in developement mode!') console.log('Moodle script running in developement mode!')
infoExpireTime = 1 infoExpireTime = 1
@ -111,7 +112,7 @@
fatalError: fatalError:
'Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!', 'Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!',
consoleErrorInfo: consoleErrorInfo:
'Itteni hibák 100% a moodle hiba. Kivéve, ha oda van írva hogy script error ;) Ha ilyesmi szerepel itt, akkor olvasd el a segítség szekciót!', 'Itteni hibák 100% a moodle hiba. Kivéve, ha oda van írva hogy script error ;) Ha ilyesmi szerepel itt, akkor olvasd el a segítség szekciót! https://qmining.frylabs.net/manual?scriptcmd',
freshStartWarning: freshStartWarning:
'<h1>Moodle teszt userscript:<h1><h3>1.5.0 verzió: a script mostantól XMLHTTP kéréseket küld szerver fele! Erre a userscript futtató kiegészítőd is figyelmeztetni fog! Ha ez történik, a script rendes működése érdekében engedélyezd (Always allow domain)! Ha nem akarod, hogy ez történjen, akkor ne engedélyezd, vagy a menüben válaszd ki a "helyi fájl használata" opciót!</h3> <h3>Elküldött adatok: minden teszt után a kérdés-válasz páros. Fogadott adatok: Az összes eddig ismert kérdés. Érdemes help-et elolvasni!!!</h3><h5>Ez az ablak frissités után eltűnik. Ha nem, akkor a visza gombbal próbálkozz.</h5>', '<h1>Moodle teszt userscript:<h1><h3>1.5.0 verzió: a script mostantól XMLHTTP kéréseket küld szerver fele! Erre a userscript futtató kiegészítőd is figyelmeztetni fog! Ha ez történik, a script rendes működése érdekében engedélyezd (Always allow domain)! Ha nem akarod, hogy ez történjen, akkor ne engedélyezd, vagy a menüben válaszd ki a "helyi fájl használata" opciót!</h3> <h3>Elküldött adatok: minden teszt után a kérdés-válasz páros. Fogadott adatok: Az összes eddig ismert kérdés. Érdemes help-et elolvasni!!!</h3><h5>Ez az ablak frissités után eltűnik. Ha nem, akkor a visza gombbal próbálkozz.</h5>',
noResult: noResult:
@ -574,6 +575,13 @@
} }
} }
getAsd() {
const a = document.getElementsByClassName('generalfeedback')
if (a.length > 0) {
return a[0].innerText
}
}
GetCurrentAnswer(i) { GetCurrentAnswer(i) {
if (logElementGetting) { if (logElementGetting) {
Log('getting curr answer by index: ' + i) Log('getting curr answer by index: ' + i)
@ -757,6 +765,14 @@
GetRightAnswerFromResult(i) { GetRightAnswerFromResult(i) {
var fun = [] var fun = []
// Ugrás... fix: textarea-ban kell válaszolni
// TODO
// fun.push(i => {
// const a = RPM.getAsd()
// console.log(a)
// return a
// })
// "húzza oda ..." skip // "húzza oda ..." skip
fun.push(i => { fun.push(i => {
let temp = RPM.GetAnswersFromGrabBox(i) let temp = RPM.GetAnswersFromGrabBox(i)
@ -1162,9 +1178,11 @@
motd = inf.motd motd = inf.motd
userSpecificMotd = inf.userSpecificMotd userSpecificMotd = inf.userSpecificMotd
subjInfo = inf.subjinfo subjInfo = inf.subjinfo
uid = inf.uid
cid = getVal('clientId')
overlay.querySelector( overlay.querySelector(
'#infoMainDiv' '#infoMainDiv'
).innerText = `${subjInfo.subjects} tárgy, ${subjInfo.questions} kérdés. Felh #${inf.uid}` ).innerText = `${subjInfo.subjects} tárgy, ${subjInfo.questions} kérdés. Felh #${uid}`
// FIXME: if cwith() throws an unhandled error it sais server is not avaible // FIXME: if cwith() throws an unhandled error it sais server is not avaible
cwith() cwith()
}) })
@ -1328,7 +1346,6 @@
) )
}) })
// FIXME: promise.all promise resolve order same as original?
Promise.all(promises).then(res => { Promise.all(promises).then(res => {
let answers = [] let answers = []
@ -1391,7 +1408,9 @@
function() { function() {
OpenErrorPage({ OpenErrorPage({
message: 'No result found', message: 'No result found',
stack: JSON.stringify(question), question: Array.isArray(question)
? question[0].replace(/"/g, '').replace(/:/g, '')
: question,
}) })
} }
) )
@ -2367,24 +2386,20 @@
} }
function OpenErrorPage(e) { function OpenErrorPage(e) {
let path = 'lred' const queries = []
try { try {
if (e.message || e.stack) { Object.keys(e).forEach(key => {
path += '?' if (e[key]) {
} queries.push(`${key}=${encodeURIComponent(e[key])}`)
if (e.message) { }
path += 'msg:' + SUtils.SimplifyQuery(e.message) })
} queries.push('version=' + encodeURIComponent(info().script.version))
if (e.stack) { queries.push('uid=' + encodeURIComponent(uid))
path += '___stack:' + SUtils.SimplifyStack(e.stack) queries.push('cid=' + encodeURIComponent(cid))
}
path += '___version:' + info().script.version
path = SUtils.RemoveSpecialChars(path)
} catch (e) { } catch (e) {
Exception(e, 'error at setting error stack/msg link') Exception(e, 'error at setting error stack/msg link')
} }
path = path.replace(/ /g, '_') openInTab(serverAdress + 'lred?' + queries.join('&'), {
openInTab(serverAdress + path, {
active: true, active: true,
}) })
} }