From 62de25668a2ada40fa8a2221c8f4876853517704 Mon Sep 17 00:00:00 2001
From: YourFriendlyNeighborhoodDealer
Date: Tue, 24 Sep 2019 17:57:18 +0200
Subject: [PATCH 1/9] small code refactoring
---
main.js | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/main.js b/main.js
index 506dca3..546c965 100644
--- a/main.js
+++ b/main.js
@@ -511,7 +511,7 @@ class ResultsPageModell {
var items = results[i].getElementsByTagName('label')
var r = []
for (var j = 0; j < items.length; j++) {
- function TryGetCorrect (j) {
+ const TryGetCorrect = (j) => {
var cn = items[j].parentNode.className
if (cn.includes('correct')) { return cn.includes('correct') && !cn.includes('incorrect') }
}
@@ -698,14 +698,14 @@ var MPM = new MiscPageModell()
// : }}}
// : Main function {{{
-function Main () {
+function Main () { // eslint-disable-line
'use strict'
console.time('main')
Init(function (count, subjCount) {
- var url = location.href
+ var url = location.href // eslint-disable-line
- let skipLoad = GM_getValue('skipLoad')
+ let skipLoad = GM_getValue('skipLoad') // eslint-disable-line
if (count === -2 && subjCount === -2 && skipLoad) {
if (url.includes('/quiz/') && url.includes('attempt.php')) {
ShowMessage({
@@ -728,7 +728,7 @@ function Main () {
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', {
+ GM_openInTab(serverAdress + 'lred', { // eslint-disable-line
active: true
})
})
@@ -755,12 +755,12 @@ function Main () {
// : Loading {{{
function Init (cwith) {
- if (false) {
- GM_setValue('version16', undefined)
- GM_setValue('version15', undefined)
- GM_setValue('firstRun', undefined) // GM_getValue("lastVerson") == undefined => firstrun
- GM_setValue('showQuestions', undefined)
- GM_setValue('showSplash', undefined)
+ 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
}
var url = location.href // window location
var count = -1 // loaded question count. stays -1 if the load failed.
@@ -831,10 +831,9 @@ function Version15 () {
function Version16 () {
var version16 = GM_getValue('version16') // if the current run is the frst
- if (version16 == undefined || version16 == true) // if its undefined, or true
- {
+ if (version16 === undefined || version16 === true) {
var i = 0
- while (GM_getValue('Is' + i + 'Active') != undefined) {
+ while (GM_getValue('Is' + i + 'Active') !== undefined) {
GM_setValue('Is' + i + 'Active', false)
i++
}
From f0b05d4fc0a86afb9653f9ef5eac2d30293b9bf3 Mon Sep 17 00:00:00 2001
From: MrFry
Date: Thu, 26 Sep 2019 12:22:17 +0200
Subject: [PATCH 2/9] Grab and drop question type
---
main.js | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/main.js b/main.js
index 506dca3..eb4de9f 100644
--- a/main.js
+++ b/main.js
@@ -540,7 +540,9 @@ class ResultsPageModell {
if (logElementGetting) { Log('Getting right answer if correct not shown') }
var results = this.GetFormResult() // getting results element
var n = results[i].getElementsByTagName('i')[0].parentNode
- if (n.className.includes('correct') && !n.className.includes('incorrect')) { return results[i].getElementsByTagName('i')[0].parentNode.innerText } else { return '' }
+ if (n.className.includes('correct') && !n.className.includes('incorrect')) {
+ return results[i].getElementsByTagName('i')[0].parentNode.innerText
+ }
}
GetFormCFOfResult (result) {
@@ -560,6 +562,15 @@ class ResultsPageModell {
return this.GetFormCFOfResult(results[i]).getElementsByTagName('img')
}
+ GetOnlyImageQuestionResult (i) {
+ console.log('############################################################')
+ console.log(i)
+ const results = this.GetFormResult() // getting results element
+ const n = results[i]
+ console.log(n)
+ console.log('############################################################')
+ }
+
// gets the question from the result page
// i is the index of the question
GetQuestionFromResult (i) {
@@ -608,6 +619,11 @@ class ResultsPageModell {
if (RPM.GetDropboxes(i).length > 0) { return RPM.GetCurrentAnswer(i) }
})
+ // image and text only question
+ fun.push(function TryGet5 (i) {
+ return RPM.GetOnlyImageQuestionResult(i)
+ })
+
// if the correct answers are not shown, and the selected answer
// is correct
fun.push(function TryGet2 (i) {
@@ -637,7 +653,10 @@ class ResultsPageModell {
var j = 0
var currAnswer
while (j < fun.length && SUtils.EmptyOrWhiteSpace(currAnswer)) {
- currAnswer = fun[j](i)
+ try {
+ currAnswer = fun[j](i)
+ } catch (e) {
+ }
j++
}
From 622dc1db31410d7dd7d705f257962d601f76fed4 Mon Sep 17 00:00:00 2001
From: MrFry
Date: Thu, 26 Sep 2019 12:44:11 +0200
Subject: [PATCH 3/9] Eslint formatting
---
main.js | 327 +++++++++++++++++++++-----------------------------------
1 file changed, 123 insertions(+), 204 deletions(-)
diff --git a/main.js b/main.js
index 6ef83a1..7a335c1 100644
--- a/main.js
+++ b/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 () {
'Moodle teszt userscript: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!
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.
'
)
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(
'Moodle teszt userscript: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
'
)
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 = '' + sentData.subj + '
TXT-ben nem szereplő kérdések: ' + addedQ + '/' +
- allQ + '
' +
- output.replace(/\n/g, '
') + '
Összes kérdés/válasz:
' + allOutput.replace(
+ var towrite = '' + sentData.subj + '
TXT-ben nem szereplő kérdések: ' + addedQ + '/' + allQ + '
' + output.replace(/\n/g, '
') + '
Összes kérdés/válasz:
' + allOutput.replace(
/\n/g, '
')
var useNetDB = GM_getValue('useNetDB')
- if (useNetDB != undefined && useNetDB == 1) {
+ if (useNetDB !== undefined && useNetDB === 1) {
try {
towrite += '
Elküldött adatok: ' + 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
@@ -1810,21 +1762,20 @@ function ShowMessage (msgItem, timeout, funct) {
// setting some events
// addEventListener(window, 'scroll', function () {
- // mainDiv.style.top = (pageYOffset + startFromTop) + 'px';
+ // mainDiv.style.top = (pageYOffset + startFromTop) + 'px';
// })
addEventListener(window, 'resize', function () {
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)
@@ -2145,7 +2078,7 @@ function ShowMenuList () {
})
// addEventListener(window, 'scroll', function () {
- // menuDiv.style.top = (pageYOffset + window.innerHeight / 3) + 'px';
+ // menuDiv.style.top = (pageYOffset + window.innerHeight / 3) + 'px';
// })
addEventListener(window, 'resize', function () {
menuDiv.style.left = window.innerWidth / 2 + 'px'
@@ -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)
From 86d279a670fc46045db9da0bb9f71ef51f5acaf7 Mon Sep 17 00:00:00 2001
From: MrFry
Date: Wed, 2 Oct 2019 16:58:53 +0200
Subject: [PATCH 4/9] commenting out stuff
---
main.js | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/main.js b/main.js
index 7a335c1..9da408a 100644
--- a/main.js
+++ b/main.js
@@ -24,14 +24,14 @@
// 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
+// 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 */
// ------------------------------------------------------------------------------
From 6ad2da1ac8f7204ed7e6a40819444684a096a1b8 Mon Sep 17 00:00:00 2001
From: MrFry
Date: Thu, 3 Oct 2019 12:37:32 +0200
Subject: [PATCH 5/9] removed version 161 action, readded labels to menu
---
main.js | 34 +++++++++++++++++-----------------
1 file changed, 17 insertions(+), 17 deletions(-)
diff --git a/main.js b/main.js
index 9da408a..fa8aea6 100644
--- a/main.js
+++ b/main.js
@@ -771,6 +771,7 @@ function Main () {
}
})
+
console.log('Moodle Test Script run time:')
console.timeEnd('main')
@@ -824,15 +825,12 @@ function VersionActions () {
// GM_setValue("version15", true);
// GM_setValue("firstRun", true);
// GM_setValue("version16", true);
- // GM_setValue("version161", true);
// throw "asd";
- let r = FreshStart()
- if (r !== true) { GM_setValue('version161', false) }
+ FreshStart()
Version15()
Version16()
- Version161()
}
// : Version action functions {{{
@@ -871,19 +869,6 @@ function Version16 () {
}
}
-function Version161 () {
- var version161 = GM_getValue('version161') // if the current run is the frst
- if (version161 === undefined || version161 === true) {
- GM_setValue('useNetDB', '1')
- GM_setValue('version161', false)
- document.write(
- 'Moodle teszt userscript: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
'
- )
- document.close()
- throw 'something, so this stuff stops' // eslint-disable-line
- }
-}
-
// : }}}
var GetFileData = () => {
@@ -1902,6 +1887,17 @@ 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 headerSubjInfoParagraph2 = CreateNodeWithText(header2, 'Aktív')
+ headerSubjInfoParagraph2.style.margin = fiveMargin // fancy margin
+
+ // TODO: group here
if (data && data.length > 0) {
for (let i = 0; i < data.length; i++) {
var subjRow = subjTable.insertRow()
@@ -1977,6 +1973,8 @@ function ShowMenuList () {
GM_setValue('showSplash', splashTickBox.checked)
}) // adding clicktextNode
+ CreateNodeWithText(splashTickboxCell, 'Üdvözlő üzenet mutatása minden oldalon', 'span')
+
// show questons tickbox -----------------------------------------------------------------------------------------------------------------------------
var questionTickboxRow = tbl.insertRow()
var questionTickboxCell = questionTickboxRow.insertCell()
@@ -2001,6 +1999,8 @@ function ShowMenuList () {
}
}) // adding clicktextNode
+ CreateNodeWithText(questionTickboxCell, 'Kérdések mutatása válaszhoz', 'span')
+
// database mode listbox -----------------------------------------------------------------------------------------------------------------------------
var databasemodeListboxRow = tbl.insertRow()
var databasemodeListboxCell = databasemodeListboxRow.insertCell()
From bd031525d08d547158976c644b5bf8b0f4df848f Mon Sep 17 00:00:00 2001
From: MrFry
Date: Thu, 3 Oct 2019 12:52:06 +0200
Subject: [PATCH 6/9] ESLint error disable hack
---
main.js | 142 ++++++++++++++++++++++++++++----------------------------
1 file changed, 70 insertions(+), 72 deletions(-)
diff --git a/main.js b/main.js
index fa8aea6..6afb117 100644
--- a/main.js
+++ b/main.js
@@ -21,19 +21,18 @@
------------------------------------------------------------------------- */
// ------------------------------------------------------------------------------
-// REMOVE THIS, only to disable ESLINT errors
-// ------------------------------------------------------------------------------
+
+// GM functions, 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
+const location = location
+const a = Main
+function getVal (name) { return GM_getValue(name) }
+function setVal (name, val) { return GM_setValue(name, val) }
+function openInTab (address, options) { GM_openInTab(address, options) }
+function getResourceText (name) { return GM_getResourceText(name) }
+function xmlhttpRequest (opts) { GM_xmlhttpRequest(opts) }
+function info () { return GM_info }
/* eslint-enable */
-// ------------------------------------------------------------------------------
var data // all data, which is in the resource txt
var addEventListener // add event listener function
@@ -269,7 +268,7 @@ class QuestionDB {
get activeIndexes () {
var r = []
for (var i = 0; i < this.length; i++) {
- if (GM_getValue('Is' + i + 'Active')) {
+ if (getVal('Is' + i + 'Active')) {
r.push(i)
}
}
@@ -277,11 +276,11 @@ class QuestionDB {
}
GetIfActive (ind) {
- return GM_getValue('Is' + ind + 'Active')
+ return getVal('Is' + ind + 'Active')
}
ChangeActive (i, value) {
- GM_setValue('Is' + i + 'Active', !!value)
+ setVal('Is' + i + 'Active', !!value)
}
AddQuestion (subj, q) {
@@ -735,7 +734,7 @@ function Main () {
Init(function (count, subjCount) {
var url = location.href
- let skipLoad = GM_getValue('skipLoad')
+ let skipLoad = getVal('skipLoad')
if (count === -2 && subjCount === -2 && skipLoad) {
if (url.includes('/quiz/') && url.includes('attempt.php')) {
ShowMessage({
@@ -758,7 +757,7 @@ function Main () {
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', {
+ openInTab(serverAdress + 'lred', {
active: true
})
})
@@ -771,7 +770,6 @@ function Main () {
}
})
-
console.log('Moodle Test Script run time:')
console.timeEnd('main')
@@ -787,11 +785,11 @@ function Main () {
function Init (cwith) {
if (false) { // eslint-disable-line
- GM_setValue('version16', undefined)
- GM_setValue('version15', undefined)
- GM_setValue('firstRun', undefined)
- GM_setValue('showQuestions', undefined)
- GM_setValue('showSplash', undefined)
+ setVal('version16', undefined)
+ setVal('version15', undefined)
+ setVal('firstRun', undefined)
+ setVal('showQuestions', undefined)
+ setVal('showSplash', undefined)
}
var url = location.href // window location
var count = -1 // loaded question count. stays -1 if the load failed.
@@ -822,9 +820,9 @@ function Init (cwith) {
function VersionActions () {
// FOR TESTING ONLY
- // GM_setValue("version15", true);
- // GM_setValue("firstRun", true);
- // GM_setValue("version16", true);
+ // setVal("version15", true);
+ // setVal("firstRun", true);
+ // setVal("version16", true);
// throw "asd";
FreshStart()
@@ -836,19 +834,19 @@ function VersionActions () {
// : Version action functions {{{
function FreshStart () {
- var firstRun = GM_getValue('firstRun') // if the current run is the frst
+ var firstRun = getVal('firstRun') // if the current run is the frst
if (firstRun === undefined || firstRun === true) {
- GM_setValue('firstRun', false)
+ setVal('firstRun', false)
ShowHelp() // showing help
return true
}
}
function Version15 () {
- var version15 = GM_getValue('version15') // if the current run is the frst
+ var version15 = getVal('version15') // if the current run is the frst
if (version15 === undefined || version15 === true) {
- GM_setValue('useNetDB', '1')
- GM_setValue('version15', false)
+ setVal('useNetDB', '1')
+ setVal('version15', false)
document.write(
'Moodle teszt userscript: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!
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.
'
)
@@ -858,21 +856,21 @@ function Version15 () {
}
function Version16 () {
- var version16 = GM_getValue('version16') // if the current run is the frst
+ var version16 = getVal('version16') // if the current run is the frst
if (version16 === undefined || version16 === true) {
var i = 0
- while (GM_getValue('Is' + i + 'Active') !== undefined) {
- GM_setValue('Is' + i + 'Active', false)
+ while (getVal('Is' + i + 'Active') !== undefined) {
+ setVal('Is' + i + 'Active', false)
i++
}
- GM_setValue('version16', false)
+ setVal('version16', false)
}
}
// : }}}
var GetFileData = () => {
- return GM_getResourceText('data')
+ return getResourceText('data')
}
function ReadFile (cwith) {
@@ -898,7 +896,7 @@ function ReadFile (cwith) {
function ReadNetDB (cwith, useNetDB) {
function NewXMLHttpRequest () {
const url = serverAdress + 'data.json'
- GM_xmlhttpRequest({
+ xmlhttpRequest({
method: 'GET',
synchronous: true,
url: url,
@@ -1016,8 +1014,8 @@ function ParseRawData (data) {
}
function Load (cwith) {
- var useNetDB = GM_getValue('useNetDB')
- let skipLoad = GM_getValue('skipLoad')
+ var useNetDB = getVal('useNetDB')
+ let skipLoad = getVal('skipLoad')
if (skipLoad) {
cwith(-2, -2)
@@ -1076,7 +1074,7 @@ function NLoad (resource, cwith) {
for (let i = 0; i < d.Subjects.length; i++) {
let s = new Subject(d.Subjects[i].Name)
- if (GM_getValue('Is' + i + 'Active')) {
+ if (getVal('Is' + i + 'Active')) {
var j = 0
for (j = 0; j < d.Subjects[i].Questions.length; j++) {
var currQ = d.Subjects[i].Questions[j]
@@ -1095,7 +1093,7 @@ function NLoad (resource, cwith) {
count = allCount + 1 // couse starting with -1 to show errors
let i = 0
- while (i < data.length && !GM_getValue('Is' + i + 'Active')) {
+ while (i < data.length && !getVal('Is' + i + 'Active')) {
i++
}
} catch (e) {
@@ -1121,7 +1119,7 @@ function HandleUI (url, count, subjCount) {
var loaded = count !== -1 // if script could load stuff
try {
- newVersion = GM_info.script.version !== GM_getValue('lastVerson')
+ newVersion = info().script.version !== getVal('lastVerson')
} catch (e) {
Log('Some weird error trying to set new verison')
}
@@ -1131,13 +1129,13 @@ function HandleUI (url, count, subjCount) {
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 = (getVal('showSplash') === undefined) || getVal('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) { // ------------------------------------------------------------------------------------------------
timeout = 5
- greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + GM_info.script.version + '. '
+ greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + info().script.version + '. '
- if (lastestVersion !== undefined && GM_info.script.version !== lastestVersion) {
+ if (lastestVersion !== undefined && info().script.version !== lastestVersion) {
greetMsg += 'Új verzió elérhető: ' + lastestVersion + '\n'
timeout = undefined
}
@@ -1162,24 +1160,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
+ greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + 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
- GM_setValue('lastVerson', GM_info.script.version) // setting lastVersion
+ greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + info().script.version + '. ' + count + ' kérdés és ' + subjCount + ' tárgy betöltve. Verzió frissítve ' + info().script.version + '-re. Changelog:\n' + lastChangeLog
+ setVal('lastVerson', info().script.version) // setting lastVersion
}
if (!SUtils.EmptyOrWhiteSpace(motd)) {
- var prevmotd = GM_getValue('motd')
+ var prevmotd = getVal('motd')
if (prevmotd !== motd) {
greetMsg += '\nMOTD:\n' + motd
timeout = null
- GM_setValue('motdcount', motdShowCount)
- GM_setValue('motd', motd)
+ setVal('motdcount', motdShowCount)
+ setVal('motd', motd)
} else {
- var motdcount = GM_getValue('motdcount')
+ var motdcount = getVal('motdcount')
if (motdcount === undefined) {
- GM_setValue('motdcount', motdShowCount)
+ setVal('motdcount', motdShowCount)
motdcount = motdShowCount
}
@@ -1187,7 +1185,7 @@ function HandleUI (url, count, subjCount) {
if (motdcount > 0) {
greetMsg += '\nMOTD:\n' + motd
timeout = null
- GM_setValue('motdcount', motdcount)
+ setVal('motdcount', motdcount)
}
}
}
@@ -1224,7 +1222,7 @@ function PrepareAnswers (result, j) {
var allMessages = [] // preparing all messages
for (var k = 0; k < result.length; k++) {
var msg = '' // the current message
- if ((GM_getValue('showQuestions') === undefined) || GM_getValue('showQuestions')) {
+ if ((getVal('showQuestions') === undefined) || getVal('showQuestions')) {
msg += result[k].q.Q + '\n' // adding the question if yes
}
msg += result[k].q.A.replace(/, /g, '\n') // adding answer
@@ -1250,7 +1248,7 @@ function ShowAnswers (answers) {
m: 'Nincs találat :( Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez! Előfordulhat, hogy a tárgyat nem válsztottad ki a menüben.',
isSimple: true
}, undefined, function () {
- GM_openInTab(serverAdress + 'lred', {
+ openInTab(serverAdress + 'lred', {
active: true
})
})
@@ -1272,7 +1270,7 @@ function ShowSaveQuizDialog (addedQ, allQ, allOutput, output, sendSuccess, sentD
if (addedQ > 0) {
msg = 'Klikk ide a nyers adatokhoz. ' + addedQ + ' új kérdés!'
- var useNetDB = GM_getValue('useNetDB')
+ var useNetDB = getVal('useNetDB')
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!' }
@@ -1288,7 +1286,7 @@ function ShowSaveQuizDialog (addedQ, allQ, allOutput, output, sendSuccess, sentD
var towrite = '' + sentData.subj + '
TXT-ben nem szereplő kérdések: ' + addedQ + '/' + allQ + '
' + output.replace(/\n/g, '
') + '
Összes kérdés/válasz:
' + allOutput.replace(
/\n/g, '
')
- var useNetDB = GM_getValue('useNetDB')
+ var useNetDB = getVal('useNetDB')
if (useNetDB !== undefined && useNetDB === 1) {
try {
towrite += 'Elküldött adatok: ' + JSON.stringify(sentData)
@@ -1374,11 +1372,11 @@ function SaveQuiz (quiz, questionData) {
sentData.subj = 'NOSUBJ'
Log('unable to get subject name :c')
}
- var useNetDB = GM_getValue('useNetDB')
+ var useNetDB = getVal('useNetDB')
if (useNetDB !== undefined && useNetDB === 1) {
sentData.allData = quiz
sentData.data = newQuestions
- sentData.version = GM_info.script.version
+ sentData.version = info().script.version
SendXHRMessage('datatoadd=' + JSON.stringify(sentData))
sendSuccess = true
}
@@ -1819,7 +1817,7 @@ function ShowMenu () {
// passive mode stuff
var questionsTickBox = document.createElement('input')
questionsTickBox.type = 'checkbox'
- questionsTickBox.checked = GM_getValue('skipLoad')
+ questionsTickBox.checked = getVal('skipLoad')
questionsTickBox.style.position = ''
questionsTickBox.style.left = 10 + 'px'
questionsTickBox.style.margin = '5px 5px 5px 5px' // fancy margin
@@ -1828,9 +1826,9 @@ function ShowMenu () {
menuButtonDiv.appendChild(questionsTickBox) // adding to main div
questionsTickBox.addEventListener('click', function () {
- GM_setValue('skipLoad', questionsTickBox.checked)
+ setVal('skipLoad', questionsTickBox.checked)
var msg = ''
- if (GM_getValue('skipLoad')) { msg = 'Passzív mód bekapcsolva, mostantól kérdések nem lesznek betöltve/lekérve.' } else { msg = 'Passzív mód kikapcsolva, frissíts az érvénybe lépéshez!' }
+ if (getVal('skipLoad')) { msg = 'Passzív mód bekapcsolva, mostantól kérdések nem lesznek betöltve/lekérve.' } else { msg = 'Passzív mód kikapcsolva, frissíts az érvénybe lépéshez!' }
ShowMessage({
m: msg,
@@ -1943,7 +1941,7 @@ function ShowMenuList () {
var noDataRow = tbl.insertRow()
var noDataRowCell = noDataRow.insertCell()
- if (GM_getValue('skipLoad')) {
+ if (getVal('skipLoad')) {
textBox = CreateNodeWithText(noDataRowCell,
'Passszív mód bekapcsolva. Kapcsold ki a kérdések betöltéséhez!'
)
@@ -1961,7 +1959,7 @@ function ShowMenuList () {
var splashTickBox = document.createElement('input')
splashTickBox.type = 'checkbox'
- splashTickBox.checked = GM_getValue('showSplash') || false
+ splashTickBox.checked = getVal('showSplash') || false
splashTickBox.style.position = ''
// splashTickBox.style.background = "white";
splashTickBox.style.left = 10 + 'px'
@@ -1970,7 +1968,7 @@ function ShowMenuList () {
splashTickboxCell.appendChild(splashTickBox) // adding to main div
splashTickBox.addEventListener('click', function () {
- GM_setValue('showSplash', splashTickBox.checked)
+ setVal('showSplash', splashTickBox.checked)
}) // adding clicktextNode
CreateNodeWithText(splashTickboxCell, 'Üdvözlő üzenet mutatása minden oldalon', 'span')
@@ -1981,7 +1979,7 @@ function ShowMenuList () {
var questionsTickBox = document.createElement('input')
questionsTickBox.type = 'checkbox'
- questionsTickBox.checked = GM_getValue('showQuestions')
+ questionsTickBox.checked = getVal('showQuestions')
questionsTickBox.style.position = ''
// questionsTickBox.style.background = "white";
questionsTickBox.style.left = 10 + 'px'
@@ -1990,7 +1988,7 @@ function ShowMenuList () {
questionTickboxCell.appendChild(questionsTickBox) // adding to main div
questionsTickBox.addEventListener('click', function () {
- GM_setValue('showQuestions', questionsTickBox.checked)
+ setVal('showQuestions', questionsTickBox.checked)
if (!questionsTickBox.checked) {
ShowMessage({
m: 'Szinte mindég jó az talált válasz a kérdésre, de attól még könnyen előfordulhat, hogy rosz kérdésre írja ki a választ! Ez a opció nélkül ezt az ellenőrzési lehetőséget nem tudod kihasználni',
@@ -2007,7 +2005,7 @@ function ShowMenuList () {
var databasemodeListbox = document.createElement('select')
databasemodeListbox.type = 'checkbox'
- // databasemodeListbox.checked = GM_getValue("showSplash") || false;
+ // databasemodeListbox.checked = getVal("showSplash") || false;
databasemodeListbox.style.position = ''
// databasemodeListbox.style.background = "white";
databasemodeListbox.style.left = 10 + 'px'
@@ -2022,7 +2020,7 @@ function ShowMenuList () {
databasemodeListbox.addEventListener('change', function (e) {
// sorry for using selectedindex :c
- GM_setValue('useNetDB', databasemodeListbox.selectedIndex)
+ setVal('useNetDB', databasemodeListbox.selectedIndex)
})
var uselocal = document.createElement('option')
@@ -2035,7 +2033,7 @@ function ShowMenuList () {
usenetsafe.value = 0
databasemodeListbox.add(usenetsafe, 1)
- var selected = GM_getValue('useNetDB')
+ var selected = getVal('useNetDB')
if (selected !== undefined) { databasemodeListbox.selectedIndex = selected }
var databasemodeListboxElement = document.createElement('span') // new paragraph
@@ -2118,7 +2116,7 @@ function CreateNodeWithText (to, text, type) {
function SendXHRMessage (message) {
var url = serverAdress + 'isAdding'
- GM_xmlhttpRequest({
+ xmlhttpRequest({
method: 'POST',
url: url,
data: message,
@@ -2141,7 +2139,7 @@ var assert = (val) => {
// shows some neat help
function ShowHelp () {
- GM_openInTab(serverAdress + 'manual', {
+ openInTab(serverAdress + 'manual', {
active: true
})
}
From 0c374906cada9bf07e9646282d885b1d58a3a090 Mon Sep 17 00:00:00 2001
From: MrFry
Date: Thu, 3 Oct 2019 14:38:42 +0200
Subject: [PATCH 7/9] Added index and active to subject. group by year on ui
prepare
---
main.js | 43 ++++++++++++++++++++++++++++++-------------
1 file changed, 30 insertions(+), 13 deletions(-)
diff --git a/main.js b/main.js
index 6afb117..5c585cd 100644
--- a/main.js
+++ b/main.js
@@ -24,7 +24,6 @@
// GM functions, only to disable ESLINT errors
/* eslint-disable */
-const location = location
const a = Main
function getVal (name) { return GM_getValue(name) }
function setVal (name, val) { return GM_setValue(name, val) }
@@ -210,6 +209,19 @@ class Subject {
this.Name = n
this.Questions = []
+ this.active = false
+ }
+
+ active () {
+ this.active = true
+ }
+
+ set index (i) {
+ this.index = i
+ }
+
+ get index () {
+ return this.index
}
get length () {
@@ -732,7 +744,7 @@ function Main () {
console.time('main')
Init(function (count, subjCount) {
- var url = location.href
+ var url = location.href // eslint-disable-line
let skipLoad = getVal('skipLoad')
if (count === -2 && subjCount === -2 && skipLoad) {
@@ -791,7 +803,7 @@ function Init (cwith) {
setVal('showQuestions', undefined)
setVal('showSplash', undefined)
}
- var url = location.href // window location
+ var url = location.href // eslint-disable-line
var count = -1 // loaded question count. stays -1 if the load failed.
// --------------------------------------------------------------------------------------
// event listener fuckery
@@ -1075,6 +1087,8 @@ function NLoad (resource, cwith) {
for (let i = 0; i < d.Subjects.length; i++) {
let s = new Subject(d.Subjects[i].Name)
if (getVal('Is' + i + 'Active')) {
+ s.active()
+ s.index = i
var j = 0
for (j = 0; j < d.Subjects[i].Questions.length; j++) {
var currQ = d.Subjects[i].Questions[j]
@@ -1895,15 +1909,20 @@ function ShowMenuList () {
var headerSubjInfoParagraph2 = CreateNodeWithText(header2, 'Aktív')
headerSubjInfoParagraph2.style.margin = fiveMargin // fancy margin
- // TODO: group here
if (data && data.length > 0) {
- for (let i = 0; i < data.length; i++) {
+ // TODO: group here
+ // let sorted = data.Subjects.sort((x) => {
+
+ // })
+ let sorted = data.Subjects
+
+ sorted.forEach((subj, i) => {
var subjRow = subjTable.insertRow()
subjRow.style.border = '1px solid #131319'
var td = subjRow.insertCell()
- var text = data.Subjects[i].Name
- if (data.Subjects[i].length !== 0) { text += ' [ ' + data.Subjects[i].length + 'db ]' }
+ var text = subj.Name
+ if (subj.length !== 0) { text += ' [ ' + subj.length + 'db ]' }
var textBox = CreateNodeWithText(td, text)
@@ -1916,16 +1935,13 @@ function ShowMenuList () {
checkbox.style.margin = '5px 5px 5px 5px' // fancy margin
td.appendChild(checkbox) // adding text box to main td
- var active = data.GetIfActive(i)
- checkbox.checked = active
-
+ checkbox.checked = subj.active
checkbox.setAttribute('id', 'HelperTextNode' + i)
-
checkbox.addEventListener('click', function () {
var checked = document.getElementById('HelperTextNode' + i).checked
data.ChangeActive(i, checked)
}) // adding click
- }
+ })
var scrollDiv = document.createElement('div')
scrollDiv.style.width = '100%'
@@ -1940,6 +1956,7 @@ function ShowMenuList () {
} else { // if no data
var noDataRow = tbl.insertRow()
var noDataRowCell = noDataRow.insertCell()
+ let textBox
if (getVal('skipLoad')) {
textBox = CreateNodeWithText(noDataRowCell,
@@ -2072,7 +2089,7 @@ function ShowMenuList () {
siteLink.innerText = 'Weboldal'
siteLink.addEventListener('click', function () {
- location.href = serverAdress + 'menuClick'
+ location.href = serverAdress + 'menuClick' // eslint-disable-line
})
// addEventListener(window, 'scroll', function () {
From 27692fe095d53f235060d92fe639717cd754a2fa Mon Sep 17 00:00:00 2001
From: MrFry
Date: Thu, 3 Oct 2019 14:40:13 +0200
Subject: [PATCH 8/9] frame update
---
frame.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/frame.js b/frame.js
index 1981181..a979689 100644
--- a/frame.js
+++ b/frame.js
@@ -23,7 +23,7 @@
// @name Moodle/Elearning/KMOOC test help
// @version 1.6.3.1
// @description Online Moodle/Elearning/KMOOC test help
-// @author YourFriendlyNeighborhoodDealer
+// @author MrFry
// @match https://elearning.uni-obuda.hu/main/*
// @match https://elearning.uni-obuda.hu/kmooc/*
// @match https://mooc.unideb.hu/*
@@ -34,8 +34,8 @@
// @grant GM_xmlhttpRequest
// @grant GM_openInTab
// @license GNU General Public License v3.0 or later
-// @supportURL qmining.tk
-// @contributionURL qmining.tk
+// @supportURL qmining.frylabs.net
+// @contributionURL qmining.frylabs.net
// @resource data file:///
// @namespace https://greasyfork.org/users/153067
// ==/UserScript==
From b647007337773ae08074bf7096be871db5478d9e Mon Sep 17 00:00:00 2001
From: MrFry
Date: Fri, 4 Oct 2019 20:29:55 +0200
Subject: [PATCH 9/9] Grouping subjects by year in menu
---
main.js | 155 +++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 113 insertions(+), 42 deletions(-)
diff --git a/main.js b/main.js
index 5c585cd..59e08f6 100644
--- a/main.js
+++ b/main.js
@@ -35,7 +35,7 @@ function info () { return GM_info }
var data // all data, which is in the resource txt
var addEventListener // add event listener function
-const lastChangeLog = 'Néhány szerkezeti átalakítás, és bugfix. Ha valami elromlott akkor pls report, thanx'
+const lastChangeLog = 'Félév szerinti csoportosítás menüben'
const serverAdress = 'https://qmining.frylabs.net/'
// forcing pages for testing. unless you test, do not set these to true!
@@ -212,28 +212,50 @@ class Subject {
this.active = false
}
- active () {
- this.active = true
- }
-
- set index (i) {
+ setIndex (i) {
this.index = i
}
- get index () {
- return this.index
+ getIndex () {
+ return this.index || -1
}
get length () {
return this.Questions.length
}
+ markActive () {
+ this.active = true
+ }
+
+ getIfActive () {
+ return this.active
+ }
+
AddQuestion (q) {
assert(q)
this.Questions.push(q)
}
+ getSubjNameWithoutYear () {
+ let t = this.Name.split(' - ')
+ if (t[0].match(/^[0-9]{4}\/[0-9]{2}\/[0-9]{1}$/i)) {
+ return t[1] || ''
+ } else {
+ return ''
+ }
+ }
+
+ getYear () {
+ let t = this.Name.split(' - ')[0]
+ if (t.match(/^[0-9]{4}\/[0-9]{2}\/[0-9]{1}$/i)) {
+ return t
+ } else {
+ return ''
+ }
+ }
+
Search (q, img) {
assert(q)
@@ -1086,9 +1108,9 @@ function NLoad (resource, cwith) {
for (let i = 0; i < d.Subjects.length; i++) {
let s = new Subject(d.Subjects[i].Name)
+ s.setIndex(i)
if (getVal('Is' + i + 'Active')) {
- s.active()
- s.index = i
+ s.markActive()
var j = 0
for (j = 0; j < d.Subjects[i].Questions.length; j++) {
var currQ = d.Subjects[i].Questions[j]
@@ -1894,53 +1916,102 @@ function ShowMenuList () {
tbl.style.width = '98%'
// adding headers ---------------------------------------------------------------------------------------------------------------
- var subjTable = document.createElement('table')
+ var subjTable = document.createElement('div')
subjTable.style.margin = fiveMargin
subjTable.style.textAlign = 'left'
subjTable.style.width = '98%'
- var tr = subjTable.insertRow()
- var header1 = tr.insertCell()
+ // 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 headerSubjInfoParagraph = CreateNodeWithText(header1, 'Tárgynév [darab kérdés]', 'center')
+ // headerSubjInfoParagraph.style.margin = fiveMargin // fancy margin
- var header2 = tr.insertCell()
- var headerSubjInfoParagraph2 = CreateNodeWithText(header2, 'Aktív')
- headerSubjInfoParagraph2.style.margin = fiveMargin // fancy margin
+ // var header2 = tr.insertCell()
+ // var headerSubjInfoParagraph2 = CreateNodeWithText(header2, 'Aktív')
+ // headerSubjInfoParagraph2.style.margin = fiveMargin // fancy margin
if (data && data.length > 0) {
- // TODO: group here
- // let sorted = data.Subjects.sort((x) => {
+ let grouped = data.Subjects.reduce((res, s) => {
+ let sName = s.getSubjNameWithoutYear()
+ if (sName) {
+ if (!res[sName]) {
+ res[sName] = []
+ }
+ res[sName].push(s)
+ } else {
+ res.others.push(s)
+ }
+ return res
+ }, {
+ others: []
+ })
- // })
- let sorted = data.Subjects
+ let collapsibles = []
- sorted.forEach((subj, i) => {
- var subjRow = subjTable.insertRow()
- subjRow.style.border = '1px solid #131319'
+ Object.entries(grouped).forEach(([subjName, subjGroup]) => {
+ let b = CreateNodeWithText(subjTable, subjName, 'button')
+ b.style.backgroundColor = '#222d32'
+ b.style.color = '#ffffff'
+ b.style.cursor = 'pointer'
+ b.style.padding = '5px'
+ b.style.width = '100%'
+ b.style.border = 'none'
+ b.style.textAlign = 'left'
+ b.style.outline = 'none'
+ collapsibles.push(b)
- var td = subjRow.insertCell()
- var text = subj.Name
- if (subj.length !== 0) { text += ' [ ' + subj.length + 'db ]' }
+ let content = document.createElement('div')
+ content.style.padding = '0 18px'
+ content.style.overflow = 'hidden'
+ content.style.backgroundColor = '#222d32'
+ content.style.borderColor = '#212127'
+ content.style.borderStyle = 'solid'
+ content.style.borderWidth = '5px'
+ let ifGroupActive = subjGroup.some((x) => {
+ return x.getIfActive()
+ })
+ content.style.display = ifGroupActive ? 'block' : 'none'
- var textBox = CreateNodeWithText(td, text)
+ subjTable.appendChild(content)
- textBox.style.margin = fiveMargin // fancy margin
+ subjGroup.forEach((subj) => {
+ let tbl = document.createElement('table')
+ content.appendChild(tbl)
- td = subjRow.insertCell()
- var checkbox = document.createElement('input') // new paragraph
- checkbox.type = 'checkbox'
- checkbox.style.background = 'white'
- checkbox.style.margin = '5px 5px 5px 5px' // fancy margin
- td.appendChild(checkbox) // adding text box to main td
+ var row = tbl.insertRow()
+ let td = row.insertCell()
+ let text = subj.getYear() || subj.Name
+ if (subj.length !== 0) { text += ' [ ' + subj.length + 'db ]' }
+ CreateNodeWithText(td, text)
- checkbox.checked = subj.active
- checkbox.setAttribute('id', 'HelperTextNode' + i)
- checkbox.addEventListener('click', function () {
- var checked = document.getElementById('HelperTextNode' + i).checked
- data.ChangeActive(i, checked)
- }) // adding click
+ td = row.insertCell()
+ let checkbox = document.createElement('input') // new paragraph
+ checkbox.type = 'checkbox'
+ checkbox.style.background = 'white'
+ checkbox.style.margin = '5px 5px 5px 5px' // fancy margin
+ td.appendChild(checkbox) // adding text box to main td
+
+ checkbox.checked = subj.active
+ let i = subj.getIndex()
+ checkbox.setAttribute('id', 'HelperTextNode' + i)
+ checkbox.addEventListener('click', function () {
+ var checked = document.getElementById('HelperTextNode' + i).checked
+ data.ChangeActive(i, checked)
+ }) // adding click
+ })
+ })
+
+ collapsibles.forEach((x) => {
+ x.addEventListener('click', function () {
+ this.classList.toggle('active')
+ var content = this.nextElementSibling
+ if (content.style.display === 'block') {
+ content.style.display = 'none'
+ } else {
+ content.style.display = 'block'
+ }
+ })
})
var scrollDiv = document.createElement('div')