diff --git a/stable.user.js b/stable.user.js index 4605e20..c18557d 100755 --- a/stable.user.js +++ b/stable.user.js @@ -20,6 +20,7 @@ ------------------------------------------------------------------------- */ +// : Script header {{{ // ==UserScript== // @name Moodle/Elearning/KMOOC test help // @version 2.1.0.0 @@ -47,6 +48,7 @@ // @namespace https://qmining.frylabs.net // @updateURL https://qmining.frylabs.net/moodle-test-userscript/stable.user.js?up // ==/UserScript== +// : }}} ;(function() { // : ESLINT bs {{{ @@ -122,13 +124,13 @@ const huTexts = { fatalError: - 'Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!', + 'Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez! (új böngésző tab-ban)', consoleErrorInfo: 'Itteni hibák 100% a moodle hiba. Kivéve, ha oda van írva hogy script error ;) Ha ilyesmi szerepel itt, akkor olvasd el a segítség szekciót! https://qmining.frylabs.net/manual?scriptcmd', freshStartWarning: '

Moodle teszt userscript:

1.5.0 verzió: a script mostantól XMLHTTP kéréseket küld szerver fele! Erre a userscript futtató kiegészítő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.
', noResult: - 'Nincs találat :( Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!', + 'Nincs találat :( Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez! (új böngésző tab-ban)', videoHelp: 'Miután elindítottad: Play/pause: space. Seek: Bal/jobb nyíl.', menuButtonText: 'Kérdések Menu', couldntLoadDataPopupMenuText: @@ -161,7 +163,7 @@ 'Hiba történt a kérdések beolvasása közben :/ Kattints az üzenetre a manuális kereséshez (új böngésző tab-ban)', loadingAnswer: 'Válaszok betöltése ...', reinstallFromCorrectSource: - 'Scriptet nem a weboldalról raktad fel. PLS reinstall aaaaaaaaa', // TODO: new text + 'Scriptet nem a qmining weboldalról raktad fel. Könnyebb kezelhetőség szempontjából kérlek onnan telepítsd. Részletes leírás', versionUpdated: 'Verzió frissítve ', newVersionAvaible: 'Új verzió elérhető: ', scriptName: 'Moodle/Elearning/KMOOC segéd ', @@ -223,6 +225,33 @@ }, []) } + function oldGetImageFormResult(img) { + try { + var imgURL = [] + for (var j = 0; j < img.length; j++) { + if (!img[j].src.includes('brokenfile')) { + var filePart = img[j].src.split('/') + filePart = filePart[filePart.length - 1] + + // shorten string + var result = '' + var i = 0 + while (i < filePart.length && i < 30) { + result += filePart[i] + i++ + } + + imgURL.push(decodeURI(result)) + } + } + if (imgURL.length > 0) { + return imgURL + } + } catch (e) { + log("Couldn't get images from result (old)") + } + } + function getCurrentSubjectName() { if (logElementGetting) { log('getting current subjects name') @@ -264,22 +293,25 @@ const promises = [] res.forEach(question => { - promises.push( - GetXHRQuestionAnswer({ - q: question.question, - data: question.data, - subj: getCurrentSubjectName(), - }) - ) + const questionObj = { + q: question.question, + data: question.data, + subj: getCurrentSubjectName(), + } + promises.push(GetXHRQuestionAnswer(questionObj)) }) - Promise.all(promises).then(res => { - const answers = res.map(result => { - return PrepareAnswers(result) - }) + Promise.all(promises).then(result => { + const answers = result.reduce((acc, res) => { + const prepared = PrepareAnswers(res) + if (prepared) { + acc.push(prepared) + } + return acc + }, []) removeLoadingMessage() - ShowAnswers(answers, res[0].question) + ShowAnswers(answers) }) }) .catch(err => { @@ -413,6 +445,7 @@ } function getDataFromTest(images) { + console.log(images) if (images.length > 0) { return { type: 'image', @@ -1100,19 +1133,12 @@ } function HandleUI(url) { - var newVersion = false // if the script is newer than last start - - try { - newVersion = info().script.version !== getVal('lastVerson') - } catch (e) { - log('Some weird error trying to set new verison') - } - + const newVersion = info().script.version !== getVal('lastVerson') const showMOTD = shouldShowMotd() const showUserSpecificMOTD = !!userSpecificMotd - - let isNewVersionAvaible = + const isNewVersionAvaible = lastestVersion !== undefined && info().script.version !== lastestVersion + let timeout = null const greetMsg = [] @@ -1154,14 +1180,10 @@ // : Answering stuffs {{{ function PrepareAnswers(result) { - assert(result) - if (result.length > 0) { return result.map(res => { let msg = res.q.Q + '\n' - // TODO: remove this maybe? - // msg += res.q.A.replace(/, /g, '\n') msg += res.q.A if (res.q.data.type === 'image') { @@ -1179,9 +1201,12 @@ } } - function ShowAnswers(answers, question) { + function ShowAnswers(answers) { assert(answers) + // TODO: show which image belongs to which text + + console.log(answers) if (answers.length > 0) { ShowMessage(answers) } else { @@ -1194,9 +1219,9 @@ function() { OpenErrorPage({ message: 'No result found', - question: Array.isArray(question) - ? question[0].replace(/"/g, '').replace(/:/g, '') - : question, + question: Array.isArray(answers[0]) + ? answers[0][0].replace(/"/g, '').replace(/:/g, '') + : answers[0], }) } ) @@ -1626,8 +1651,8 @@ const SetQuestionText = () => { const relevantQuestion = GetRelevantQuestion() - questionTextElement.innerText = relevantQuestion.m headerText.innerText = relevantQuestion.header + questionTextElement.innerText = relevantQuestion.m if (currItem === 0 && currRelevantQuestion === 0) { numberTextBox.innerText = currRelevantQuestion + 1 + '.'