mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Removed old school question parsing, minor code clean
This commit is contained in:
parent
e13d18ec9c
commit
a445512234
1 changed files with 6 additions and 121 deletions
127
main.js
127
main.js
|
@ -663,15 +663,6 @@ class ResultsPageModell {
|
|||
return this.GetFormCFOfResult(results[i]).getElementsByTagName('img')
|
||||
}
|
||||
|
||||
GetOnlyImageQuestionResult (i) {
|
||||
console.log('############################################################')
|
||||
console.log(i)
|
||||
const results = this.GetFormResult() // getting results element
|
||||
const n = results[i]
|
||||
console.log(n)
|
||||
console.log('############################################################')
|
||||
}
|
||||
|
||||
// gets the question from the result page
|
||||
// i is the index of the question
|
||||
GetQuestionFromResult (i) {
|
||||
|
@ -720,11 +711,6 @@ class ResultsPageModell {
|
|||
if (RPM.GetDropboxes(i).length > 0) { return RPM.GetCurrentAnswer(i) }
|
||||
})
|
||||
|
||||
// image and text only question
|
||||
fun.push(function TryGet5 (i) {
|
||||
return RPM.GetOnlyImageQuestionResult(i)
|
||||
})
|
||||
|
||||
// if the correct answers are not shown, and the selected answer
|
||||
// is correct
|
||||
fun.push(function TryGet2 (i) {
|
||||
|
@ -1008,103 +994,6 @@ function ReadNetDB (cwith, useNetDB) {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a question database from the given data.
|
||||
* Parameter should be raw read file in string with "\n"-s
|
||||
* */
|
||||
function ParseRawData (data) {
|
||||
const d = data.split('\n')
|
||||
const r = new QuestionDB()
|
||||
var logs = []
|
||||
var currSubj = '' // the current subjects name
|
||||
var ExpectedIdentifier = ['+', '?']
|
||||
let currQuestion = new Question()
|
||||
|
||||
var i = -1
|
||||
while (i < d.length) {
|
||||
let currIdentifier
|
||||
let skipped = 0
|
||||
do {
|
||||
if (skipped >= 1) { logs.push(i + ': ' + d[i]) }
|
||||
i++
|
||||
if (i >= d.length) {
|
||||
if (currQuestion.IsComplete()) { r.AddQuestion(currSubj, currQuestion) }
|
||||
return {
|
||||
result: r,
|
||||
logs: logs
|
||||
}
|
||||
}
|
||||
currIdentifier = d[i][0]
|
||||
skipped++
|
||||
} while (!ExpectedIdentifier.includes(currIdentifier) && i < d.length)
|
||||
|
||||
let currData = d[i].substring(1).trim()
|
||||
|
||||
if (currIdentifier === '+') {
|
||||
if (currQuestion.IsComplete()) { r.AddQuestion(currSubj, currQuestion) }
|
||||
currQuestion = new Question()
|
||||
currSubj = currData
|
||||
ExpectedIdentifier = ['?']
|
||||
continue
|
||||
}
|
||||
|
||||
if (currIdentifier === '?') {
|
||||
if (currQuestion.IsComplete()) {
|
||||
r.AddQuestion(currSubj, currQuestion)
|
||||
currQuestion = new Question()
|
||||
}
|
||||
// overwriting is allowed here, bcus:
|
||||
// ?????!>
|
||||
currQuestion.Q = currData
|
||||
ExpectedIdentifier = ['!', '?']
|
||||
continue
|
||||
}
|
||||
|
||||
if (currIdentifier === '!') {
|
||||
// if dont have question continue
|
||||
if (!currQuestion.HasQuestion()) {
|
||||
throw 'No question! (A)' // eslint-disable-line
|
||||
}
|
||||
// dont allow overwriting
|
||||
// ?!!!!
|
||||
if (!currQuestion.HasAnswer()) {
|
||||
currData = currData.replace('A helyes válaszok: ', '')
|
||||
currData = currData.replace('A helyes válasz: ', '')
|
||||
|
||||
currQuestion.A = currData
|
||||
}
|
||||
ExpectedIdentifier = ['?', '>', '+']
|
||||
continue
|
||||
}
|
||||
|
||||
if (currIdentifier === '>') {
|
||||
// if dont have question or answer continue
|
||||
if (!currQuestion.HasQuestion()) {
|
||||
throw 'No question! (I)' // eslint-disable-line
|
||||
}
|
||||
if (!currQuestion.HasAnswer()) {
|
||||
throw 'No asnwer! (I)' // eslint-disable-line
|
||||
}
|
||||
// dont allow overwriting
|
||||
// ?!>>>
|
||||
if (!currQuestion.HasImage()) {
|
||||
try {
|
||||
currQuestion.I = JSON.parse(currData)
|
||||
} catch (e) {
|
||||
currQuestion.I = currData.split(',')
|
||||
}
|
||||
}
|
||||
ExpectedIdentifier = ['?', '+']
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
result: r,
|
||||
logs: logs
|
||||
}
|
||||
}
|
||||
|
||||
function Load (cwith) {
|
||||
var useNetDB = getVal('useNetDB')
|
||||
let skipLoad = getVal('skipLoad')
|
||||
|
@ -1147,16 +1036,12 @@ function NLoad (resource, cwith) {
|
|||
d = JSON.parse(resource)
|
||||
} catch (e) {
|
||||
Log('Old data, trying with old methods....')
|
||||
try {
|
||||
d = ParseRawData(resource).result
|
||||
} catch (e2) {
|
||||
Log('Couldt parse data!')
|
||||
ShowMessage({
|
||||
m: 'Nem sikerült betölteni az adatokat! Ellenőriz a megadott fájlt, vagy az internetelérésed!',
|
||||
isSimple: true
|
||||
})
|
||||
return
|
||||
}
|
||||
Log('Couldt parse data!')
|
||||
Log(e)
|
||||
ShowMessage({
|
||||
m: 'Nem sikerült betölteni az adatokat! Kattints a manualért',
|
||||
isSimple: true
|
||||
}, undefined, ShowHelp)
|
||||
}
|
||||
var r = new QuestionDB()
|
||||
var rt = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue