Eslint formatting

This commit is contained in:
MrFry 2019-09-26 12:44:11 +02:00
parent a05973b6a0
commit 622dc1db31

327
main.js
View file

@ -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 data // all data, which is in the resource txt
var addEventListener // add event listener function var addEventListener // add event listener function
@ -717,14 +728,14 @@ var MPM = new MiscPageModell()
// : }}} // : }}}
// : Main function {{{ // : Main function {{{
function Main () { // eslint-disable-line function Main () {
'use strict' 'use strict'
console.time('main') console.time('main')
Init(function (count, subjCount) { 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 (count === -2 && subjCount === -2 && skipLoad) {
if (url.includes('/quiz/') && url.includes('attempt.php')) { if (url.includes('/quiz/') && url.includes('attempt.php')) {
ShowMessage({ 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!', m: 'Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!',
isSimple: true isSimple: true
}, undefined, function () { }, undefined, function () {
GM_openInTab(serverAdress + 'lred', { // eslint-disable-line GM_openInTab(serverAdress + 'lred', {
active: true active: true
}) })
}) })
@ -775,11 +786,11 @@ function Main () { // eslint-disable-line
function Init (cwith) { function Init (cwith) {
if (false) { // eslint-disable-line if (false) { // eslint-disable-line
GM_setValue('version16', undefined) // eslint-disable-line GM_setValue('version16', undefined)
GM_setValue('version15', undefined) // eslint-disable-line GM_setValue('version15', undefined)
GM_setValue('firstRun', undefined) // eslint-disable-line GM_setValue('firstRun', undefined)
GM_setValue('showQuestions', undefined) // eslint-disable-line GM_setValue('showQuestions', undefined)
GM_setValue('showSplash', undefined) // eslint-disable-line GM_setValue('showSplash', undefined)
} }
var url = location.href // window location var url = location.href // window location
var count = -1 // loaded question count. stays -1 if the load failed. var count = -1 // loaded question count. stays -1 if the load failed.
@ -844,7 +855,7 @@ function Version15 () {
'<h1>Moodle teszt userscript:<h1><h3>1.5.0 verzió: a script mostantól XMLHTTP kéréseket küld szerver fele! Erre a userscript futtató kiegészitőd is figyelmeztetni fog! Ha ez történik, a script rendes működése érdekében engedélyezd (Always allow domain)! Ha nem akarod, hogy ez történjen, akkor ne engedélyezd, vagy a menüben válaszd ki a "helyi fájl használata" opciót!</h3> <h3>Elküldött adatok: minden teszt után a kérdés-válasz páros. Fogadott adatok: Az összes eddig ismert kérdés. Érdemes help-et elolvasni!!!</h3><h5>Ez az ablak frissités után eltűnik. Ha nem, akkor a visza gombbal próbálkozz.</h5>' '<h1>Moodle teszt userscript:<h1><h3>1.5.0 verzió: a script mostantól XMLHTTP kéréseket küld szerver fele! Erre a userscript futtató kiegészitőd is figyelmeztetni fog! Ha ez történik, a script rendes működése érdekében engedélyezd (Always allow domain)! Ha nem akarod, hogy ez történjen, akkor ne engedélyezd, vagy a menüben válaszd ki a "helyi fájl használata" opciót!</h3> <h3>Elküldött adatok: minden teszt után a kérdés-válasz páros. Fogadott adatok: Az összes eddig ismert kérdés. Érdemes help-et elolvasni!!!</h3><h5>Ez az ablak frissités után eltűnik. Ha nem, akkor a visza gombbal próbálkozz.</h5>'
) )
document.close() 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 () { function Version161 () {
var version161 = GM_getValue('version161') // if the current run is the frst 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('useNetDB', '1')
GM_setValue('version161', false) GM_setValue('version161', false)
document.write( document.write(
'<h1>Moodle teszt userscript:<h1><h3>1.6.1.0 verzió: Új domain név: qmining.tk. Ha frissíted az oldalt, akkor tampremonkey rá fog kérdezni, hpgy engedélyezed-e a kérdések külését erre az új domain-re. A rendes működés érdekében kattints a "Allow always domain"-gombra</h3>' '<h1>Moodle teszt userscript:<h1><h3>1.6.1.0 verzió: Új domain név: qmining.tk. Ha frissíted az oldalt, akkor tampremonkey rá fog kérdezni, hpgy engedélyezed-e a kérdések külését erre az új domain-re. A rendes működés érdekében kattints a "Allow always domain"-gombra</h3>'
) )
document.close() 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 = '' var resource = ''
try { try {
resource = GetFileData() // getting data from txt resource = GetFileData() // getting data from txt
if (resource == undefined) { if (resource === undefined) {
ShowMessage({ ShowMessage({
m: 'Nem lehetett beolvasni a fájlt :c Ellenőrizd az elérési utat, vagy a fájl jogosultságokat', m: 'Nem lehetett beolvasni a fájlt :c Ellenőrizd az elérési utat, vagy a fájl jogosultságokat',
isSimple: true isSimple: true
@ -892,9 +902,7 @@ function ReadFile (cwith) {
return return
} }
if (SUtils.EmptyOrWhiteSpace(resource)) { if (SUtils.EmptyOrWhiteSpace(resource)) {
throw { throw 'data file empty' // eslint-disable-line
message: 'data file empty'
}
} }
} catch (e) { } catch (e) {
Exception(e, 'script error at reading file:') Exception(e, 'script error at reading file:')
@ -957,7 +965,7 @@ function ParseRawData (data) {
let currData = d[i].substring(1).trim() let currData = d[i].substring(1).trim()
if (currIdentifier == '+') { if (currIdentifier === '+') {
if (currQuestion.IsComplete()) { r.AddQuestion(currSubj, currQuestion) } if (currQuestion.IsComplete()) { r.AddQuestion(currSubj, currQuestion) }
currQuestion = new Question() currQuestion = new Question()
currSubj = currData currSubj = currData
@ -965,7 +973,7 @@ function ParseRawData (data) {
continue continue
} }
if (currIdentifier == '?') { if (currIdentifier === '?') {
if (currQuestion.IsComplete()) { if (currQuestion.IsComplete()) {
r.AddQuestion(currSubj, currQuestion) r.AddQuestion(currSubj, currQuestion)
currQuestion = new Question() currQuestion = new Question()
@ -977,9 +985,11 @@ function ParseRawData (data) {
continue continue
} }
if (currIdentifier == '!') { if (currIdentifier === '!') {
// if dont have question continue // 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 // dont allow overwriting
// ?!!!! // ?!!!!
if (!currQuestion.HasAnswer()) { if (!currQuestion.HasAnswer()) {
@ -992,10 +1002,14 @@ function ParseRawData (data) {
continue continue
} }
if (currIdentifier == '>') { if (currIdentifier === '>') {
// if dont have question or answer continue // if dont have question or answer continue
if (!currQuestion.HasQuestion()) { throw 'No question! (I)' } if (!currQuestion.HasQuestion()) {
if (!currQuestion.HasAnswer()) { throw 'No asnwer! (I)' } throw 'No question! (I)' // eslint-disable-line
}
if (!currQuestion.HasAnswer()) {
throw 'No asnwer! (I)' // eslint-disable-line
}
// dont allow overwriting // dont allow overwriting
// ?!>>> // ?!>>>
if (!currQuestion.HasImage()) { if (!currQuestion.HasImage()) {
@ -1025,7 +1039,7 @@ function Load (cwith) {
return -1 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) { function LoadMOTD (resource) {
@ -1075,7 +1089,7 @@ function NLoad (resource, cwith) {
LoadMOTD(d) LoadMOTD(d)
LoadVersion(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) let s = new Subject(d.Subjects[i].Name)
if (GM_getValue('Is' + i + 'Active')) { if (GM_getValue('Is' + i + 'Active')) {
var j = 0 var j = 0
@ -1095,7 +1109,7 @@ function NLoad (resource, cwith) {
data = r data = r
count = allCount + 1 // couse starting with -1 to show errors 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')) { while (i < data.length && !GM_getValue('Is' + i + 'Active')) {
i++ i++
} }
@ -1119,10 +1133,9 @@ function AlertOnNoQuestion () {
// : UI handling {{{ // : UI handling {{{
function HandleUI (url, count, subjCount) { function HandleUI (url, count, subjCount) {
var newVersion = false // if the script is newer than last start 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') newVersion = GM_info.script.version !== GM_getValue('lastVerson')
} catch (e) { } catch (e) {
Log('Some weird error trying to set new verison') 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 greetMsg = '' // message to show at the end
var timeout = null // the timeout. if null, it wont be hidden var timeout = null // the timeout. if null, it wont be hidden
// no new version, nothing loaded // no new version, nothing loaded
if (!newVersion && !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!'
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 // 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 timeout = 5
greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + GM_info.script.version + '. ' 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' greetMsg += 'Új verzió elérhető: ' + lastestVersion + '\n'
timeout = undefined timeout = undefined
} }
@ -1154,7 +1164,7 @@ function HandleUI (url, count, subjCount) {
toAdd.push(data.Subjects[i].Name + ' (' + data.Subjects[i].length + ')') 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(', ') + '.' greetMsg += '\nAktív tárgyak: ' + toAdd.join(', ') + '.'
} else { } else {
AlertOnNoQuestion() AlertOnNoQuestion()
@ -1166,30 +1176,24 @@ function HandleUI (url, count, subjCount) {
} }
} }
// new version, nothing loaded // new version, nothing loaded
if (newVersion && !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. ' + 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 // new version, everything loaded -> set lastVerson to current
if (newVersion && loaded) // -------------------------------------------------------------------------------------------------------------- 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
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 GM_setValue('lastVerson', GM_info.script.version) // setting lastVersion
} }
if (!SUtils.EmptyOrWhiteSpace(motd)) { if (!SUtils.EmptyOrWhiteSpace(motd)) {
var prevmotd = GM_getValue('motd') var prevmotd = GM_getValue('motd')
if (prevmotd != motd) { if (prevmotd !== motd) {
greetMsg += '\nMOTD:\n' + motd greetMsg += '\nMOTD:\n' + motd
timeout = null timeout = null
GM_setValue('motdcount', motdShowCount) GM_setValue('motdcount', motdShowCount)
GM_setValue('motd', motd) GM_setValue('motd', motd)
} else { } else {
var motdcount = GM_getValue('motdcount') var motdcount = GM_getValue('motdcount')
if (motdcount == undefined) { if (motdcount === undefined) {
GM_setValue('motdcount', motdShowCount) GM_setValue('motdcount', motdShowCount)
motdcount = motdShowCount motdcount = motdShowCount
} }
@ -1215,16 +1219,14 @@ function HandleUI (url, count, subjCount) {
function HandleQuiz () { function HandleQuiz () {
var q = QPM.GetQuestionFromTest() var q = QPM.GetQuestionFromTest()
var questions = q.q var questions = q.q
var allQuestions = q.allQ
var imgNodes = q.imgnodes var imgNodes = q.imgnodes
// ------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------
var answers = [] 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 question = SUtils.RemoveUnnecesarySpaces(questions[j]) // simplifying question
var result = data.Search(question, SimplifyImages(imgNodes)) var result = data.Search(question, SimplifyImages(imgNodes))
var r = PrepareAnswers(result, j) 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 HighLightAnswer(result, j) // highlights the answer for the current result
} }
ShowAnswers(answers) ShowAnswers(answers)
@ -1233,19 +1235,15 @@ function HandleQuiz () {
function PrepareAnswers (result, j) { function PrepareAnswers (result, j) {
assert(result) assert(result)
if (result.length > 0) // if there are more than zero results if (result.length > 0) {
{
var allMessages = [] // preparing all messages 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 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.Q + '\n' // adding the question if yes
} }
msg += result[k].q.A.replace(/, /g, '\n') // adding answer 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 msg += '\n' + result[k].q.I // if it has image part, adding that too
} }
allMessages.push({ allMessages.push({
@ -1279,7 +1277,6 @@ function ShowAnswers (answers) {
// : Quiz saving {{{ // : Quiz saving {{{
function HandleResults (url) { function HandleResults (url) {
var allResults = new QuestionDB()
var d = SaveQuiz(GetQuiz(), data) // saves the quiz questions and answers 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) } 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) { function ShowSaveQuizDialog (addedQ, allQ, allOutput, output, sendSuccess, sentData) {
var msg = '' var msg = ''
if (addedQ > 0) // if there are more than 0 new question if (addedQ > 0) {
{ msg = 'Klikk ide a nyers adatokhoz. ' + addedQ + ' új kérdés!'
msg = 'Klikk ide a nyers adatokhoz. ' + addedQ +
' új kérdés!'
var useNetDB = GM_getValue('useNetDB') 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.' } 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 { 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.' 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.' } 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, m: msg,
isSimple: true isSimple: true
}, null, function () { }, null, function () {
var towrite = '<h3>' + sentData.subj + '<br>TXT-ben nem szereplő kérdések: ' + addedQ + '/' + var towrite = '<h3>' + sentData.subj + '<br>TXT-ben nem szereplő kérdések: ' + addedQ + '/' + allQ + '</h3><br>' + output.replace(/\n/g, '<br>') + '<br><h3>Összes kérdés/válasz:</h3>' + allOutput.replace(
allQ + '</h3><br>' +
output.replace(/\n/g, '<br>') + '<br><h3>Összes kérdés/válasz:</h3>' + allOutput.replace(
/\n/g, '<br>') /\n/g, '<br>')
var useNetDB = GM_getValue('useNetDB') var useNetDB = GM_getValue('useNetDB')
if (useNetDB != undefined && useNetDB == 1) { if (useNetDB !== undefined && useNetDB === 1) {
try { try {
towrite += '</p>Elküldött adatok:</p> ' + JSON.stringify(sentData) towrite += '</p>Elküldött adatok:</p> ' + JSON.stringify(sentData)
} catch (e) { } catch (e) {
@ -1332,7 +1324,7 @@ function SearchSameQuestion (questionData, quiz, i) {
if (item.match > minResultMatchPercent) { count++ } 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 // 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 imgElements = RPM.GetResultImage(i) // trying to get image
var imgURL = [] // image urls var imgURL = [] // image urls
for (var j = 0; j < imgElements.length; j++) { 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 "/" var filePart = imgElements[j].src.split('/') // splits the link by "/"
filePart = filePart[filePart.length - 1] // the last one is the image name filePart = filePart[filePart.length - 1] // the last one is the image name
imgURL.push(decodeURI(SUtils.ShortenString(filePart, 30))) imgURL.push(decodeURI(SUtils.ShortenString(filePart, 30)))
@ -1362,8 +1353,8 @@ function GetImageFormResult (i) {
// saves the current quiz. questionData contains the active subjects questions // saves the current quiz. questionData contains the active subjects questions
function SaveQuiz (quiz, questionData) { function SaveQuiz (quiz, questionData) {
try { try {
if (quiz.length == 0) { if (quiz.length === 0) {
throw { throw { // eslint-disable-line
message: 'quiz length is zero!', message: 'quiz length is zero!',
stack: 'no stack.' stack: 'no stack.'
} }
@ -1373,8 +1364,7 @@ function SaveQuiz (quiz, questionData) {
var allQ = 0 var allQ = 0
var addedQ = 0 var addedQ = 0
var newQuestions = [] 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 // searching for same questions in questionData
var toAdd = '' // this will be added to some variable depending on if its already in the database 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 toAdd += '?' + SUtils.RemoveUnnecesarySpaces(quiz[i].Q) + '\n' // adding quiz question
@ -1382,8 +1372,7 @@ function SaveQuiz (quiz, questionData) {
if (quiz[i].HasImage()) { if (quiz[i].HasImage()) {
toAdd += '>' + SUtils.RemoveUnnecesarySpaces(quiz[i].I) + '\n' // adding quiz image if there is any 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 output += toAdd // adding to output
newQuestions.push(quiz[i]) newQuestions.push(quiz[i])
addedQ++ addedQ++
@ -1401,7 +1390,7 @@ function SaveQuiz (quiz, questionData) {
Log('unable to get subject name :c') Log('unable to get subject name :c')
} }
var useNetDB = GM_getValue('useNetDB') var useNetDB = GM_getValue('useNetDB')
if (useNetDB != undefined && useNetDB == 1) { if (useNetDB !== undefined && useNetDB === 1) {
sentData.allData = quiz sentData.allData = quiz
sentData.data = newQuestions sentData.data = newQuestions
sentData.version = GM_info.script.version sentData.version = GM_info.script.version
@ -1429,26 +1418,24 @@ function GetQuiz () {
try { try {
var quiz = [] // final quiz stuff var quiz = [] // final quiz stuff
var results = RPM.GetFormResult() // getting results element 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 var question = {} // the current question
// QUESTION -------------------------------------------------------------------------------------------------------------------- // QUESTION --------------------------------------------------------------------------------------------------------------------
var q = RPM.GetQuestionFromResult(i) var q = RPM.GetQuestionFromResult(i)
if (q != undefined) { question.q = SUtils.SimplifyQuery(q) } if (q !== undefined) { question.q = SUtils.SimplifyQuery(q) }
// RIGHTANSWER --------------------------------------------------------------------------------------------------------------------- // RIGHTANSWER ---------------------------------------------------------------------------------------------------------------------
var a = RPM.GetRightAnswerFromResultv2(i) var a = RPM.GetRightAnswerFromResultv2(i)
if (a == undefined) { a = RPM.GetRightAnswerFromResult(i) } if (a === undefined) { a = RPM.GetRightAnswerFromResult(i) }
if (a != undefined) { question.a = SUtils.SimplifyQuery(a) } if (a !== undefined) { question.a = SUtils.SimplifyQuery(a) }
// IMG --------------------------------------------------------------------------------------------------------------------- // IMG ---------------------------------------------------------------------------------------------------------------------
var img = GetImageFormResult(i) var img = GetImageFormResult(i)
question.i = img question.i = img
if (q != undefined) { q = SUtils.ReplaceCharsWithSpace(q, '\n') } if (q !== undefined) { q = SUtils.ReplaceCharsWithSpace(q, '\n') }
if (a != undefined) { a = SUtils.ReplaceCharsWithSpace(a, '\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 quiz.push(new Question(question.q, question.a, question.i)) // adding current question to quiz
} else { } else {
Log('error getting queston, no correct answer given, or its incorrect') Log('error getting queston, no correct answer given, or its incorrect')
@ -1467,10 +1454,8 @@ function GetQuiz () {
function SimplifyImages (imgs) { function SimplifyImages (imgs) {
var questionImages = [] // the array for the image names in question var questionImages = [] // the array for the image names in question
for (var i = 0; i < imgs.length; i++) // going through all image for (var i = 0; i < imgs.length; i++) {
{ if (!imgs[i].src.includes('brokenfile')) {
if (!imgs[i].src.includes('brokenfile')) // if its includes borken file its broken. Its another moodle crap. So i just wont check those
{
var filePart = imgs[i].src.split('/') // splits the link by "/" var filePart = imgs[i].src.split('/') // splits the link by "/"
filePart = filePart[filePart.length - 1] // the last one is the image name 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 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 // adds image names to image nodes
function AddImageNamesToImages (imgs) { function AddImageNamesToImages (imgs) {
for (var i = 0; i < imgs.length; i++) // going through all image for (var i = 0; i < imgs.length; i++) {
{ if (!imgs[i].src.includes('brokenfile')) {
if (!imgs[i].src.includes('brokenfile')) // if its includes borken file its broken. Its another moodle crap. So i just wont check those
{
var filePart = imgs[i].src.split('/') // splits the link by "/" var filePart = imgs[i].src.split('/') // splits the link by "/"
filePart = filePart[filePart.length - 1] // the last one is the image name filePart = filePart[filePart.length - 1] // the last one is the image name
var appedtTo = imgs[i].parentNode // it will be appended here 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. // this function adds basic hotkeys for video controll.
function AddVideoHotkeys (url) { function AddVideoHotkeys (url) {
var seekTime = 20 var seekTime = 20
document.addEventListener('keydown', function (e) // keydown event listener document.addEventListener('keydown', function (e) {
{
try { try {
var video = MPM.GetVideo() var video = MPM.GetVideo()
var keyCode = e.keyCode // getting keycode 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) e.preventDefault() // preventing default action (space scrolles down)
if (video.paused && video.buffered.length > 0) { if (video.paused && video.buffered.length > 0) {
video.play() video.play()
@ -1514,12 +1495,10 @@ function AddVideoHotkeys (url) {
video.pause() video.pause()
} }
} }
if (keyCode == 39) // rigth : 39 if (keyCode === 39) { // rigth : 39
{
video.currentTime += seekTime video.currentTime += seekTime
} }
if (keyCode == 37) // left : 37 if (keyCode === 37) { // left : 37
{
video.currentTime -= seekTime video.currentTime -= seekTime
} }
} catch (err) { } catch (err) {
@ -1533,20 +1512,6 @@ function AddVideoHotkeys (url) {
node.style.margin = '5px 5px 5px 5px' // fancy margin 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" // removes stuff like " a. q1" -> "q1"
function RemoveLetterMarking (inp) { function RemoveLetterMarking (inp) {
let dotIndex = inp.indexOf('.') let dotIndex = inp.indexOf('.')
@ -1559,15 +1524,12 @@ function RemoveLetterMarking (inp) {
// highlights the possible solutions to the current question // highlights the possible solutions to the current question
function HighLightAnswer (results, currQuestionNumber) { function HighLightAnswer (results, currQuestionNumber) {
try { 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 answers = RPM.GetAllAnswer(currQuestionNumber) // getting all answers
var toColor = [] // the numberth in the array will be colored, and .length items will be colored 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 var type = '' // type of the question. radio or ticbox or whatitscalled
for (var i = 0; i < answers.length; i++) // going thtough answers 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"
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 correct = results[0].q.A.toLowerCase() // getting current correct answer from data
var answer = answers[i].innerText.replace(/\n/g, '').toLowerCase() // getting current answer 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.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 toColor.push(i) // adding the index
type = MPM.GetInputType(answers, i) // setting the type type = MPM.GetInputType(answers, i) // setting the type
} }
} }
} }
if (results[0].match == 100) // if the result is 100% correct if (results[0].match === 100) { // if the result is 100% correct
{ if (type !== 'radio' || toColor.length === 1) { // TODO why not radio
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'
for (var i = 0; i < toColor.length; i++) // going through "toColor" }
{ answers[toColor[i]].style.backgroundColor = '#8cff66' }
} }
} // and coloring the correct index } // 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) Log('script error at highlightin answer: ' + e.message)
} }
} }
@ -1629,10 +1588,9 @@ function ShowMessage (msgItem, timeout, funct) {
var defMargin = '0px 5px 0px 5px' var defMargin = '0px 5px 0px 5px'
var isSimpleMessage = false var isSimpleMessage = false
var simpleMessageText = '' var simpleMessageText = ''
if (msgItem.isSimple) // parsing msgItem for easier use if (msgItem.isSimple) { // parsing msgItem for easier use
{
simpleMessageText = msgItem.m simpleMessageText = msgItem.m
if (simpleMessageText == '') { if (simpleMessageText === '') {
return return
} }
msgItem = [ msgItem = [
@ -1645,13 +1603,11 @@ function ShowMessage (msgItem, timeout, funct) {
var appedtTo = document.body // will be appended here var appedtTo = document.body // will be appended here
var width = window.innerWidth - window.innerWidth / 6 // with of the box 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 startFromTop = 25 // top distance
var mainDiv = document.createElement('div') // the main divider, wich items will be attached to var mainDiv = document.createElement('div') // the main divider, wich items will be attached to
mainDiv.setAttribute('id', 'messageMainDiv') 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 addEventListener(mainDiv, 'click', funct) // adding it as click
} }
// lotsa crap style // lotsa crap style
@ -1679,8 +1635,7 @@ function ShowMessage (msgItem, timeout, funct) {
mesageNode.style.margin = defMargin // fancy margin mesageNode.style.margin = defMargin // fancy margin
} }
mainDiv.appendChild(simpleMessageParagrapg) // adding text box to main div 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 ------------------------------------------------------------------------------------------------------------ // TABLE SETUP ------------------------------------------------------------------------------------------------------------
var table = document.createElement('table') var table = document.createElement('table')
table.style.width = '100%' table.style.width = '100%'
@ -1708,8 +1663,7 @@ function ShowMessage (msgItem, timeout, funct) {
var percentTextBox = CreateNodeWithText(percentTextCell, '') var percentTextBox = CreateNodeWithText(percentTextCell, '')
percentTextBox.setAttribute('id', 'percentTextBox') 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 + '%' percentTextBox.innerText = matchPercent + '%'
} }
// NUMBER SETUP ----------------------------------------------------------------------------------------------------- // NUMBER SETUP -----------------------------------------------------------------------------------------------------
@ -1724,12 +1678,11 @@ function ShowMessage (msgItem, timeout, funct) {
var currItem = 0 var currItem = 0
var currRelevantQuestion = 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] return msgItem[currItem][currRelevantQuestion]
} }
function ChangeCurrItemIndex (to) { const ChangeCurrItemIndex = (to) => {
currItem += to currItem += to
if (currItem < 0) { if (currItem < 0) {
currItem = 0 currItem = 0
@ -1740,7 +1693,7 @@ function ShowMessage (msgItem, timeout, funct) {
currRelevantQuestion = 0 currRelevantQuestion = 0
} }
function ChangeCurrRelevantQuestionIndex (to) { const ChangeCurrRelevantQuestionIndex = (to) => {
currRelevantQuestion += to currRelevantQuestion += to
if (currRelevantQuestion < 0) { if (currRelevantQuestion < 0) {
currRelevantQuestion = 0 currRelevantQuestion = 0
@ -1750,10 +1703,10 @@ function ShowMessage (msgItem, timeout, funct) {
} }
} }
function SetQuestionText () { const SetQuestionText = () => {
var relevantQuestion = GetRelevantQuestion() var relevantQuestion = GetRelevantQuestion()
questionTextElement.innerText = relevantQuestion.m questionTextElement.innerText = relevantQuestion.m
if (currItem == 0 && currRelevantQuestion == 0) { if (currItem === 0 && currRelevantQuestion === 0) {
numberTextBox.innerText = (currRelevantQuestion + 1) + '.' numberTextBox.innerText = (currRelevantQuestion + 1) + '.'
} else { } else {
numberTextBox.innerText = (currItem + 1) + './' + (currRelevantQuestion + 1) + '.' numberTextBox.innerText = (currItem + 1) + './' + (currRelevantQuestion + 1) + '.'
@ -1781,10 +1734,9 @@ function ShowMessage (msgItem, timeout, funct) {
}) })
} }
// deciding if has multiple questions ------------------------------------------------------------------------------------------------ // deciding if has multiple questions ------------------------------------------------------------------------------------------------
if (msgItem.length == 1) { if (msgItem.length === 1) {
SetQuestionText() SetQuestionText()
} else // if there are multiple items to display } else { // if there are multiple items to display
{
// PREV QUESTION BUTTON ------------------------------------------------------------------------------------------------------------ // PREV QUESTION BUTTON ------------------------------------------------------------------------------------------------------------
var prevButton = CreateNodeWithText(prevQuestionCell, '^', 'button') var prevButton = CreateNodeWithText(prevQuestionCell, '^', 'button')
prevButton.style.margin = buttonMargin // fancy margin prevButton.style.margin = buttonMargin // fancy margin
@ -1810,21 +1762,20 @@ function ShowMessage (msgItem, timeout, funct) {
// setting some events // setting some events
// addEventListener(window, 'scroll', function () { // addEventListener(window, 'scroll', function () {
// mainDiv.style.top = (pageYOffset + startFromTop) + 'px'; // mainDiv.style.top = (pageYOffset + startFromTop) + 'px';
// }) // })
addEventListener(window, 'resize', function () { addEventListener(window, 'resize', function () {
mainDiv.style.left = (window.innerWidth - width) / 2 + 'px' mainDiv.style.left = (window.innerWidth - width) / 2 + 'px'
}) })
var timeOut 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 () { timeOut = setTimeout(function () {
mainDiv.parentNode.removeChild(mainDiv) mainDiv.parentNode.removeChild(mainDiv)
}, timeout * 1000) }, timeout * 1000)
} }
// middle click close event listener // middle click close event listener
addEventListener(mainDiv, 'mousedown', function (e) { addEventListener(mainDiv, 'mousedown', function (e) {
if (e.which == 2) { if (e.which === 2) {
mainDiv.parentNode.removeChild(mainDiv) mainDiv.parentNode.removeChild(mainDiv)
if (timeOut) { if (timeOut) {
clearTimeout(timeOut) clearTimeout(timeOut)
@ -1951,16 +1902,6 @@ function ShowMenuList () {
subjTable.style.textAlign = 'left' subjTable.style.textAlign = 'left'
subjTable.style.width = '98%' 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) { if (data && data.length > 0) {
for (let i = 0; i < data.length; i++) { for (let i = 0; i < data.length; i++) {
var subjRow = subjTable.insertRow() var subjRow = subjTable.insertRow()
@ -1968,7 +1909,7 @@ function ShowMenuList () {
var td = subjRow.insertCell() var td = subjRow.insertCell()
var text = data.Subjects[i].Name 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) var textBox = CreateNodeWithText(td, text)
@ -1978,8 +1919,7 @@ function ShowMenuList () {
var checkbox = document.createElement('input') // new paragraph var checkbox = document.createElement('input') // new paragraph
checkbox.type = 'checkbox' checkbox.type = 'checkbox'
checkbox.style.background = 'white' checkbox.style.background = 'white'
checkbox.style.margin = checkbox.style.margin = '5px 5px 5px 5px' // fancy margin
'5px 5px 5px 5px' // fancy margin
td.appendChild(checkbox) // adding text box to main td td.appendChild(checkbox) // adding text box to main td
var active = data.GetIfActive(i) var active = data.GetIfActive(i)
@ -2003,11 +1943,9 @@ function ShowMenuList () {
var subjtblrow = tbl.insertRow() var subjtblrow = tbl.insertRow()
var subjtbltd = subjtblrow.insertCell() var subjtbltd = subjtblrow.insertCell()
subjtbltd.appendChild(scrollDiv) subjtbltd.appendChild(scrollDiv)
} else // if no data } else { // if no data
{
var noDataRow = tbl.insertRow() var noDataRow = tbl.insertRow()
var noDataRowCell = noDataRow.insertCell() var noDataRowCell = noDataRow.insertCell()
var textBox
if (GM_getValue('skipLoad')) { if (GM_getValue('skipLoad')) {
textBox = CreateNodeWithText(noDataRowCell, textBox = CreateNodeWithText(noDataRowCell,
@ -2039,9 +1977,6 @@ function ShowMenuList () {
GM_setValue('showSplash', splashTickBox.checked) GM_setValue('showSplash', splashTickBox.checked)
}) // adding clicktextNode }) // adding clicktextNode
var splashTickBoxTextSpan = CreateNodeWithText(splashTickboxCell,
'Üdvözlő üzenet mutatása minden oldalon', 'span')
// show questons tickbox ----------------------------------------------------------------------------------------------------------------------------- // show questons tickbox -----------------------------------------------------------------------------------------------------------------------------
var questionTickboxRow = tbl.insertRow() var questionTickboxRow = tbl.insertRow()
var questionTickboxCell = questionTickboxRow.insertCell() var questionTickboxCell = questionTickboxRow.insertCell()
@ -2065,8 +2000,6 @@ function ShowMenuList () {
}, 7) }, 7)
} }
}) // adding clicktextNode }) // adding clicktextNode
var questionsTickBoxTextSpan = CreateNodeWithText(questionTickboxCell,
'Kérdések mutatása válaszhoz', 'span')
// database mode listbox ----------------------------------------------------------------------------------------------------------------------------- // database mode listbox -----------------------------------------------------------------------------------------------------------------------------
var databasemodeListboxRow = tbl.insertRow() var databasemodeListboxRow = tbl.insertRow()
@ -2103,7 +2036,7 @@ function ShowMenuList () {
databasemodeListbox.add(usenetsafe, 1) databasemodeListbox.add(usenetsafe, 1)
var selected = GM_getValue('useNetDB') var selected = GM_getValue('useNetDB')
if (selected != undefined) { databasemodeListbox.selectedIndex = selected } if (selected !== undefined) { databasemodeListbox.selectedIndex = selected }
var databasemodeListboxElement = document.createElement('span') // new paragraph var databasemodeListboxElement = document.createElement('span') // new paragraph
databasemodeListboxCell.appendChild(databasemodeListboxElement) databasemodeListboxCell.appendChild(databasemodeListboxElement)
@ -2145,7 +2078,7 @@ function ShowMenuList () {
}) })
// addEventListener(window, 'scroll', function () { // addEventListener(window, 'scroll', function () {
// menuDiv.style.top = (pageYOffset + window.innerHeight / 3) + 'px'; // menuDiv.style.top = (pageYOffset + window.innerHeight / 3) + 'px';
// }) // })
addEventListener(window, 'resize', function () { addEventListener(window, 'resize', function () {
menuDiv.style.left = window.innerWidth / 2 + 'px' menuDiv.style.left = window.innerWidth / 2 + 'px'
@ -2161,7 +2094,7 @@ function ShowMenuList () {
} }
function EscClose (e) { function EscClose (e) {
if (e.keyCode == 27) { CloseMenu() } if (e.keyCode === 27) { CloseMenu() }
} }
function CloseMenu () { function CloseMenu () {
@ -2175,20 +2108,6 @@ function CloseMenu () {
// : Generic utils {{{ // : 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) { function CreateNodeWithText (to, text, type) {
var paragraphElement = document.createElement(type || 'p') // new paragraph var paragraphElement = document.createElement(type || 'p') // new paragraph
var textNode = document.createTextNode(text) var textNode = document.createTextNode(text)