diff --git a/frame.js b/frame.js index e2e2f6e..5b36b91 100644 --- a/frame.js +++ b/frame.js @@ -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== diff --git a/main.js b/main.js index 177013c..67480d3 100644 --- a/main.js +++ b/main.js @@ -20,13 +20,22 @@ ------------------------------------------------------------------------- */ -/* TODO - * remove stuff like "b. answer", "c. answer" .... - * */ +// ------------------------------------------------------------------------------ + +// GM functions, only to disable ESLINT errors +/* eslint-disable */ +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 -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! @@ -200,18 +209,53 @@ class Subject { this.Name = n this.Questions = [] + this.active = false + } + + setIndex (i) { + this.index = i + } + + 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) @@ -258,7 +302,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) } } @@ -266,11 +310,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) { @@ -511,7 +555,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') } } @@ -540,7 +584,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 +606,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 +663,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 +697,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++ } @@ -703,9 +766,9 @@ function Main () { 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 = getVal('skipLoad') if (count === -2 && subjCount === -2 && skipLoad) { if (url.includes('/quiz/') && url.includes('attempt.php')) { ShowMessage({ @@ -728,7 +791,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 }) }) @@ -755,14 +818,14 @@ 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 + setVal('version16', undefined) + setVal('version15', undefined) + setVal('firstRun', undefined) + 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 @@ -791,82 +854,64 @@ function Init (cwith) { function VersionActions () { // FOR TESTING ONLY - // GM_setValue("version15", true); - // GM_setValue("firstRun", true); - // GM_setValue("version16", true); - // GM_setValue("version161", true); + // setVal("version15", true); + // setVal("firstRun", true); + // setVal("version16", true); // throw "asd"; - let r = FreshStart() - if (r !== true) { GM_setValue('version161', false) } + FreshStart() Version15() Version16() - Version161() } // : 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.
' ) document.close() - throw 'something, so this stuff stops' + throw 'something, so this stuff stops' // eslint-disable-line } } function Version16 () { - var version16 = GM_getValue('version16') // if the current run is the frst - if (version16 == undefined || version16 == true) // if its undefined, or true - { + 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) - } -} - -function Version161 () { - var version161 = GM_getValue('version161') // if the current run is the frst - if (version161 == undefined || version161 == true) // if its undefined, or 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' + setVal('version16', false) } } // : }}} var GetFileData = () => { - return GM_getResourceText('data') + return getResourceText('data') } 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 @@ -874,9 +919,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:') @@ -887,7 +930,7 @@ function ReadFile (cwith) { function ReadNetDB (cwith, useNetDB) { function NewXMLHttpRequest () { const url = serverAdress + 'data.json' - GM_xmlhttpRequest({ + xmlhttpRequest({ method: 'GET', synchronous: true, url: url, @@ -939,7 +982,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 @@ -947,7 +990,7 @@ function ParseRawData (data) { continue } - if (currIdentifier == '?') { + if (currIdentifier === '?') { if (currQuestion.IsComplete()) { r.AddQuestion(currSubj, currQuestion) currQuestion = new Question() @@ -959,9 +1002,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()) { @@ -974,10 +1019,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()) { @@ -999,15 +1048,15 @@ 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) 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) { @@ -1057,9 +1106,11 @@ 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')) { + s.setIndex(i) + if (getVal('Is' + i + 'Active')) { + s.markActive() var j = 0 for (j = 0; j < d.Subjects[i].Questions.length; j++) { var currQ = d.Subjects[i].Questions[j] @@ -1077,8 +1128,8 @@ function NLoad (resource, cwith) { data = r count = allCount + 1 // couse starting with -1 to show errors - var i = 0 - while (i < data.length && !GM_getValue('Is' + i + 'Active')) { + let i = 0 + while (i < data.length && !getVal('Is' + i + 'Active')) { i++ } } catch (e) { @@ -1101,30 +1152,26 @@ 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 - { - newVersion = GM_info.script.version !== GM_getValue('lastVerson') + try { + newVersion = info().script.version !== getVal('lastVerson') } catch (e) { Log('Some weird error trying to set new verison') } 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 = (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) // ------------------------------------------------------------------------------------------------ - { + 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 } @@ -1136,7 +1183,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() @@ -1148,31 +1195,25 @@ 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. ' + 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 + if (newVersion && loaded) { // -------------------------------------------------------------------------------------------------------------- + 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') - if (prevmotd != 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') - if (motdcount == undefined) { - GM_setValue('motdcount', motdShowCount) + var motdcount = getVal('motdcount') + if (motdcount === undefined) { + setVal('motdcount', motdShowCount) motdcount = motdShowCount } @@ -1180,7 +1221,7 @@ function HandleUI (url, count, subjCount) { if (motdcount > 0) { greetMsg += '\nMOTD:\n' + motd timeout = null - GM_setValue('motdcount', motdcount) + setVal('motdcount', motdcount) } } } @@ -1197,16 +1238,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) @@ -1215,19 +1254,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 ((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 - 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({ @@ -1249,7 +1284,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 }) }) @@ -1261,7 +1296,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) } @@ -1269,17 +1303,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) { + 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!' } - } 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.' } } @@ -1288,13 +1319,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) { + var useNetDB = getVal('useNetDB') + if (useNetDB !== undefined && useNetDB === 1) { try { towrite += '

Elküldött adatok:

' + JSON.stringify(sentData) } catch (e) { @@ -1314,7 +1343,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 @@ -1325,8 +1354,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))) @@ -1344,8 +1372,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.' } @@ -1355,8 +1383,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 @@ -1364,8 +1391,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++ @@ -1382,11 +1408,11 @@ function SaveQuiz (quiz, questionData) { sentData.subj = 'NOSUBJ' Log('unable to get subject name :c') } - var useNetDB = GM_getValue('useNetDB') - if (useNetDB != undefined && useNetDB == 1) { + 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 } @@ -1411,26 +1437,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') @@ -1449,10 +1473,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 @@ -1463,10 +1485,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 @@ -1482,13 +1502,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() @@ -1496,12 +1514,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) { @@ -1515,20 +1531,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('.') @@ -1541,15 +1543,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 @@ -1558,24 +1557,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) } } @@ -1611,10 +1607,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 = [ @@ -1627,13 +1622,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 @@ -1661,8 +1654,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%' @@ -1690,8 +1682,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 ----------------------------------------------------------------------------------------------------- @@ -1706,12 +1697,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 @@ -1722,7 +1712,7 @@ function ShowMessage (msgItem, timeout, funct) { currRelevantQuestion = 0 } - function ChangeCurrRelevantQuestionIndex (to) { + const ChangeCurrRelevantQuestionIndex = (to) => { currRelevantQuestion += to if (currRelevantQuestion < 0) { currRelevantQuestion = 0 @@ -1732,10 +1722,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) + '.' @@ -1763,10 +1753,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 @@ -1792,21 +1781,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) @@ -1865,7 +1853,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 @@ -1874,9 +1862,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, @@ -1928,52 +1916,103 @@ 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 headerSubjInfoParagraph = CreateNodeWithText(header2, 'Aktív') - headerSubjInfoParagraph.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) { - for (let i = 0; i < data.length; i++) { - var subjRow = subjTable.insertRow() - subjRow.style.border = '1px solid #131319' + 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: [] + }) - var td = subjRow.insertCell() - var text = data.Subjects[i].Name - if (data.Subjects[i].length != 0) { text += ' [ ' + data.Subjects[i].length + 'db ]' } + let collapsibles = [] - var textBox = CreateNodeWithText(td, text) + 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) - textBox.style.margin = fiveMargin // fancy margin + 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' - 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 + subjTable.appendChild(content) - var active = data.GetIfActive(i) - checkbox.checked = active + subjGroup.forEach((subj) => { + let tbl = document.createElement('table') + content.appendChild(tbl) - checkbox.setAttribute('id', 'HelperTextNode' + i) + 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.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') scrollDiv.style.width = '100%' @@ -1985,13 +2024,12 @@ 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 + let textBox - 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!' ) @@ -2009,7 +2047,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' @@ -2018,11 +2056,10 @@ function ShowMenuList () { splashTickboxCell.appendChild(splashTickBox) // adding to main div splashTickBox.addEventListener('click', function () { - GM_setValue('showSplash', splashTickBox.checked) + setVal('showSplash', splashTickBox.checked) }) // adding clicktextNode - var splashTickBoxTextSpan = CreateNodeWithText(splashTickboxCell, - 'Üdvözlő üzenet mutatása minden oldalon', 'span') + CreateNodeWithText(splashTickboxCell, 'Üdvözlő üzenet mutatása minden oldalon', 'span') // show questons tickbox ----------------------------------------------------------------------------------------------------------------------------- var questionTickboxRow = tbl.insertRow() @@ -2030,7 +2067,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' @@ -2039,7 +2076,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', @@ -2047,8 +2084,8 @@ function ShowMenuList () { }, 7) } }) // adding clicktextNode - var questionsTickBoxTextSpan = CreateNodeWithText(questionTickboxCell, - 'Kérdések mutatása válaszhoz', 'span') + + CreateNodeWithText(questionTickboxCell, 'Kérdések mutatása válaszhoz', 'span') // database mode listbox ----------------------------------------------------------------------------------------------------------------------------- var databasemodeListboxRow = tbl.insertRow() @@ -2056,7 +2093,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' @@ -2071,7 +2108,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') @@ -2084,8 +2121,8 @@ function ShowMenuList () { usenetsafe.value = 0 databasemodeListbox.add(usenetsafe, 1) - var selected = GM_getValue('useNetDB') - if (selected != undefined) { databasemodeListbox.selectedIndex = selected } + var selected = getVal('useNetDB') + if (selected !== undefined) { databasemodeListbox.selectedIndex = selected } var databasemodeListboxElement = document.createElement('span') // new paragraph databasemodeListboxCell.appendChild(databasemodeListboxElement) @@ -2123,11 +2160,11 @@ function ShowMenuList () { siteLink.innerText = 'Weboldal' siteLink.addEventListener('click', function () { - location.href = serverAdress + 'menuClick' + location.href = serverAdress + 'menuClick' // eslint-disable-line }) // 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' @@ -2143,7 +2180,7 @@ function ShowMenuList () { } function EscClose (e) { - if (e.keyCode == 27) { CloseMenu() } + if (e.keyCode === 27) { CloseMenu() } } function CloseMenu () { @@ -2157,20 +2194,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) @@ -2181,7 +2204,7 @@ function CreateNodeWithText (to, text, type) { function SendXHRMessage (message) { var url = serverAdress + 'isAdding' - GM_xmlhttpRequest({ + xmlhttpRequest({ method: 'POST', url: url, data: message, @@ -2204,7 +2227,7 @@ var assert = (val) => { // shows some neat help function ShowHelp () { - GM_openInTab(serverAdress + 'manual', { + openInTab(serverAdress + 'manual', { active: true }) }