From 73d465213c1b49dc533ed2b4a5eed9fb924b26c8 Mon Sep 17 00:00:00 2001 From: MrFry Date: Fri, 10 Jan 2020 12:06:57 +0100 Subject: [PATCH] image comparing fix --- stable.user.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/stable.user.js b/stable.user.js index 9d783c0..9d5f6d0 100644 --- a/stable.user.js +++ b/stable.user.js @@ -43,6 +43,7 @@ // TODO: // test select boxes on result page // dragboxes test on quiz page +// image in questions sorted ! (function() { // eslint-disable-line // GM functions, only to disable ESLINT errors @@ -253,7 +254,13 @@ constructor (q, a, i) { this.Q = SUtils.SimplifyQuestion(q) this.A = SUtils.SimplifyAnswer(a) - this.I = i + try { + this.I = JSON.parse(i).sort((a, b) => { + return a > b + }) + } catch (e) { + this.I = i + } } toString () { @@ -298,8 +305,7 @@ const qmatchpercent = SUtils.CompareString(this.Q, q2.Q) const amatchpercent = SUtils.CompareString(this.A, q2.A) if (this.I !== undefined) { - const imatchpercent = this.I === undefined ? SUtils.CompareString(this.I.join(' '), q2.I.join( - ' ')) : 0 + const imatchpercent = q2.I === undefined ? 0 : SUtils.CompareString(this.I.join(' '), q2.I.join(' ')) return (qmatchpercent + amatchpercent + imatchpercent) / 3 } else { return (qmatchpercent + amatchpercent) / 2 @@ -674,7 +680,7 @@ return r } - TestIfQuestionIsGrabBox (i) { + GetAnswersFromGrabBox (i) { if (logElementGetting) { Log('testing if question is grab-box') } let results = this.GetFormResult() // getting results element let t = results[i].getElementsByClassName('dragitems')[0].childNodes @@ -770,7 +776,7 @@ // "hĂșzza oda ..." skip fun.push((i) => { - let temp = RPM.TestIfQuestionIsGrabBox(i) + let temp = RPM.GetAnswersFromGrabBox(i) console.log('GRABBOX TEST') console.log(temp) return temp.map((x) => { @@ -1327,6 +1333,8 @@ function SearchSameQuestion (questionData, quiz, i) { var r = questionData.Search(quiz[i]) + console.log(quiz[i], r) // TODO: remove + let count = 0 r.forEach((item) => { if (item.match > minResultMatchPercent) { @@ -1377,7 +1385,8 @@ toAdd += '?' + SUtils.RemoveUnnecesarySpaces(quiz[i].Q) + '\n' // adding quiz question toAdd += '!' + SUtils.RemoveUnnecesarySpaces(quiz[i].A) + '\n' // adding quiz answer if (quiz[i].HasImage()) { - toAdd += '>' + SUtils.RemoveUnnecesarySpaces(quiz[i].I) + '\n' // adding quiz image if there is any + let imgString = typeof quiz[i].I === 'string' ? quiz[i].I : JSON.stringify(quiz[i].I) + toAdd += '>' + imgString + '\n' // adding quiz image if there is any } if (SearchSameQuestion(questionData, quiz, i) === -1) { output += toAdd // adding to output