From 5b8ee3fbb8225fb9a11800ae904deed40cad1c92 Mon Sep 17 00:00:00 2001
From: MrFry
Date: Mon, 7 Oct 2019 09:54:46 +0200
Subject: [PATCH 1/9] Removing special characters from strings, and replacig
fixes
---
main.js | 20 +++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)
diff --git a/main.js b/main.js
index 59e08f6..913297a 100644
--- a/main.js
+++ b/main.js
@@ -83,7 +83,7 @@ class StringUtils {
var toremove = this.NormalizeSpaces(val)
var regex = new RegExp(char, 'g')
- toremove.replace(regex, ' ')
+ toremove = toremove.replace(regex, ' ')
return this.RemoveUnnecesarySpaces(toremove)
}
@@ -107,11 +107,21 @@ class StringUtils {
var removableChars = [',', '.', ':', '!']
for (var i = 0; i < removableChars.length; i++) {
var regex = new RegExp(removableChars[i], 'g')
- value.replace(regex, '')
+ value = value.replace(regex, '')
}
return value
}
+ RemoveSpecialChars (value) {
+ assert(value)
+
+ let removableChars = ['&']
+ return removableChars.reduce((res, x) => {
+ let regex = new RegExp(x, 'g')
+ return res.replace(regex, '')
+ }, value)
+ }
+
// if the value is empty, or whitespace
EmptyOrWhiteSpace (value) {
// replaces /n-s with "". then replaces spaces with "". if it equals "", then its empty, or only consists of white space
@@ -146,9 +156,9 @@ class StringUtils {
class Question {
constructor (q, a, i) {
- this.Q = q
- this.A = a
- this.I = i
+ this.Q = SUtils.RemoveSpecialChars(q)
+ this.A = SUtils.RemoveSpecialChars(a)
+ this.I = SUtils.RemoveSpecialChars(i)
}
toString () {
From e13d18ec9c505c0e31e2b25ef681a9d488e5bec2 Mon Sep 17 00:00:00 2001
From: MrFry
Date: Mon, 7 Oct 2019 10:29:22 +0200
Subject: [PATCH 2/9] Question string simplifying
---
main.js | 79 ++++++++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 62 insertions(+), 17 deletions(-)
diff --git a/main.js b/main.js
index 913297a..2b815d8 100644
--- a/main.js
+++ b/main.js
@@ -54,9 +54,31 @@ const minMatchAmmount = 60 /* Minimum ammount to consider that two questions mat
const minResultMatchPercent = 99 /* Minimum ammount to consider that two questions match during saving */
const lengthDiffMultiplier = 10 /* Percent minus for length difference */
+// ------------------------------------------------------------------------------
+// Other constants
+// ------------------------------------------------------------------------------
+const commonUselessAnswerParts = [
+ 'A helyes válasz az ',
+ 'A helyes válasz a ',
+ 'A helyes válaszok: ',
+ 'A helyes válasz: ',
+ 'The correct answer is:',
+ '\''
+]
+const commonUselessStringParts = [',', '.', ':', '!']
+// ------------------------------------------------------------------------------
+
// : Class descriptions {{{
class StringUtils {
+ RemoveStuff (value, removableStrings) {
+ removableStrings.forEach((x) => {
+ var regex = new RegExp(x, 'g')
+ value = value.replace(regex, '')
+ })
+ return value
+ }
+
SimplifyQuery (q) {
assert(q)
@@ -104,22 +126,13 @@ class StringUtils {
assert(value)
value = this.RemoveUnnecesarySpaces(value).toLowerCase()
- var removableChars = [',', '.', ':', '!']
- for (var i = 0; i < removableChars.length; i++) {
- var regex = new RegExp(removableChars[i], 'g')
- value = value.replace(regex, '')
- }
- return value
+ return this.RemoveStuff(value, commonUselessStringParts)
}
RemoveSpecialChars (value) {
assert(value)
- let removableChars = ['&']
- return removableChars.reduce((res, x) => {
- let regex = new RegExp(x, 'g')
- return res.replace(regex, '')
- }, value)
+ return this.RemoveStuff(value, ['&'])
}
// if the value is empty, or whitespace
@@ -152,13 +165,47 @@ class StringUtils {
if (percent < 0) { percent = 0 }
return percent
}
+
+ QuestionPreProcessor (value) {
+ assert(value)
+
+ return this.RemoveStuff(
+ value, commonUselessAnswerParts)
+ }
+
+ // 'a. pécsi sör' -> 'pécsi sör'
+ RemoveAnswerLetters (value) {
+ assert(value)
+
+ let s = value.split('. ')
+ if (s[0].length < 2 && s.length > 1) {
+ return s.shift()
+ } else {
+ return value
+ }
+ }
+
+ SimplifyQuestion (value) {
+ if (!value) { return }
+
+ let mods = [
+ this.RemoveSpecialChars,
+ this.RemoveUnnecesarySpaces,
+ this.QuestionPreProcessor,
+ this.RemoveAnswerLetters
+ ]
+
+ return mods.reduce((res, fn) => {
+ return fn(res)
+ }, value)
+ }
}
class Question {
constructor (q, a, i) {
- this.Q = SUtils.RemoveSpecialChars(q)
- this.A = SUtils.RemoveSpecialChars(a)
- this.I = SUtils.RemoveSpecialChars(i)
+ this.Q = SUtils.SimplifyQuestion(q)
+ this.A = SUtils.SimplifyQuestion(a)
+ this.I = i
}
toString () {
@@ -938,6 +985,7 @@ function ReadFile (cwith) {
}
function ReadNetDB (cwith, useNetDB) {
+ // TODO: params what to get
function NewXMLHttpRequest () {
const url = serverAdress + 'data.json'
xmlhttpRequest({
@@ -1461,9 +1509,6 @@ function GetQuiz () {
var img = GetImageFormResult(i)
question.i = img
- if (q !== undefined) { q = SUtils.ReplaceCharsWithSpace(q, '\n') }
- if (a !== undefined) { a = SUtils.ReplaceCharsWithSpace(a, '\n') }
-
if (question.a !== undefined) {
quiz.push(new Question(question.q, question.a, question.i)) // adding current question to quiz
} else {
From a4455122346a9cae8a78c46296ada0e2f8fdbffe Mon Sep 17 00:00:00 2001
From: MrFry
Date: Mon, 7 Oct 2019 10:33:44 +0200
Subject: [PATCH 3/9] Removed old school question parsing, minor code clean
---
main.js | 127 +++-----------------------------------------------------
1 file changed, 6 insertions(+), 121 deletions(-)
diff --git a/main.js b/main.js
index 2b815d8..59f4f25 100644
--- a/main.js
+++ b/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 = []
From e53ca9d87c57a58be360d4e6e5c2a70cf4a63c82 Mon Sep 17 00:00:00 2001
From: MrFry
Date: Mon, 7 Oct 2019 11:00:26 +0200
Subject: [PATCH 4/9] Added error/stack sending, question simplifying bugfix
---
main.js | 51 ++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 44 insertions(+), 7 deletions(-)
diff --git a/main.js b/main.js
index 59f4f25..cc0f04c 100644
--- a/main.js
+++ b/main.js
@@ -189,15 +189,37 @@ class StringUtils {
if (!value) { return }
let mods = [
- this.RemoveSpecialChars,
- this.RemoveUnnecesarySpaces,
- this.QuestionPreProcessor,
- this.RemoveAnswerLetters
+ this.RemoveSpecialChars.bind(this),
+ this.RemoveUnnecesarySpaces.bind(this),
+ this.QuestionPreProcessor.bind(this),
+ this.RemoveAnswerLetters.bind(this)
]
- return mods.reduce((res, fn) => {
+ const reducer = (res, fn) => {
return fn(res)
- }, value)
+ }
+
+ return mods.reduce(reducer, value)
+ }
+
+ SimplifyStack (stack) {
+ stack = this.SimplifyQuery(stack)
+ let ns = ''
+ let adding = true
+ stack.split('').forEach((c) => {
+ if (c === '(') {
+ adding = false
+ }
+
+ if (adding) {
+ ns += c
+ }
+
+ if (c === ')') {
+ adding = true
+ }
+ })
+ return ns
}
}
@@ -834,10 +856,25 @@ function Main () {
m: 'Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!',
isSimple: true
}, undefined, function () {
- openInTab(serverAdress + 'lred', {
+ let path = 'lred'
+ try {
+ if (e.message || e.stack) {
+ path += '?'
+ }
+ if (e.message) {
+ path += 'msg:' + SUtils.SimplifyQuery(e.message) + '&'
+ }
+ if (e.stack) {
+ path += 'stack:' + SUtils.SimplifyStack(e.stack)
+ }
+ } catch (e) {
+ Exception(e, 'error at setting error stack/msg link')
+ }
+ openInTab(serverAdress + path, {
active: true
})
})
+
Exception(e, 'script error at main:')
}
if (url.includes('eduplayer')) { AddVideoHotkeys(url) } // adding video hotkeys
From ff25bff70e4cfd51fbbac8efce49501b8f00401a Mon Sep 17 00:00:00 2001
From: MrFry
Date: Mon, 7 Oct 2019 11:23:31 +0200
Subject: [PATCH 5/9] Refactored error url generation
---
CHANGELOG | 13 -------------
main.js | 51 +++++++++++++++++++++++++++++----------------------
2 files changed, 29 insertions(+), 35 deletions(-)
delete mode 100644 CHANGELOG
diff --git a/CHANGELOG b/CHANGELOG
deleted file mode 100644
index 8ce9856..0000000
--- a/CHANGELOG
+++ /dev/null
@@ -1,13 +0,0 @@
-1.6.0.0:
- Added JSON data format
- Old one should still work
-1.6.1.0:
- Changed server domain name
- Fixed not found data file "brick"
-1.6.1.5:
- Question answering/getting/parsing improvements
- Passive mode
-1.6.1.6:
- Fixed question saving match percent
-1.6.2.0:
- Document element getting refactoring
diff --git a/main.js b/main.js
index cc0f04c..61db4e1 100644
--- a/main.js
+++ b/main.js
@@ -855,24 +855,8 @@ function Main () {
ShowMessage({
m: 'Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!',
isSimple: true
- }, undefined, function () {
- let path = 'lred'
- try {
- if (e.message || e.stack) {
- path += '?'
- }
- if (e.message) {
- path += 'msg:' + SUtils.SimplifyQuery(e.message) + '&'
- }
- if (e.stack) {
- path += 'stack:' + SUtils.SimplifyStack(e.stack)
- }
- } catch (e) {
- Exception(e, 'error at setting error stack/msg link')
- }
- openInTab(serverAdress + path, {
- active: true
- })
+ }, undefined, () => {
+ OpenErrorPage(e)
})
Exception(e, 'script error at main:')
@@ -1228,7 +1212,7 @@ function HandleQuiz () {
if (r !== undefined) { answers.push(r) }
HighLightAnswer(result, j) // highlights the answer for the current result
}
- ShowAnswers(answers)
+ ShowAnswers(answers, q.q)
}
function PrepareAnswers (result, j) {
@@ -1254,7 +1238,7 @@ function PrepareAnswers (result, j) {
}
}
-function ShowAnswers (answers) {
+function ShowAnswers (answers, question) {
assert(answers)
if (answers.length > 0) { // if there are more than 0 answer
@@ -1264,8 +1248,9 @@ function ShowAnswers (answers) {
m: 'Nincs találat :( Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez! Előfordulhat, hogy a tárgyat nem válsztottad ki a menüben.',
isSimple: true
}, undefined, function () {
- openInTab(serverAdress + 'lred', {
- active: true
+ OpenErrorPage({
+ message: 'No result found',
+ stack: question // TODO: test this
})
})
}
@@ -2198,6 +2183,28 @@ var assert = (val) => {
if (!val) { throw new Error('Assertion failed') }
}
+function OpenErrorPage (e) {
+ let path = 'lred'
+ try {
+ if (e.message || e.stack) {
+ path += '?'
+ }
+ if (e.message) {
+ path += 'msg:' + SUtils.SimplifyQuery(e.message) + '&'
+ }
+ if (e.stack) {
+ path += 'stack:' + SUtils.SimplifyStack(e.stack)
+ }
+ path = SUtils.RemoveSpecialChars(path)
+ } catch (e) {
+ Exception(e, 'error at setting error stack/msg link')
+ }
+ path = path.replace(/ /g, '_')
+ openInTab(serverAdress + path, {
+ active: true
+ })
+}
+
// : }}}
// : Help {{{
From a9f9d1951fcead7144adb9e9e1a020d89537b07e Mon Sep 17 00:00:00 2001
From: MrFry
Date: Mon, 7 Oct 2019 11:25:20 +0200
Subject: [PATCH 6/9] Small refractor of throw/errors-s
---
main.js | 9 +++------
1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/main.js b/main.js
index 61db4e1..96b3dfe 100644
--- a/main.js
+++ b/main.js
@@ -949,7 +949,7 @@ function Version15 () {
'Moodle teszt userscript:1.5.0 verzió: a script mostantól XMLHTTP kéréseket küld szerver fele! Erre a userscript futtató kiegészitő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!
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!!!
Ez az ablak frissités után eltűnik. Ha nem, akkor a visza gombbal próbálkozz.
'
)
document.close()
- throw 'something, so this stuff stops' // eslint-disable-line
+ throw new Error('something, so this stuff stops')
}
}
@@ -983,7 +983,7 @@ function ReadFile (cwith) {
return
}
if (SUtils.EmptyOrWhiteSpace(resource)) {
- throw 'data file empty' // eslint-disable-line
+ throw new Error('data file empty')
}
} catch (e) {
Exception(e, 'script error at reading file:')
@@ -1338,10 +1338,7 @@ function GetImageFormResult (i) {
function SaveQuiz (quiz, questionData) {
try {
if (quiz.length === 0) {
- throw { // eslint-disable-line
- message: 'quiz length is zero!',
- stack: 'no stack.'
- }
+ throw new Error('quiz length is zero!')
}
var output = '' // thefinal output
var allOutput = '' // thefinal output with all questions
From aba448fdc2f39bbc76b91d04d1f6e6d770a44935 Mon Sep 17 00:00:00 2001
From: MrFry
Date: Mon, 7 Oct 2019 13:51:57 +0200
Subject: [PATCH 7/9] Regexp fix, error stack sending refactor
---
main.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/main.js b/main.js
index 96b3dfe..be4fd9c 100644
--- a/main.js
+++ b/main.js
@@ -65,7 +65,7 @@ const commonUselessAnswerParts = [
'The correct answer is:',
'\''
]
-const commonUselessStringParts = [',', '.', ':', '!']
+const commonUselessStringParts = [',', '\\.', ':', '!']
// ------------------------------------------------------------------------------
// : Class descriptions {{{
@@ -1250,7 +1250,7 @@ function ShowAnswers (answers, question) {
}, undefined, function () {
OpenErrorPage({
message: 'No result found',
- stack: question // TODO: test this
+ stack: JSON.stringify(question)
})
})
}
@@ -2187,10 +2187,10 @@ function OpenErrorPage (e) {
path += '?'
}
if (e.message) {
- path += 'msg:' + SUtils.SimplifyQuery(e.message) + '&'
+ path += 'msg:' + SUtils.SimplifyQuery(e.message)
}
if (e.stack) {
- path += 'stack:' + SUtils.SimplifyStack(e.stack)
+ path += '___stack:' + SUtils.SimplifyStack(e.stack)
}
path = SUtils.RemoveSpecialChars(path)
} catch (e) {
From 2d0b496f2769fcb2019fd6d76c6c31ac9d84fd1e Mon Sep 17 00:00:00 2001
From: MrFry
Date: Mon, 7 Oct 2019 14:33:46 +0200
Subject: [PATCH 8/9] Removed old school question reading options
---
main.js | 100 +++++++-------------------------------------------------
1 file changed, 12 insertions(+), 88 deletions(-)
diff --git a/main.js b/main.js
index be4fd9c..61688cd 100644
--- a/main.js
+++ b/main.js
@@ -28,7 +28,6 @@ const a = Main
function getVal (name) { return GM_getValue(name) }
function setVal (name, val) { return GM_setValue(name, val) }
function openInTab (address, options) { GM_openInTab(address, options) }
-function getResourceText (name) { return GM_getResourceText(name) }
function xmlhttpRequest (opts) { GM_xmlhttpRequest(opts) }
function info () { return GM_info }
/* eslint-enable */
@@ -943,7 +942,6 @@ function FreshStart () {
function Version15 () {
var version15 = getVal('version15') // if the current run is the frst
if (version15 === undefined || version15 === true) {
- setVal('useNetDB', '1')
setVal('version15', false)
document.write(
'Moodle teszt userscript:1.5.0 verzió: a script mostantól XMLHTTP kéréseket küld szerver fele! Erre a userscript futtató kiegészitő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!
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!!!
Ez az ablak frissités után eltűnik. Ha nem, akkor a visza gombbal próbálkozz.
'
@@ -967,31 +965,7 @@ function Version16 () {
// : }}}
-var GetFileData = () => {
- return getResourceText('data')
-}
-
-function ReadFile (cwith) {
- var resource = ''
- try {
- resource = GetFileData() // getting data from txt
- if (resource === undefined) {
- ShowMessage({
- m: 'Nem lehetett beolvasni a fájlt :c Ellenőrizd az elérési utat, vagy a fájl jogosultságokat',
- isSimple: true
- })
- return
- }
- if (SUtils.EmptyOrWhiteSpace(resource)) {
- throw new Error('data file empty')
- }
- } catch (e) {
- Exception(e, 'script error at reading file:')
- }
- NLoad(resource, cwith)
-}
-
-function ReadNetDB (cwith, useNetDB) {
+function ReadNetDB (cwith) {
// TODO: params what to get
function NewXMLHttpRequest () {
const url = serverAdress + 'data.json'
@@ -1016,7 +990,6 @@ function ReadNetDB (cwith, useNetDB) {
}
function Load (cwith) {
- var useNetDB = getVal('useNetDB')
let skipLoad = getVal('skipLoad')
if (skipLoad) {
@@ -1024,7 +997,7 @@ function Load (cwith) {
return -1
}
- if (useNetDB !== undefined && useNetDB === 1) { return ReadNetDB(cwith, useNetDB) } else { return ReadFile(cwith) }
+ ReadNetDB(cwith)
}
function LoadMOTD (resource) {
@@ -1271,10 +1244,7 @@ function ShowSaveQuizDialog (addedQ, allQ, allOutput, output, sendSuccess, sentD
if (addedQ > 0) {
msg = 'Klikk ide a nyers adatokhoz. ' + addedQ + ' új kérdés!'
- var useNetDB = getVal('useNetDB')
- if (useNetDB !== undefined && useNetDB === 1) {
- if (!sendSuccess) { msg += ' Nem sikerült kérdéseket elküldeni szervernek. Ha gondolod utánanézhetsz.' } else { msg += 'Az új kérdések elküldve.' }
- } else { msg += 'Ne felejtsd el bemásolni a fő txt-be!' }
+ if (!sendSuccess) { msg += ' Nem sikerült kérdéseket elküldeni szervernek. Ha gondolod utánanézhetsz.' } else { msg += 'Az új kérdések elküldve.' }
} else {
msg = 'A kérdőívben nincsen új kérdés. Ha mégis le akarod menteni klikk ide.'
if (!data) { msg += ' Lehet azért, mert nincs kérdés betöltve.' }
@@ -1287,13 +1257,10 @@ function ShowSaveQuizDialog (addedQ, allQ, allOutput, output, sendSuccess, sentD
var towrite = '' + sentData.subj + '
TXT-ben nem szereplő kérdések: ' + addedQ + '/' + allQ + '
' + output.replace(/\n/g, '
') + '
Összes kérdés/válasz:
' + allOutput.replace(
/\n/g, '
')
- var useNetDB = getVal('useNetDB')
- if (useNetDB !== undefined && useNetDB === 1) {
- try {
- towrite += '
Elküldött adatok: ' + JSON.stringify(sentData)
- } catch (e) {
- towrite += 'Elküldött adatok: ' + sentData
- }
+ try {
+ towrite += 'Elküldött adatok: ' + JSON.stringify(sentData)
+ } catch (e) {
+ towrite += 'Elküldött adatok: ' + sentData
}
document.write(towrite)
document.close()
@@ -1370,14 +1337,11 @@ function SaveQuiz (quiz, questionData) {
sentData.subj = 'NOSUBJ'
Log('unable to get subject name :c')
}
- var useNetDB = getVal('useNetDB')
- if (useNetDB !== undefined && useNetDB === 1) {
- sentData.allData = quiz
- sentData.data = newQuestions
- sentData.version = info().script.version
- SendXHRMessage('datatoadd=' + JSON.stringify(sentData))
- sendSuccess = true
- }
+ sentData.allData = quiz
+ sentData.data = newQuestions
+ sentData.version = info().script.version
+ SendXHRMessage('datatoadd=' + JSON.stringify(sentData))
+ sendSuccess = true
} catch (e) {
Exception(e, 'error at sending data to server.')
}
@@ -2046,46 +2010,6 @@ function ShowMenuList () {
CreateNodeWithText(questionTickboxCell, 'Kérdések mutatása válaszhoz', 'span')
- // database mode listbox -----------------------------------------------------------------------------------------------------------------------------
- var databasemodeListboxRow = tbl.insertRow()
- var databasemodeListboxCell = databasemodeListboxRow.insertCell()
-
- var databasemodeListbox = document.createElement('select')
- databasemodeListbox.type = 'checkbox'
- // databasemodeListbox.checked = getVal("showSplash") || false;
- databasemodeListbox.style.position = ''
- // databasemodeListbox.style.background = "white";
- databasemodeListbox.style.left = 10 + 'px'
- databasemodeListbox.style.margin = '5px 5px 5px 5px' // fancy margin
- databasemodeListbox.style.top = menuDiv.offsetHeight + 'px'
-
- var databasemodeListboxText = CreateNodeWithText(questionTickboxCell,
- 'Kérdések beszerzése:', 'span')
- databasemodeListboxCell.appendChild(databasemodeListboxText)
-
- databasemodeListboxCell.appendChild(databasemodeListbox) // adding to main div
-
- databasemodeListbox.addEventListener('change', function (e) {
- // sorry for using selectedindex :c
- setVal('useNetDB', databasemodeListbox.selectedIndex)
- })
-
- var uselocal = document.createElement('option')
- uselocal.text = 'Helyi fájlból (old school)'
- uselocal.value = 2
- databasemodeListbox.add(uselocal, 0)
-
- var usenetsafe = document.createElement('option')
- usenetsafe.text = 'Netről'
- usenetsafe.value = 0
- databasemodeListbox.add(usenetsafe, 1)
-
- var selected = getVal('useNetDB')
- if (selected !== undefined) { databasemodeListbox.selectedIndex = selected }
-
- var databasemodeListboxElement = document.createElement('span') // new paragraph
- databasemodeListboxCell.appendChild(databasemodeListboxElement)
-
// setting up buttons
var buttonRow = tbl.insertRow()
var buttonCell = buttonRow.insertCell()
From d3c93c5b99d5ac0ea816c6dd308058d222ee4fa8 Mon Sep 17 00:00:00 2001
From: MrFry
Date: Mon, 7 Oct 2019 15:34:00 +0200
Subject: [PATCH 9/9] String processing polishing
---
frame.js | 5 ++---
main.js | 41 ++++++++++++++++++++++++++++++-----------
2 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/frame.js b/frame.js
index a979689..647a180 100644
--- a/frame.js
+++ b/frame.js
@@ -2,7 +2,7 @@
Online Moodle/Elearning/KMOOC test help
Greasyfork:
- GitLab:
+ GitLab:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -21,7 +21,7 @@
// ==UserScript==
// @name Moodle/Elearning/KMOOC test help
-// @version 1.6.3.1
+// @version 1.6.4.0
// @description Online Moodle/Elearning/KMOOC test help
// @author MrFry
// @match https://elearning.uni-obuda.hu/main/*
@@ -36,7 +36,6 @@
// @license GNU General Public License v3.0 or later
// @supportURL qmining.frylabs.net
// @contributionURL qmining.frylabs.net
-// @resource data file:///
// @namespace https://greasyfork.org/users/153067
// ==/UserScript==
diff --git a/main.js b/main.js
index 61688cd..ba1d439 100644
--- a/main.js
+++ b/main.js
@@ -34,7 +34,7 @@ function info () { return GM_info }
var data // all data, which is in the resource txt
var addEventListener // add event listener function
-const lastChangeLog = 'Félév szerinti csoportosítás menüben'
+const lastChangeLog = 'Kérdés parsolás bugfixek, old school fálj beolvasás kiszedése, részletesebb hibajelentés és egyéb fixek'
const serverAdress = 'https://qmining.frylabs.net/'
// forcing pages for testing. unless you test, do not set these to true!
@@ -60,7 +60,9 @@ const commonUselessAnswerParts = [
'A helyes válasz az ',
'A helyes válasz a ',
'A helyes válaszok: ',
+ 'A helyes válaszok:',
'A helyes válasz: ',
+ 'A helyes válasz:',
'The correct answer is:',
'\''
]
@@ -152,6 +154,10 @@ class StringUtils {
assert(s1)
assert(s2)
+ if (s1 === '' || s2 === '') {
+ return 0
+ }
+
s1 = this.SimplifyStringForComparison(s1).split(' ')
s2 = this.SimplifyStringForComparison(s2).split(' ')
var match = 0
@@ -165,7 +171,7 @@ class StringUtils {
return percent
}
- QuestionPreProcessor (value) {
+ AnswerPreProcessor (value) {
assert(value)
return this.RemoveStuff(
@@ -184,16 +190,9 @@ class StringUtils {
}
}
- SimplifyQuestion (value) {
+ SimplifyQA (value, mods) {
if (!value) { return }
- let mods = [
- this.RemoveSpecialChars.bind(this),
- this.RemoveUnnecesarySpaces.bind(this),
- this.QuestionPreProcessor.bind(this),
- this.RemoveAnswerLetters.bind(this)
- ]
-
const reducer = (res, fn) => {
return fn(res)
}
@@ -201,6 +200,26 @@ class StringUtils {
return mods.reduce(reducer, value)
}
+ SimplifyAnswer (value) {
+ return this.SimplifyQA(
+ value,
+ [
+ this.RemoveSpecialChars.bind(this),
+ this.RemoveUnnecesarySpaces.bind(this),
+ this.AnswerPreProcessor.bind(this),
+ this.RemoveAnswerLetters.bind(this)
+ ])
+ }
+
+ SimplifyQuestion (value) {
+ return this.SimplifyQA(
+ value,
+ [
+ this.RemoveSpecialChars.bind(this),
+ this.RemoveUnnecesarySpaces.bind(this)
+ ])
+ }
+
SimplifyStack (stack) {
stack = this.SimplifyQuery(stack)
let ns = ''
@@ -225,7 +244,7 @@ class StringUtils {
class Question {
constructor (q, a, i) {
this.Q = SUtils.SimplifyQuestion(q)
- this.A = SUtils.SimplifyQuestion(a)
+ this.A = SUtils.SimplifyAnswer(a)
this.I = i
}