Removing + from questions

This commit is contained in:
MrFry 2019-11-22 14:06:10 +01:00
parent 6cee318903
commit dc3e8f5391

View file

@ -21,7 +21,7 @@
// ==UserScript== // ==UserScript==
// @name Moodle/Elearning/KMOOC test help // @name Moodle/Elearning/KMOOC test help
// @version 1.6.4.7 // @version 1.6.4.8
// @description Online Moodle/Elearning/KMOOC test help // @description Online Moodle/Elearning/KMOOC test help
// @author MrFry // @author MrFry
// @match https://elearning.uni-obuda.hu/main/* // @match https://elearning.uni-obuda.hu/main/*
@ -82,7 +82,8 @@
'The correct answer is:', 'The correct answer is:',
'\'' '\''
] ]
const commonUselessStringParts = [',', '\\.', ':', '!'] const commonUselessStringParts = [',', '\\.', ':', '!', '\\+']
const specialChars = [ '&', '\\+' ]
const lengthDiffMultiplier = 10 /* Percent minus for length difference */ const lengthDiffMultiplier = 10 /* Percent minus for length difference */
const minMatchAmmount = 60 /* Minimum ammount to consider that two questions match during answering */ const minMatchAmmount = 60 /* Minimum ammount to consider that two questions match during answering */
@ -91,10 +92,10 @@
} }
class StringUtils { class StringUtils {
RemoveStuff (value, removableStrings) { RemoveStuff (value, removableStrings, toReplace) {
removableStrings.forEach((x) => { removableStrings.forEach((x) => {
var regex = new RegExp(x, 'g') var regex = new RegExp(x, 'g')
value = value.replace(regex, '') value = value.replace(regex, toReplace || '')
}) })
return value return value
} }
@ -152,7 +153,7 @@
RemoveSpecialChars (value) { RemoveSpecialChars (value) {
assert(value) assert(value)
return this.RemoveStuff(value, ['&']) return this.RemoveStuff(value, specialChars, ' ')
} }
// if the value is empty, or whitespace // if the value is empty, or whitespace
@ -1296,7 +1297,9 @@
let count = 0 let count = 0
r.forEach((item) => { r.forEach((item) => {
if (item.match > minResultMatchPercent) { count++ } if (item.match > minResultMatchPercent) {
count++
}
}) })
return count === 0 ? -1 : count return count === 0 ? -1 : count
@ -1392,12 +1395,12 @@
var question = {} // the current question var question = {} // the current question
// QUESTION -------------------------------------------------------------------------------------------------------------------- // QUESTION --------------------------------------------------------------------------------------------------------------------
var q = RPM.GetQuestionFromResult(i) var q = RPM.GetQuestionFromResult(i)
if (q !== undefined) { question.q = SUtils.SimplifyQuery(q) } if (q !== undefined) { question.q = SUtils.SimplifyQuestion(q) }
// RIGHTANSWER --------------------------------------------------------------------------------------------------------------------- // RIGHTANSWER ---------------------------------------------------------------------------------------------------------------------
var a = RPM.GetRightAnswerFromResultv2(i) var a = RPM.GetRightAnswerFromResultv2(i)
if (a === undefined) { a = RPM.GetRightAnswerFromResult(i) } if (a === undefined) { a = RPM.GetRightAnswerFromResult(i) }
if (a !== undefined) { question.a = SUtils.SimplifyQuery(a) } if (a !== undefined) { question.a = SUtils.SimplifyAnswer(a) }
// IMG --------------------------------------------------------------------------------------------------------------------- // IMG ---------------------------------------------------------------------------------------------------------------------
var img = GetImageFormResult(i) var img = GetImageFormResult(i)
question.i = img question.i = img