mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Eslint formatting
This commit is contained in:
parent
a05973b6a0
commit
622dc1db31
1 changed files with 123 additions and 204 deletions
323
main.js
323
main.js
|
@ -20,9 +20,20 @@
|
|||
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
/* TODO
|
||||
* remove stuff like "b. answer", "c. answer" ....
|
||||
* */
|
||||
// ------------------------------------------------------------------------------
|
||||
// REMOVE THIS, only to disable ESLINT errors
|
||||
// ------------------------------------------------------------------------------
|
||||
/* eslint-disable */
|
||||
const GM_getValue = 0
|
||||
const GM_info = 0
|
||||
const GM_setValue = 0
|
||||
const GM_xmlhttpRequest = 0
|
||||
const GM_openInTab = 0
|
||||
const GM_getResourceText = 0
|
||||
Main()
|
||||
const location = 0
|
||||
/* eslint-enable */
|
||||
// ------------------------------------------------------------------------------
|
||||
|
||||
var data // all data, which is in the resource txt
|
||||
var addEventListener // add event listener function
|
||||
|
@ -717,14 +728,14 @@ var MPM = new MiscPageModell()
|
|||
// : }}}
|
||||
|
||||
// : Main function {{{
|
||||
function Main () { // eslint-disable-line
|
||||
function Main () {
|
||||
'use strict'
|
||||
console.time('main')
|
||||
|
||||
Init(function (count, subjCount) {
|
||||
var url = location.href // eslint-disable-line
|
||||
var url = location.href
|
||||
|
||||
let skipLoad = GM_getValue('skipLoad') // eslint-disable-line
|
||||
let skipLoad = GM_getValue('skipLoad')
|
||||
if (count === -2 && subjCount === -2 && skipLoad) {
|
||||
if (url.includes('/quiz/') && url.includes('attempt.php')) {
|
||||
ShowMessage({
|
||||
|
@ -747,7 +758,7 @@ function Main () { // eslint-disable-line
|
|||
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 () {
|
||||
GM_openInTab(serverAdress + 'lred', { // eslint-disable-line
|
||||
GM_openInTab(serverAdress + 'lred', {
|
||||
active: true
|
||||
})
|
||||
})
|
||||
|
@ -775,11 +786,11 @@ function Main () { // eslint-disable-line
|
|||
|
||||
function Init (cwith) {
|
||||
if (false) { // eslint-disable-line
|
||||
GM_setValue('version16', undefined) // eslint-disable-line
|
||||
GM_setValue('version15', undefined) // eslint-disable-line
|
||||
GM_setValue('firstRun', undefined) // eslint-disable-line
|
||||
GM_setValue('showQuestions', undefined) // eslint-disable-line
|
||||
GM_setValue('showSplash', undefined) // eslint-disable-line
|
||||
GM_setValue('version16', undefined)
|
||||
GM_setValue('version15', undefined)
|
||||
GM_setValue('firstRun', undefined)
|
||||
GM_setValue('showQuestions', undefined)
|
||||
GM_setValue('showSplash', undefined)
|
||||
}
|
||||
var url = location.href // window location
|
||||
var count = -1 // loaded question count. stays -1 if the load failed.
|
||||
|
@ -844,7 +855,7 @@ function Version15 () {
|
|||
'<h1>Moodle teszt userscript:<h1><h3>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!</h3> <h3>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!!!</h3><h5>Ez az ablak frissités után eltűnik. Ha nem, akkor a visza gombbal próbálkozz.</h5>'
|
||||
)
|
||||
document.close()
|
||||
throw 'something, so this stuff stops'
|
||||
throw 'something, so this stuff stops' // eslint-disable-line
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -862,15 +873,14 @@ function Version16 () {
|
|||
|
||||
function Version161 () {
|
||||
var version161 = GM_getValue('version161') // if the current run is the frst
|
||||
if (version161 == undefined || version161 == true) // if its undefined, or true
|
||||
{
|
||||
if (version161 === undefined || version161 === true) {
|
||||
GM_setValue('useNetDB', '1')
|
||||
GM_setValue('version161', false)
|
||||
document.write(
|
||||
'<h1>Moodle teszt userscript:<h1><h3>1.6.1.0 verzió: Új domain név: qmining.tk. Ha frissíted az oldalt, akkor tampremonkey rá fog kérdezni, hpgy engedélyezed-e a kérdések külését erre az új domain-re. A rendes működés érdekében kattints a "Allow always domain"-gombra</h3>'
|
||||
)
|
||||
document.close()
|
||||
throw 'something, so this stuff stops'
|
||||
throw 'something, so this stuff stops' // eslint-disable-line
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -884,7 +894,7 @@ function ReadFile (cwith) {
|
|||
var resource = ''
|
||||
try {
|
||||
resource = GetFileData() // getting data from txt
|
||||
if (resource == undefined) {
|
||||
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
|
||||
|
@ -892,9 +902,7 @@ function ReadFile (cwith) {
|
|||
return
|
||||
}
|
||||
if (SUtils.EmptyOrWhiteSpace(resource)) {
|
||||
throw {
|
||||
message: 'data file empty'
|
||||
}
|
||||
throw 'data file empty' // eslint-disable-line
|
||||
}
|
||||
} catch (e) {
|
||||
Exception(e, 'script error at reading file:')
|
||||
|
@ -957,7 +965,7 @@ function ParseRawData (data) {
|
|||
|
||||
let currData = d[i].substring(1).trim()
|
||||
|
||||
if (currIdentifier == '+') {
|
||||
if (currIdentifier === '+') {
|
||||
if (currQuestion.IsComplete()) { r.AddQuestion(currSubj, currQuestion) }
|
||||
currQuestion = new Question()
|
||||
currSubj = currData
|
||||
|
@ -965,7 +973,7 @@ function ParseRawData (data) {
|
|||
continue
|
||||
}
|
||||
|
||||
if (currIdentifier == '?') {
|
||||
if (currIdentifier === '?') {
|
||||
if (currQuestion.IsComplete()) {
|
||||
r.AddQuestion(currSubj, currQuestion)
|
||||
currQuestion = new Question()
|
||||
|
@ -977,9 +985,11 @@ function ParseRawData (data) {
|
|||
continue
|
||||
}
|
||||
|
||||
if (currIdentifier == '!') {
|
||||
if (currIdentifier === '!') {
|
||||
// if dont have question continue
|
||||
if (!currQuestion.HasQuestion()) { throw 'No question! (A)' }
|
||||
if (!currQuestion.HasQuestion()) {
|
||||
throw 'No question! (A)' // eslint-disable-line
|
||||
}
|
||||
// dont allow overwriting
|
||||
// ?!!!!
|
||||
if (!currQuestion.HasAnswer()) {
|
||||
|
@ -992,10 +1002,14 @@ function ParseRawData (data) {
|
|||
continue
|
||||
}
|
||||
|
||||
if (currIdentifier == '>') {
|
||||
if (currIdentifier === '>') {
|
||||
// if dont have question or answer continue
|
||||
if (!currQuestion.HasQuestion()) { throw 'No question! (I)' }
|
||||
if (!currQuestion.HasAnswer()) { throw 'No asnwer! (I)' }
|
||||
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()) {
|
||||
|
@ -1025,7 +1039,7 @@ function Load (cwith) {
|
|||
return -1
|
||||
}
|
||||
|
||||
if (useNetDB != undefined && useNetDB == 1) { return ReadNetDB(cwith, useNetDB) } else { return ReadFile(cwith) }
|
||||
if (useNetDB !== undefined && useNetDB === 1) { return ReadNetDB(cwith, useNetDB) } else { return ReadFile(cwith) }
|
||||
}
|
||||
|
||||
function LoadMOTD (resource) {
|
||||
|
@ -1075,7 +1089,7 @@ function NLoad (resource, cwith) {
|
|||
LoadMOTD(d)
|
||||
LoadVersion(d)
|
||||
|
||||
for (var i = 0; i < d.Subjects.length; i++) {
|
||||
for (let i = 0; i < d.Subjects.length; i++) {
|
||||
let s = new Subject(d.Subjects[i].Name)
|
||||
if (GM_getValue('Is' + i + 'Active')) {
|
||||
var j = 0
|
||||
|
@ -1095,7 +1109,7 @@ function NLoad (resource, cwith) {
|
|||
data = r
|
||||
count = allCount + 1 // couse starting with -1 to show errors
|
||||
|
||||
var i = 0
|
||||
let i = 0
|
||||
while (i < data.length && !GM_getValue('Is' + i + 'Active')) {
|
||||
i++
|
||||
}
|
||||
|
@ -1119,10 +1133,9 @@ function AlertOnNoQuestion () {
|
|||
// : UI handling {{{
|
||||
function HandleUI (url, count, subjCount) {
|
||||
var newVersion = false // if the script is newer than last start
|
||||
var loaded = count != -1 // if script could load stuff
|
||||
var loaded = count !== -1 // if script could load stuff
|
||||
|
||||
try // try, cus im suspicious
|
||||
{
|
||||
try {
|
||||
newVersion = GM_info.script.version !== GM_getValue('lastVerson')
|
||||
} catch (e) {
|
||||
Log('Some weird error trying to set new verison')
|
||||
|
@ -1130,19 +1143,16 @@ function HandleUI (url, count, subjCount) {
|
|||
var greetMsg = '' // message to show at the end
|
||||
var timeout = null // the timeout. if null, it wont be hidden
|
||||
// no new version, nothing loaded
|
||||
if (!newVersion && !loaded) // --------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
greetMsg =
|
||||
'Hiba a @resource tagnál, vagy a fileval van gond! (Lehet át lett helyezve, vagy üres, vagy nincs tárgy kiválasztva) Vagy válaszd a netes adatok használatát menüben. Ellenőrizd az elérési utat, vagy hogy a Tampermonkey bővítmény eléri-e a fájlokat. Ha netes forrást használsz, akkor nem elérhető a szerver! Segítségért kattints!'
|
||||
if (!newVersion && !loaded) { // --------------------------------------------------------------------------------------------------------------
|
||||
greetMsg = 'Hiba a @resource tagnál, vagy a fileval van gond! (Lehet át lett helyezve, vagy üres, vagy nincs tárgy kiválasztva) Vagy válaszd a netes adatok használatát menüben. Ellenőrizd az elérési utat, vagy hogy a Tampermonkey bővítmény eléri-e a fájlokat. Ha netes forrást használsz, akkor nem elérhető a szerver! Segítségért kattints!'
|
||||
}
|
||||
var showSplash = (GM_getValue('showSplash') == undefined) || GM_getValue('showSplash') // getting value, if splash screen should be shown. Its true, if its undefined, or true
|
||||
var showSplash = (GM_getValue('showSplash') === undefined) || GM_getValue('showSplash') // getting value, if splash screen should be shown. Its true, if its undefined, or true
|
||||
// no new version, everything loaded, and show splash is enabled. otherwise something happened, so showing it
|
||||
if (!newVersion && loaded && showSplash) // ------------------------------------------------------------------------------------------------
|
||||
{
|
||||
if (!newVersion && loaded && showSplash) { // ------------------------------------------------------------------------------------------------
|
||||
timeout = 5
|
||||
greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + GM_info.script.version + '. '
|
||||
|
||||
if (lastestVersion != undefined && GM_info.script.version != lastestVersion) {
|
||||
if (lastestVersion !== undefined && GM_info.script.version !== lastestVersion) {
|
||||
greetMsg += 'Új verzió elérhető: ' + lastestVersion + '\n'
|
||||
timeout = undefined
|
||||
}
|
||||
|
@ -1154,7 +1164,7 @@ function HandleUI (url, count, subjCount) {
|
|||
toAdd.push(data.Subjects[i].Name + ' (' + data.Subjects[i].length + ')')
|
||||
}
|
||||
}
|
||||
if (toAdd.length != 0) {
|
||||
if (toAdd.length !== 0) {
|
||||
greetMsg += '\nAktív tárgyak: ' + toAdd.join(', ') + '.'
|
||||
} else {
|
||||
AlertOnNoQuestion()
|
||||
|
@ -1166,30 +1176,24 @@ function HandleUI (url, count, subjCount) {
|
|||
}
|
||||
}
|
||||
// new version, nothing loaded
|
||||
if (newVersion && !loaded) // --------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + GM_info.script.version +
|
||||
'. Új verzió!\n Írd át a @resouce tagnál az elírési utat! Kivéve ha üres a file, akkor töltsd fel :) Nincs kérdés betöltve! Segítséghez kattints. Changelog:\n' +
|
||||
lastChangeLog // showing changelog too
|
||||
if (newVersion && !loaded) { // --------------------------------------------------------------------------------------------------------------
|
||||
greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + GM_info.script.version + '. Új verzió!\n Írd át a @resouce tagnál az elírési utat! Kivéve ha üres a file, akkor töltsd fel :) Nincs kérdés betöltve! Segítséghez kattints. Changelog:\n' + lastChangeLog // showing changelog too
|
||||
}
|
||||
// new version, everything loaded -> set lastVerson to current
|
||||
if (newVersion && loaded) // --------------------------------------------------------------------------------------------------------------
|
||||
{
|
||||
greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + GM_info.script.version + '. ' + count +
|
||||
' kérdés és ' + subjCount + ' tárgy betöltve. Verzió frissítve ' + GM_info.script.version +
|
||||
'-re. Changelog:\n' + lastChangeLog
|
||||
if (newVersion && loaded) { // --------------------------------------------------------------------------------------------------------------
|
||||
greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + GM_info.script.version + '. ' + count + ' kérdés és ' + subjCount + ' tárgy betöltve. Verzió frissítve ' + GM_info.script.version + '-re. Changelog:\n' + lastChangeLog
|
||||
GM_setValue('lastVerson', GM_info.script.version) // setting lastVersion
|
||||
}
|
||||
if (!SUtils.EmptyOrWhiteSpace(motd)) {
|
||||
var prevmotd = GM_getValue('motd')
|
||||
if (prevmotd != motd) {
|
||||
if (prevmotd !== motd) {
|
||||
greetMsg += '\nMOTD:\n' + motd
|
||||
timeout = null
|
||||
GM_setValue('motdcount', motdShowCount)
|
||||
GM_setValue('motd', motd)
|
||||
} else {
|
||||
var motdcount = GM_getValue('motdcount')
|
||||
if (motdcount == undefined) {
|
||||
if (motdcount === undefined) {
|
||||
GM_setValue('motdcount', motdShowCount)
|
||||
motdcount = motdShowCount
|
||||
}
|
||||
|
@ -1215,16 +1219,14 @@ function HandleUI (url, count, subjCount) {
|
|||
function HandleQuiz () {
|
||||
var q = QPM.GetQuestionFromTest()
|
||||
var questions = q.q
|
||||
var allQuestions = q.allQ
|
||||
var imgNodes = q.imgnodes
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
var answers = []
|
||||
for (var j = 0; j < questions.length; j++) // going thru all answers
|
||||
{
|
||||
for (var j = 0; j < questions.length; j++) {
|
||||
var question = SUtils.RemoveUnnecesarySpaces(questions[j]) // simplifying question
|
||||
var result = data.Search(question, SimplifyImages(imgNodes))
|
||||
var r = PrepareAnswers(result, j)
|
||||
if (r != undefined) { answers.push(r) }
|
||||
if (r !== undefined) { answers.push(r) }
|
||||
HighLightAnswer(result, j) // highlights the answer for the current result
|
||||
}
|
||||
ShowAnswers(answers)
|
||||
|
@ -1233,19 +1235,15 @@ function HandleQuiz () {
|
|||
function PrepareAnswers (result, j) {
|
||||
assert(result)
|
||||
|
||||
if (result.length > 0) // if there are more than zero results
|
||||
{
|
||||
if (result.length > 0) {
|
||||
var allMessages = [] // preparing all messages
|
||||
for (var k = 0; k < result.length; k++) // going throuh all results
|
||||
{
|
||||
for (var k = 0; k < result.length; k++) {
|
||||
var msg = '' // the current message
|
||||
if ((GM_getValue('showQuestions') == undefined) || GM_getValue('showQuestions')) // if the question should be shown
|
||||
{
|
||||
if ((GM_getValue('showQuestions') === undefined) || GM_getValue('showQuestions')) {
|
||||
msg += result[k].q.Q + '\n' // adding the question if yes
|
||||
}
|
||||
msg += result[k].q.A.replace(/, /g, '\n') // adding answer
|
||||
if (result[k].q.HasImage()) // and adding image, if it exists
|
||||
{
|
||||
if (result[k].q.HasImage()) {
|
||||
msg += '\n' + result[k].q.I // if it has image part, adding that too
|
||||
}
|
||||
allMessages.push({
|
||||
|
@ -1279,7 +1277,6 @@ function ShowAnswers (answers) {
|
|||
// : Quiz saving {{{
|
||||
|
||||
function HandleResults (url) {
|
||||
var allResults = new QuestionDB()
|
||||
var d = SaveQuiz(GetQuiz(), data) // saves the quiz questions and answers
|
||||
|
||||
if (d) { ShowSaveQuizDialog(d.addedQ, d.allQ, d.allOutput, d.output, d.sendSuccess, d.sentData) }
|
||||
|
@ -1287,17 +1284,14 @@ function HandleResults (url) {
|
|||
|
||||
function ShowSaveQuizDialog (addedQ, allQ, allOutput, output, sendSuccess, sentData) {
|
||||
var msg = ''
|
||||
if (addedQ > 0) // if there are more than 0 new question
|
||||
{
|
||||
msg = 'Klikk ide a nyers adatokhoz. ' + addedQ +
|
||||
' új kérdés!'
|
||||
if (addedQ > 0) {
|
||||
msg = 'Klikk ide a nyers adatokhoz. ' + addedQ + ' új kérdés!'
|
||||
|
||||
var useNetDB = GM_getValue('useNetDB')
|
||||
if (useNetDB != undefined && useNetDB == 1) {
|
||||
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!' }
|
||||
} else // if there is 0 or less new question
|
||||
{
|
||||
} 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.' }
|
||||
}
|
||||
|
@ -1306,13 +1300,11 @@ function ShowSaveQuizDialog (addedQ, allQ, allOutput, output, sendSuccess, sentD
|
|||
m: msg,
|
||||
isSimple: true
|
||||
}, null, function () {
|
||||
var towrite = '<h3>' + sentData.subj + '<br>TXT-ben nem szereplő kérdések: ' + addedQ + '/' +
|
||||
allQ + '</h3><br>' +
|
||||
output.replace(/\n/g, '<br>') + '<br><h3>Összes kérdés/válasz:</h3>' + allOutput.replace(
|
||||
var towrite = '<h3>' + sentData.subj + '<br>TXT-ben nem szereplő kérdések: ' + addedQ + '/' + allQ + '</h3><br>' + output.replace(/\n/g, '<br>') + '<br><h3>Összes kérdés/válasz:</h3>' + allOutput.replace(
|
||||
/\n/g, '<br>')
|
||||
|
||||
var useNetDB = GM_getValue('useNetDB')
|
||||
if (useNetDB != undefined && useNetDB == 1) {
|
||||
if (useNetDB !== undefined && useNetDB === 1) {
|
||||
try {
|
||||
towrite += '</p>Elküldött adatok:</p> ' + JSON.stringify(sentData)
|
||||
} catch (e) {
|
||||
|
@ -1332,7 +1324,7 @@ function SearchSameQuestion (questionData, quiz, i) {
|
|||
if (item.match > minResultMatchPercent) { count++ }
|
||||
})
|
||||
|
||||
return count == 0 ? -1 : count
|
||||
return count === 0 ? -1 : count
|
||||
}
|
||||
|
||||
// this should get the image url from a result page
|
||||
|
@ -1343,8 +1335,7 @@ function GetImageFormResult (i) {
|
|||
var imgElements = RPM.GetResultImage(i) // trying to get image
|
||||
var imgURL = [] // image urls
|
||||
for (var j = 0; j < imgElements.length; j++) {
|
||||
if (!imgElements[j].src.includes('brokenfile')) // idk why brokenfile is in some urls, which are broken, so why tf are they there damn moodle
|
||||
{
|
||||
if (!imgElements[j].src.includes('brokenfile')) {
|
||||
var filePart = imgElements[j].src.split('/') // splits the link by "/"
|
||||
filePart = filePart[filePart.length - 1] // the last one is the image name
|
||||
imgURL.push(decodeURI(SUtils.ShortenString(filePart, 30)))
|
||||
|
@ -1362,8 +1353,8 @@ function GetImageFormResult (i) {
|
|||
// saves the current quiz. questionData contains the active subjects questions
|
||||
function SaveQuiz (quiz, questionData) {
|
||||
try {
|
||||
if (quiz.length == 0) {
|
||||
throw {
|
||||
if (quiz.length === 0) {
|
||||
throw { // eslint-disable-line
|
||||
message: 'quiz length is zero!',
|
||||
stack: 'no stack.'
|
||||
}
|
||||
|
@ -1373,8 +1364,7 @@ function SaveQuiz (quiz, questionData) {
|
|||
var allQ = 0
|
||||
var addedQ = 0
|
||||
var newQuestions = []
|
||||
for (var i = 0; i < quiz.length; i++) // going though quiz
|
||||
{
|
||||
for (var i = 0; i < quiz.length; i++) {
|
||||
// searching for same questions in questionData
|
||||
var toAdd = '' // this will be added to some variable depending on if its already in the database
|
||||
toAdd += '?' + SUtils.RemoveUnnecesarySpaces(quiz[i].Q) + '\n' // adding quiz question
|
||||
|
@ -1382,8 +1372,7 @@ function SaveQuiz (quiz, questionData) {
|
|||
if (quiz[i].HasImage()) {
|
||||
toAdd += '>' + SUtils.RemoveUnnecesarySpaces(quiz[i].I) + '\n' // adding quiz image if there is any
|
||||
}
|
||||
if (SearchSameQuestion(questionData, quiz, i) == -1) // if there is no such item in the database (w/ same q and a)
|
||||
{
|
||||
if (SearchSameQuestion(questionData, quiz, i) === -1) {
|
||||
output += toAdd // adding to output
|
||||
newQuestions.push(quiz[i])
|
||||
addedQ++
|
||||
|
@ -1401,7 +1390,7 @@ function SaveQuiz (quiz, questionData) {
|
|||
Log('unable to get subject name :c')
|
||||
}
|
||||
var useNetDB = GM_getValue('useNetDB')
|
||||
if (useNetDB != undefined && useNetDB == 1) {
|
||||
if (useNetDB !== undefined && useNetDB === 1) {
|
||||
sentData.allData = quiz
|
||||
sentData.data = newQuestions
|
||||
sentData.version = GM_info.script.version
|
||||
|
@ -1429,26 +1418,24 @@ function GetQuiz () {
|
|||
try {
|
||||
var quiz = [] // final quiz stuff
|
||||
var results = RPM.GetFormResult() // getting results element
|
||||
for (var i = 0; i < results.length - 2; i++) // going through results, except last two, idk why, dont remember, go check it man
|
||||
{
|
||||
for (var i = 0; i < results.length - 2; i++) {
|
||||
var question = {} // the current question
|
||||
// QUESTION --------------------------------------------------------------------------------------------------------------------
|
||||
var q = RPM.GetQuestionFromResult(i)
|
||||
if (q != undefined) { question.q = SUtils.SimplifyQuery(q) }
|
||||
if (q !== undefined) { question.q = SUtils.SimplifyQuery(q) }
|
||||
|
||||
// RIGHTANSWER ---------------------------------------------------------------------------------------------------------------------
|
||||
var a = RPM.GetRightAnswerFromResultv2(i)
|
||||
if (a == undefined) { a = RPM.GetRightAnswerFromResult(i) }
|
||||
if (a != undefined) { question.a = SUtils.SimplifyQuery(a) }
|
||||
if (a === undefined) { a = RPM.GetRightAnswerFromResult(i) }
|
||||
if (a !== undefined) { question.a = SUtils.SimplifyQuery(a) }
|
||||
// IMG ---------------------------------------------------------------------------------------------------------------------
|
||||
var img = GetImageFormResult(i)
|
||||
question.i = img
|
||||
|
||||
if (q != undefined) { q = SUtils.ReplaceCharsWithSpace(q, '\n') }
|
||||
if (a != undefined) { a = SUtils.ReplaceCharsWithSpace(a, '\n') }
|
||||
if (q !== undefined) { q = SUtils.ReplaceCharsWithSpace(q, '\n') }
|
||||
if (a !== undefined) { a = SUtils.ReplaceCharsWithSpace(a, '\n') }
|
||||
|
||||
if (question.a != undefined) // adding only if has question
|
||||
{
|
||||
if (question.a !== undefined) {
|
||||
quiz.push(new Question(question.q, question.a, question.i)) // adding current question to quiz
|
||||
} else {
|
||||
Log('error getting queston, no correct answer given, or its incorrect')
|
||||
|
@ -1467,10 +1454,8 @@ function GetQuiz () {
|
|||
|
||||
function SimplifyImages (imgs) {
|
||||
var questionImages = [] // the array for the image names in question
|
||||
for (var i = 0; i < imgs.length; i++) // going through all image
|
||||
{
|
||||
if (!imgs[i].src.includes('brokenfile')) // if its includes borken file its broken. Its another moodle crap. So i just wont check those
|
||||
{
|
||||
for (var i = 0; i < imgs.length; i++) {
|
||||
if (!imgs[i].src.includes('brokenfile')) {
|
||||
var filePart = imgs[i].src.split('/') // splits the link by "/"
|
||||
filePart = filePart[filePart.length - 1] // the last one is the image name
|
||||
questionImages.push(decodeURI(SUtils.RemoveUnnecesarySpaces(SUtils.ShortenString(filePart, 30)))) // decodes uri codes, and removes exess spaces, and shortening it
|
||||
|
@ -1481,10 +1466,8 @@ function SimplifyImages (imgs) {
|
|||
|
||||
// adds image names to image nodes
|
||||
function AddImageNamesToImages (imgs) {
|
||||
for (var i = 0; i < imgs.length; i++) // going through all image
|
||||
{
|
||||
if (!imgs[i].src.includes('brokenfile')) // if its includes borken file its broken. Its another moodle crap. So i just wont check those
|
||||
{
|
||||
for (var i = 0; i < imgs.length; i++) {
|
||||
if (!imgs[i].src.includes('brokenfile')) {
|
||||
var filePart = imgs[i].src.split('/') // splits the link by "/"
|
||||
filePart = filePart[filePart.length - 1] // the last one is the image name
|
||||
var appedtTo = imgs[i].parentNode // it will be appended here
|
||||
|
@ -1500,13 +1483,11 @@ function AddImageNamesToImages (imgs) {
|
|||
// this function adds basic hotkeys for video controll.
|
||||
function AddVideoHotkeys (url) {
|
||||
var seekTime = 20
|
||||
document.addEventListener('keydown', function (e) // keydown event listener
|
||||
{
|
||||
document.addEventListener('keydown', function (e) {
|
||||
try {
|
||||
var video = MPM.GetVideo()
|
||||
var keyCode = e.keyCode // getting keycode
|
||||
if (keyCode == 32) // if the keycode is 32 (space)
|
||||
{
|
||||
if (keyCode === 32) { // if the keycode is 32 (space)
|
||||
e.preventDefault() // preventing default action (space scrolles down)
|
||||
if (video.paused && video.buffered.length > 0) {
|
||||
video.play()
|
||||
|
@ -1514,12 +1495,10 @@ function AddVideoHotkeys (url) {
|
|||
video.pause()
|
||||
}
|
||||
}
|
||||
if (keyCode == 39) // rigth : 39
|
||||
{
|
||||
if (keyCode === 39) { // rigth : 39
|
||||
video.currentTime += seekTime
|
||||
}
|
||||
if (keyCode == 37) // left : 37
|
||||
{
|
||||
if (keyCode === 37) { // left : 37
|
||||
video.currentTime -= seekTime
|
||||
}
|
||||
} catch (err) {
|
||||
|
@ -1533,20 +1512,6 @@ function AddVideoHotkeys (url) {
|
|||
node.style.margin = '5px 5px 5px 5px' // fancy margin
|
||||
}
|
||||
|
||||
// simple sort.
|
||||
function SortByPercent (results) {
|
||||
for (var i = 0; i < results.length; i++) {
|
||||
for (var j = results.length - 1; j > i; j--) {
|
||||
if (results[i].p < results[j].p) {
|
||||
var temp = results[i]
|
||||
results[i] = results[j]
|
||||
results[j] = temp
|
||||
}
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
|
||||
// removes stuff like " a. q1" -> "q1"
|
||||
function RemoveLetterMarking (inp) {
|
||||
let dotIndex = inp.indexOf('.')
|
||||
|
@ -1559,15 +1524,12 @@ function RemoveLetterMarking (inp) {
|
|||
// highlights the possible solutions to the current question
|
||||
function HighLightAnswer (results, currQuestionNumber) {
|
||||
try {
|
||||
if (results.length > 0) // if there are items in the result
|
||||
{
|
||||
if (results.length > 0) {
|
||||
var answers = RPM.GetAllAnswer(currQuestionNumber) // getting all answers
|
||||
var toColor = [] // the numberth in the array will be colored, and .length items will be colored
|
||||
var type = '' // type of the question. radio or ticbox or whatitscalled
|
||||
for (var i = 0; i < answers.length; i++) // going thtough answers
|
||||
{
|
||||
if (answers[i].tagName && answers[i].tagName.toLowerCase() == 'div') // if its not null and is "div"
|
||||
{
|
||||
for (let i = 0; i < answers.length; i++) { // going thtough answers
|
||||
if (answers[i].tagName && answers[i].tagName.toLowerCase() === 'div') { // if its not null and is "div"
|
||||
var correct = results[0].q.A.toLowerCase() // getting current correct answer from data
|
||||
var answer = answers[i].innerText.replace(/\n/g, '').toLowerCase() // getting current answer
|
||||
|
||||
|
@ -1576,24 +1538,21 @@ function HighLightAnswer (results, currQuestionNumber) {
|
|||
|
||||
if (SUtils.EmptyOrWhiteSpace(correct) || SUtils.EmptyOrWhiteSpace(answer)) { continue }
|
||||
|
||||
if (SUtils.NormalizeSpaces(SUtils.RemoveUnnecesarySpaces(correct)).includes(answer)) // if the correct answer includes the current answer
|
||||
{
|
||||
if (SUtils.NormalizeSpaces(SUtils.RemoveUnnecesarySpaces(correct)).includes(answer)) { // if the correct answer includes the current answer
|
||||
toColor.push(i) // adding the index
|
||||
type = MPM.GetInputType(answers, i) // setting the type
|
||||
}
|
||||
}
|
||||
}
|
||||
if (results[0].match == 100) // if the result is 100% correct
|
||||
{
|
||||
if (type !== 'radio' || toColor.length == 1) // TODO why not radio
|
||||
{
|
||||
for (var i = 0; i < toColor.length; i++) // going through "toColor"
|
||||
{ answers[toColor[i]].style.backgroundColor = '#8cff66' }
|
||||
if (results[0].match === 100) { // if the result is 100% correct
|
||||
if (type !== 'radio' || toColor.length === 1) { // TODO why not radio
|
||||
for (let i = 0; i < toColor.length; i++) { // going through "toColor"
|
||||
answers[toColor[i]].style.backgroundColor = '#8cff66'
|
||||
}
|
||||
}
|
||||
} // and coloring the correct index
|
||||
}
|
||||
} catch (e) // catching errors. Sometimes there are random errors, wich i did not test, but they are rare, and does not break the main script.
|
||||
{
|
||||
} catch (e) { // catching errors. Sometimes there are random errors, wich i did not test, but they are rare, and does not break the main script.
|
||||
Log('script error at highlightin answer: ' + e.message)
|
||||
}
|
||||
}
|
||||
|
@ -1629,10 +1588,9 @@ function ShowMessage (msgItem, timeout, funct) {
|
|||
var defMargin = '0px 5px 0px 5px'
|
||||
var isSimpleMessage = false
|
||||
var simpleMessageText = ''
|
||||
if (msgItem.isSimple) // parsing msgItem for easier use
|
||||
{
|
||||
if (msgItem.isSimple) { // parsing msgItem for easier use
|
||||
simpleMessageText = msgItem.m
|
||||
if (simpleMessageText == '') {
|
||||
if (simpleMessageText === '') {
|
||||
return
|
||||
}
|
||||
msgItem = [
|
||||
|
@ -1645,13 +1603,11 @@ function ShowMessage (msgItem, timeout, funct) {
|
|||
|
||||
var appedtTo = document.body // will be appended here
|
||||
var width = window.innerWidth - window.innerWidth / 6 // with of the box
|
||||
var startFromLeft = window.innerWidth / 2 - width / 2 // dont change this
|
||||
var startFromTop = 25 // top distance
|
||||
|
||||
var mainDiv = document.createElement('div') // the main divider, wich items will be attached to
|
||||
mainDiv.setAttribute('id', 'messageMainDiv')
|
||||
if (funct) // if there is a function as parameter
|
||||
{
|
||||
if (funct) { // if there is a function as parameter
|
||||
addEventListener(mainDiv, 'click', funct) // adding it as click
|
||||
}
|
||||
// lotsa crap style
|
||||
|
@ -1679,8 +1635,7 @@ function ShowMessage (msgItem, timeout, funct) {
|
|||
mesageNode.style.margin = defMargin // fancy margin
|
||||
}
|
||||
mainDiv.appendChild(simpleMessageParagrapg) // adding text box to main div
|
||||
} else // if its a fucking complicated message
|
||||
{
|
||||
} else { // if its a fucking complicated message
|
||||
// TABLE SETUP ------------------------------------------------------------------------------------------------------------
|
||||
var table = document.createElement('table')
|
||||
table.style.width = '100%'
|
||||
|
@ -1708,8 +1663,7 @@ function ShowMessage (msgItem, timeout, funct) {
|
|||
var percentTextBox = CreateNodeWithText(percentTextCell, '')
|
||||
percentTextBox.setAttribute('id', 'percentTextBox')
|
||||
|
||||
if (matchPercent) // if match percent param is not null
|
||||
{
|
||||
if (matchPercent) { // if match percent param is not null
|
||||
percentTextBox.innerText = matchPercent + '%'
|
||||
}
|
||||
// NUMBER SETUP -----------------------------------------------------------------------------------------------------
|
||||
|
@ -1724,12 +1678,11 @@ function ShowMessage (msgItem, timeout, funct) {
|
|||
var currItem = 0
|
||||
var currRelevantQuestion = 0
|
||||
|
||||
function GetRelevantQuestion () // returns the currItemth questions currRelevantQuestionth relevant question
|
||||
{
|
||||
const GetRelevantQuestion = () => { // returns the currItemth questions currRelevantQuestionth relevant question
|
||||
return msgItem[currItem][currRelevantQuestion]
|
||||
}
|
||||
|
||||
function ChangeCurrItemIndex (to) {
|
||||
const ChangeCurrItemIndex = (to) => {
|
||||
currItem += to
|
||||
if (currItem < 0) {
|
||||
currItem = 0
|
||||
|
@ -1740,7 +1693,7 @@ function ShowMessage (msgItem, timeout, funct) {
|
|||
currRelevantQuestion = 0
|
||||
}
|
||||
|
||||
function ChangeCurrRelevantQuestionIndex (to) {
|
||||
const ChangeCurrRelevantQuestionIndex = (to) => {
|
||||
currRelevantQuestion += to
|
||||
if (currRelevantQuestion < 0) {
|
||||
currRelevantQuestion = 0
|
||||
|
@ -1750,10 +1703,10 @@ function ShowMessage (msgItem, timeout, funct) {
|
|||
}
|
||||
}
|
||||
|
||||
function SetQuestionText () {
|
||||
const SetQuestionText = () => {
|
||||
var relevantQuestion = GetRelevantQuestion()
|
||||
questionTextElement.innerText = relevantQuestion.m
|
||||
if (currItem == 0 && currRelevantQuestion == 0) {
|
||||
if (currItem === 0 && currRelevantQuestion === 0) {
|
||||
numberTextBox.innerText = (currRelevantQuestion + 1) + '.'
|
||||
} else {
|
||||
numberTextBox.innerText = (currItem + 1) + './' + (currRelevantQuestion + 1) + '.'
|
||||
|
@ -1781,10 +1734,9 @@ function ShowMessage (msgItem, timeout, funct) {
|
|||
})
|
||||
}
|
||||
// deciding if has multiple questions ------------------------------------------------------------------------------------------------
|
||||
if (msgItem.length == 1) {
|
||||
if (msgItem.length === 1) {
|
||||
SetQuestionText()
|
||||
} else // if there are multiple items to display
|
||||
{
|
||||
} else { // if there are multiple items to display
|
||||
// PREV QUESTION BUTTON ------------------------------------------------------------------------------------------------------------
|
||||
var prevButton = CreateNodeWithText(prevQuestionCell, '^', 'button')
|
||||
prevButton.style.margin = buttonMargin // fancy margin
|
||||
|
@ -1816,15 +1768,14 @@ function ShowMessage (msgItem, timeout, funct) {
|
|||
mainDiv.style.left = (window.innerWidth - width) / 2 + 'px'
|
||||
})
|
||||
var timeOut
|
||||
if (timeout && timeout > 0) // setting timeout if not zero or null
|
||||
{
|
||||
if (timeout && timeout > 0) { // setting timeout if not zero or null
|
||||
timeOut = setTimeout(function () {
|
||||
mainDiv.parentNode.removeChild(mainDiv)
|
||||
}, timeout * 1000)
|
||||
}
|
||||
// middle click close event listener
|
||||
addEventListener(mainDiv, 'mousedown', function (e) {
|
||||
if (e.which == 2) {
|
||||
if (e.which === 2) {
|
||||
mainDiv.parentNode.removeChild(mainDiv)
|
||||
if (timeOut) {
|
||||
clearTimeout(timeOut)
|
||||
|
@ -1951,16 +1902,6 @@ function ShowMenuList () {
|
|||
subjTable.style.textAlign = 'left'
|
||||
subjTable.style.width = '98%'
|
||||
|
||||
var tr = subjTable.insertRow()
|
||||
var header1 = tr.insertCell()
|
||||
|
||||
var headerSubjInfoParagraph = CreateNodeWithText(header1, 'Tárgynév [darab kérdés]', 'center')
|
||||
headerSubjInfoParagraph.style.margin = fiveMargin // fancy margin
|
||||
|
||||
var header2 = tr.insertCell()
|
||||
var headerSubjInfoParagraph = CreateNodeWithText(header2, 'Aktív')
|
||||
headerSubjInfoParagraph.style.margin = fiveMargin // fancy margin
|
||||
|
||||
if (data && data.length > 0) {
|
||||
for (let i = 0; i < data.length; i++) {
|
||||
var subjRow = subjTable.insertRow()
|
||||
|
@ -1968,7 +1909,7 @@ function ShowMenuList () {
|
|||
|
||||
var td = subjRow.insertCell()
|
||||
var text = data.Subjects[i].Name
|
||||
if (data.Subjects[i].length != 0) { text += ' [ ' + data.Subjects[i].length + 'db ]' }
|
||||
if (data.Subjects[i].length !== 0) { text += ' [ ' + data.Subjects[i].length + 'db ]' }
|
||||
|
||||
var textBox = CreateNodeWithText(td, text)
|
||||
|
||||
|
@ -1978,8 +1919,7 @@ function ShowMenuList () {
|
|||
var checkbox = document.createElement('input') // new paragraph
|
||||
checkbox.type = 'checkbox'
|
||||
checkbox.style.background = 'white'
|
||||
checkbox.style.margin =
|
||||
'5px 5px 5px 5px' // fancy margin
|
||||
checkbox.style.margin = '5px 5px 5px 5px' // fancy margin
|
||||
td.appendChild(checkbox) // adding text box to main td
|
||||
|
||||
var active = data.GetIfActive(i)
|
||||
|
@ -2003,11 +1943,9 @@ function ShowMenuList () {
|
|||
var subjtblrow = tbl.insertRow()
|
||||
var subjtbltd = subjtblrow.insertCell()
|
||||
subjtbltd.appendChild(scrollDiv)
|
||||
} else // if no data
|
||||
{
|
||||
} else { // if no data
|
||||
var noDataRow = tbl.insertRow()
|
||||
var noDataRowCell = noDataRow.insertCell()
|
||||
var textBox
|
||||
|
||||
if (GM_getValue('skipLoad')) {
|
||||
textBox = CreateNodeWithText(noDataRowCell,
|
||||
|
@ -2039,9 +1977,6 @@ function ShowMenuList () {
|
|||
GM_setValue('showSplash', splashTickBox.checked)
|
||||
}) // adding clicktextNode
|
||||
|
||||
var splashTickBoxTextSpan = CreateNodeWithText(splashTickboxCell,
|
||||
'Üdvözlő üzenet mutatása minden oldalon', 'span')
|
||||
|
||||
// show questons tickbox -----------------------------------------------------------------------------------------------------------------------------
|
||||
var questionTickboxRow = tbl.insertRow()
|
||||
var questionTickboxCell = questionTickboxRow.insertCell()
|
||||
|
@ -2065,8 +2000,6 @@ function ShowMenuList () {
|
|||
}, 7)
|
||||
}
|
||||
}) // adding clicktextNode
|
||||
var questionsTickBoxTextSpan = CreateNodeWithText(questionTickboxCell,
|
||||
'Kérdések mutatása válaszhoz', 'span')
|
||||
|
||||
// database mode listbox -----------------------------------------------------------------------------------------------------------------------------
|
||||
var databasemodeListboxRow = tbl.insertRow()
|
||||
|
@ -2103,7 +2036,7 @@ function ShowMenuList () {
|
|||
databasemodeListbox.add(usenetsafe, 1)
|
||||
|
||||
var selected = GM_getValue('useNetDB')
|
||||
if (selected != undefined) { databasemodeListbox.selectedIndex = selected }
|
||||
if (selected !== undefined) { databasemodeListbox.selectedIndex = selected }
|
||||
|
||||
var databasemodeListboxElement = document.createElement('span') // new paragraph
|
||||
databasemodeListboxCell.appendChild(databasemodeListboxElement)
|
||||
|
@ -2161,7 +2094,7 @@ function ShowMenuList () {
|
|||
}
|
||||
|
||||
function EscClose (e) {
|
||||
if (e.keyCode == 27) { CloseMenu() }
|
||||
if (e.keyCode === 27) { CloseMenu() }
|
||||
}
|
||||
|
||||
function CloseMenu () {
|
||||
|
@ -2175,20 +2108,6 @@ function CloseMenu () {
|
|||
|
||||
// : Generic utils {{{
|
||||
|
||||
function RemoveMultipleItems (array) {
|
||||
var newArray = []
|
||||
for (var i = 0; i < array.length; i++) {
|
||||
var j = 0
|
||||
while (j < newArray.length && newArray[j] !== array[i]) {
|
||||
j++
|
||||
}
|
||||
if (j >= newArray.length) {
|
||||
newArray.push(array[i])
|
||||
}
|
||||
}
|
||||
return newArray
|
||||
}
|
||||
|
||||
function CreateNodeWithText (to, text, type) {
|
||||
var paragraphElement = document.createElement(type || 'p') // new paragraph
|
||||
var textNode = document.createTextNode(text)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue