diff --git a/frame.js b/frame.js index 58375ae..8186c33 100644 --- a/frame.js +++ b/frame.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 1.6.4.1 +// @version 1.6.4.3 // @description Online Moodle/Elearning/KMOOC test help // @author MrFry // @match https://elearning.uni-obuda.hu/main/* @@ -36,7 +36,8 @@ // @license GNU General Public License v3.0 or later // @supportURL qmining.frylabs.net // @contributionURL qmining.frylabs.net -// @namespace https://greasyfork.org/users/153067 +// @namespace https://qmining.frylabs.net +// @updateURL https://qmining.frylabs.net/moodle-test-userscript/stable.user.js // ==/UserScript== (function() { diff --git a/main.js b/main.js index 05e58f5..ee33c22 100644 --- a/main.js +++ b/main.js @@ -49,13 +49,9 @@ const motdShowCount = 3 /* Ammount of times to show motd */ var motd = '' var lastestVersion = '' -const minMatchAmmount = 60 /* Minimum ammount to consider that two questions match during answering */ const minResultMatchPercent = 99 /* Minimum ammount to consider that two questions match during saving */ -const lengthDiffMultiplier = 10 /* Percent minus for length difference */ -// ------------------------------------------------------------------------------ -// Other constants -// ------------------------------------------------------------------------------ +// : question-classes {{{ const commonUselessAnswerParts = [ 'A helyes válasz az ', 'A helyes válasz a ', @@ -67,9 +63,12 @@ const commonUselessAnswerParts = [ '\'' ] const commonUselessStringParts = [',', '\\.', ':', '!'] -// ------------------------------------------------------------------------------ +const lengthDiffMultiplier = 10 /* Percent minus for length difference */ +const minMatchAmmount = 60 /* Minimum ammount to consider that two questions match during answering */ -// : Class descriptions {{{ +const assert = (val) => { + if (!val) { throw new Error('Assertion failed') } +} class StringUtils { RemoveStuff (value, removableStrings) { @@ -151,10 +150,7 @@ class StringUtils { } CompareString (s1, s2) { - assert(s1) - assert(s2) - - if (s1 === '' || s2 === '') { + if (!s1 || !s2) { return 0 } @@ -226,6 +222,8 @@ class StringUtils { } } +const SUtils = new StringUtils() + class Question { constructor (q, a, i) { this.Q = SUtils.SimplifyQuestion(q) @@ -373,8 +371,10 @@ class Subject { } class QuestionDB { - constructor () { + constructor (getVal, setVal) { this.Subjects = [] + this.getVal = getVal + this.setVal = setVal } get length () { @@ -384,7 +384,7 @@ class QuestionDB { get activeIndexes () { var r = [] for (var i = 0; i < this.length; i++) { - if (getVal('Is' + i + 'Active')) { + if (this.getVal('Is' + i + 'Active')) { r.push(i) } } @@ -392,11 +392,11 @@ class QuestionDB { } GetIfActive (ind) { - return getVal('Is' + ind + 'Active') + return this.getVal('Is' + ind + 'Active') } ChangeActive (i, value) { - setVal('Is' + i + 'Active', !!value) + this.setVal('Is' + i + 'Active', !!value) } AddQuestion (subj, q) { @@ -452,8 +452,6 @@ class QuestionDB { } } -var SUtils = new StringUtils() - // : }}} // : DOM getting stuff {{{ @@ -1042,7 +1040,7 @@ function NLoad (resource, cwith) { isSimple: true }, undefined, ShowHelp) } - var r = new QuestionDB() + var r = new QuestionDB(getVal, setVal) var rt = [] var allCount = -1 LoadMOTD(d) @@ -2105,10 +2103,6 @@ function SendXHRMessage (message) { }) } -var assert = (val) => { - if (!val) { throw new Error('Assertion failed') } -} - function OpenErrorPage (e) { let path = 'lred' try { diff --git a/stable.user.js b/stable.user.js index c7cd208..20fa7c1 100644 --- a/stable.user.js +++ b/stable.user.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 1.6.4.2 +// @version 1.6.4.3 // @description Online Moodle/Elearning/KMOOC test help // @author MrFry // @match https://elearning.uni-obuda.hu/main/* @@ -36,7 +36,8 @@ // @license GNU General Public License v3.0 or later // @supportURL qmining.frylabs.net // @contributionURL qmining.frylabs.net -// @namespace https://greasyfork.org/users/153067 +// @namespace https://qmining.frylabs.net +// @updateURL https://qmining.frylabs.net/moodle-test-userscript/stable.user.js // ==/UserScript== (function() { @@ -67,13 +68,9 @@ var motd = '' var lastestVersion = '' - const minMatchAmmount = 60 /* Minimum ammount to consider that two questions match during answering */ const minResultMatchPercent = 99 /* Minimum ammount to consider that two questions match during saving */ - const lengthDiffMultiplier = 10 /* Percent minus for length difference */ - // ------------------------------------------------------------------------------ - // Other constants - // ------------------------------------------------------------------------------ + // : question-classes {{{ const commonUselessAnswerParts = [ 'A helyes válasz az ', 'A helyes válasz a ', @@ -85,9 +82,12 @@ '\'' ] const commonUselessStringParts = [',', '\\.', ':', '!'] - // ------------------------------------------------------------------------------ + const lengthDiffMultiplier = 10 /* Percent minus for length difference */ + const minMatchAmmount = 60 /* Minimum ammount to consider that two questions match during answering */ - // : Class descriptions {{{ + const assert = (val) => { + if (!val) { throw new Error('Assertion failed') } + } class StringUtils { RemoveStuff (value, removableStrings) { @@ -169,10 +169,7 @@ } CompareString (s1, s2) { - assert(s1) - assert(s2) - - if (s1 === '' || s2 === '') { + if (!s1 || !s2) { return 0 } @@ -244,6 +241,8 @@ } } + const SUtils = new StringUtils() + class Question { constructor (q, a, i) { this.Q = SUtils.SimplifyQuestion(q) @@ -391,8 +390,10 @@ } class QuestionDB { - constructor () { + constructor (getVal, setVal) { this.Subjects = [] + this.getVal = getVal + this.setVal = setVal } get length () { @@ -402,7 +403,7 @@ get activeIndexes () { var r = [] for (var i = 0; i < this.length; i++) { - if (getVal('Is' + i + 'Active')) { + if (this.getVal('Is' + i + 'Active')) { r.push(i) } } @@ -410,11 +411,11 @@ } GetIfActive (ind) { - return getVal('Is' + ind + 'Active') + return this.getVal('Is' + ind + 'Active') } ChangeActive (i, value) { - setVal('Is' + i + 'Active', !!value) + this.setVal('Is' + i + 'Active', !!value) } AddQuestion (subj, q) { @@ -470,8 +471,6 @@ } } - var SUtils = new StringUtils() - // : }}} // : DOM getting stuff {{{ @@ -1061,7 +1060,7 @@ isSimple: true }, undefined, ShowHelp) } - var r = new QuestionDB() + var r = new QuestionDB(getVal, setVal) var rt = [] var allCount = -1 LoadMOTD(d) @@ -2124,10 +2123,6 @@ }) } - var assert = (val) => { - if (!val) { throw new Error('Assertion failed') } - } - function OpenErrorPage (e) { let path = 'lred' try {