diff --git a/main.js b/main.js index fa8aea6..6afb117 100644 --- a/main.js +++ b/main.js @@ -21,19 +21,18 @@ ------------------------------------------------------------------------- */ // ------------------------------------------------------------------------------ -// REMOVE THIS, only to disable ESLINT errors -// ------------------------------------------------------------------------------ + +// GM functions, only to disable ESLINT errors /* eslint-disable */ -// const GM_getValue = 0 -// const GM_info = 0 -// const GM_setValue = 0 -// const GM_xmlhttpRequest = 0 -// const GM_openInTab = 0 -// const GM_getResourceText = 0 -// Main() -// const location = 0 +const location = location +const a = Main +function getVal (name) { return GM_getValue(name) } +function setVal (name, val) { return GM_setValue(name, val) } +function openInTab (address, options) { GM_openInTab(address, options) } +function getResourceText (name) { return GM_getResourceText(name) } +function xmlhttpRequest (opts) { GM_xmlhttpRequest(opts) } +function info () { return GM_info } /* eslint-enable */ -// ------------------------------------------------------------------------------ var data // all data, which is in the resource txt var addEventListener // add event listener function @@ -269,7 +268,7 @@ class QuestionDB { get activeIndexes () { var r = [] for (var i = 0; i < this.length; i++) { - if (GM_getValue('Is' + i + 'Active')) { + if (getVal('Is' + i + 'Active')) { r.push(i) } } @@ -277,11 +276,11 @@ class QuestionDB { } GetIfActive (ind) { - return GM_getValue('Is' + ind + 'Active') + return getVal('Is' + ind + 'Active') } ChangeActive (i, value) { - GM_setValue('Is' + i + 'Active', !!value) + setVal('Is' + i + 'Active', !!value) } AddQuestion (subj, q) { @@ -735,7 +734,7 @@ function Main () { Init(function (count, subjCount) { var url = location.href - let skipLoad = GM_getValue('skipLoad') + let skipLoad = getVal('skipLoad') if (count === -2 && subjCount === -2 && skipLoad) { if (url.includes('/quiz/') && url.includes('attempt.php')) { ShowMessage({ @@ -758,7 +757,7 @@ function Main () { m: 'Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!', isSimple: true }, undefined, function () { - GM_openInTab(serverAdress + 'lred', { + openInTab(serverAdress + 'lred', { active: true }) }) @@ -771,7 +770,6 @@ function Main () { } }) - console.log('Moodle Test Script run time:') console.timeEnd('main') @@ -787,11 +785,11 @@ function Main () { function Init (cwith) { if (false) { // eslint-disable-line - GM_setValue('version16', undefined) - GM_setValue('version15', undefined) - GM_setValue('firstRun', undefined) - GM_setValue('showQuestions', undefined) - GM_setValue('showSplash', undefined) + setVal('version16', undefined) + setVal('version15', undefined) + setVal('firstRun', undefined) + setVal('showQuestions', undefined) + setVal('showSplash', undefined) } var url = location.href // window location var count = -1 // loaded question count. stays -1 if the load failed. @@ -822,9 +820,9 @@ function Init (cwith) { function VersionActions () { // FOR TESTING ONLY - // GM_setValue("version15", true); - // GM_setValue("firstRun", true); - // GM_setValue("version16", true); + // setVal("version15", true); + // setVal("firstRun", true); + // setVal("version16", true); // throw "asd"; FreshStart() @@ -836,19 +834,19 @@ function VersionActions () { // : Version action functions {{{ function FreshStart () { - var firstRun = GM_getValue('firstRun') // if the current run is the frst + var firstRun = getVal('firstRun') // if the current run is the frst if (firstRun === undefined || firstRun === true) { - GM_setValue('firstRun', false) + setVal('firstRun', false) ShowHelp() // showing help return true } } function Version15 () { - var version15 = GM_getValue('version15') // if the current run is the frst + var version15 = getVal('version15') // if the current run is the frst if (version15 === undefined || version15 === true) { - GM_setValue('useNetDB', '1') - GM_setValue('version15', false) + setVal('useNetDB', '1') + setVal('version15', false) document.write( '

Moodle teszt userscript:

1.5.0 verzió: a script mostantól XMLHTTP kéréseket küld szerver fele! Erre a userscript futtató kiegészitőd is figyelmeztetni fog! Ha ez történik, a script rendes működése érdekében engedélyezd (Always allow domain)! Ha nem akarod, hogy ez történjen, akkor ne engedélyezd, vagy a menüben válaszd ki a "helyi fájl használata" opciót!

Elküldött adatok: minden teszt után a kérdés-válasz páros. Fogadott adatok: Az összes eddig ismert kérdés. Érdemes help-et elolvasni!!!

Ez az ablak frissités után eltűnik. Ha nem, akkor a visza gombbal próbálkozz.
' ) @@ -858,21 +856,21 @@ function Version15 () { } function Version16 () { - var version16 = GM_getValue('version16') // if the current run is the frst + var version16 = getVal('version16') // if the current run is the frst if (version16 === undefined || version16 === true) { var i = 0 - while (GM_getValue('Is' + i + 'Active') !== undefined) { - GM_setValue('Is' + i + 'Active', false) + while (getVal('Is' + i + 'Active') !== undefined) { + setVal('Is' + i + 'Active', false) i++ } - GM_setValue('version16', false) + setVal('version16', false) } } // : }}} var GetFileData = () => { - return GM_getResourceText('data') + return getResourceText('data') } function ReadFile (cwith) { @@ -898,7 +896,7 @@ function ReadFile (cwith) { function ReadNetDB (cwith, useNetDB) { function NewXMLHttpRequest () { const url = serverAdress + 'data.json' - GM_xmlhttpRequest({ + xmlhttpRequest({ method: 'GET', synchronous: true, url: url, @@ -1016,8 +1014,8 @@ function ParseRawData (data) { } function Load (cwith) { - var useNetDB = GM_getValue('useNetDB') - let skipLoad = GM_getValue('skipLoad') + var useNetDB = getVal('useNetDB') + let skipLoad = getVal('skipLoad') if (skipLoad) { cwith(-2, -2) @@ -1076,7 +1074,7 @@ function NLoad (resource, cwith) { for (let i = 0; i < d.Subjects.length; i++) { let s = new Subject(d.Subjects[i].Name) - if (GM_getValue('Is' + i + 'Active')) { + if (getVal('Is' + i + 'Active')) { var j = 0 for (j = 0; j < d.Subjects[i].Questions.length; j++) { var currQ = d.Subjects[i].Questions[j] @@ -1095,7 +1093,7 @@ function NLoad (resource, cwith) { count = allCount + 1 // couse starting with -1 to show errors let i = 0 - while (i < data.length && !GM_getValue('Is' + i + 'Active')) { + while (i < data.length && !getVal('Is' + i + 'Active')) { i++ } } catch (e) { @@ -1121,7 +1119,7 @@ function HandleUI (url, count, subjCount) { var loaded = count !== -1 // if script could load stuff try { - newVersion = GM_info.script.version !== GM_getValue('lastVerson') + newVersion = info().script.version !== getVal('lastVerson') } catch (e) { Log('Some weird error trying to set new verison') } @@ -1131,13 +1129,13 @@ function HandleUI (url, count, subjCount) { if (!newVersion && !loaded) { // -------------------------------------------------------------------------------------------------------------- greetMsg = 'Hiba a @resource tagnál, vagy a fileval van gond! (Lehet át lett helyezve, vagy üres, vagy nincs tárgy kiválasztva) Vagy válaszd a netes adatok használatát menüben. Ellenőrizd az elérési utat, vagy hogy a Tampermonkey bővítmény eléri-e a fájlokat. Ha netes forrást használsz, akkor nem elérhető a szerver! Segítségért kattints!' } - var showSplash = (GM_getValue('showSplash') === undefined) || GM_getValue('showSplash') // getting value, if splash screen should be shown. Its true, if its undefined, or true + var showSplash = (getVal('showSplash') === undefined) || getVal('showSplash') // getting value, if splash screen should be shown. Its true, if its undefined, or true // no new version, everything loaded, and show splash is enabled. otherwise something happened, so showing it if (!newVersion && loaded && showSplash) { // ------------------------------------------------------------------------------------------------ timeout = 5 - greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + GM_info.script.version + '. ' + greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + info().script.version + '. ' - if (lastestVersion !== undefined && GM_info.script.version !== lastestVersion) { + if (lastestVersion !== undefined && info().script.version !== lastestVersion) { greetMsg += 'Új verzió elérhető: ' + lastestVersion + '\n' timeout = undefined } @@ -1162,24 +1160,24 @@ function HandleUI (url, count, subjCount) { } // new version, nothing loaded if (newVersion && !loaded) { // -------------------------------------------------------------------------------------------------------------- - greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + GM_info.script.version + '. Új verzió!\n Írd át a @resouce tagnál az elírési utat! Kivéve ha üres a file, akkor töltsd fel :) Nincs kérdés betöltve! Segítséghez kattints. Changelog:\n' + lastChangeLog // showing changelog too + greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + info().script.version + '. Új verzió!\n Írd át a @resouce tagnál az elírési utat! Kivéve ha üres a file, akkor töltsd fel :) Nincs kérdés betöltve! Segítséghez kattints. Changelog:\n' + lastChangeLog // showing changelog too } // new version, everything loaded -> set lastVerson to current if (newVersion && loaded) { // -------------------------------------------------------------------------------------------------------------- - greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + GM_info.script.version + '. ' + count + ' kérdés és ' + subjCount + ' tárgy betöltve. Verzió frissítve ' + GM_info.script.version + '-re. Changelog:\n' + lastChangeLog - GM_setValue('lastVerson', GM_info.script.version) // setting lastVersion + greetMsg = 'Moodle/Elearning/KMOOC segéd v. ' + info().script.version + '. ' + count + ' kérdés és ' + subjCount + ' tárgy betöltve. Verzió frissítve ' + info().script.version + '-re. Changelog:\n' + lastChangeLog + setVal('lastVerson', info().script.version) // setting lastVersion } if (!SUtils.EmptyOrWhiteSpace(motd)) { - var prevmotd = GM_getValue('motd') + var prevmotd = getVal('motd') if (prevmotd !== motd) { greetMsg += '\nMOTD:\n' + motd timeout = null - GM_setValue('motdcount', motdShowCount) - GM_setValue('motd', motd) + setVal('motdcount', motdShowCount) + setVal('motd', motd) } else { - var motdcount = GM_getValue('motdcount') + var motdcount = getVal('motdcount') if (motdcount === undefined) { - GM_setValue('motdcount', motdShowCount) + setVal('motdcount', motdShowCount) motdcount = motdShowCount } @@ -1187,7 +1185,7 @@ function HandleUI (url, count, subjCount) { if (motdcount > 0) { greetMsg += '\nMOTD:\n' + motd timeout = null - GM_setValue('motdcount', motdcount) + setVal('motdcount', motdcount) } } } @@ -1224,7 +1222,7 @@ function PrepareAnswers (result, j) { var allMessages = [] // preparing all messages for (var k = 0; k < result.length; k++) { var msg = '' // the current message - if ((GM_getValue('showQuestions') === undefined) || GM_getValue('showQuestions')) { + if ((getVal('showQuestions') === undefined) || getVal('showQuestions')) { msg += result[k].q.Q + '\n' // adding the question if yes } msg += result[k].q.A.replace(/, /g, '\n') // adding answer @@ -1250,7 +1248,7 @@ function ShowAnswers (answers) { m: 'Nincs találat :( Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez! Előfordulhat, hogy a tárgyat nem válsztottad ki a menüben.', isSimple: true }, undefined, function () { - GM_openInTab(serverAdress + 'lred', { + openInTab(serverAdress + 'lred', { active: true }) }) @@ -1272,7 +1270,7 @@ function ShowSaveQuizDialog (addedQ, allQ, allOutput, output, sendSuccess, sentD if (addedQ > 0) { msg = 'Klikk ide a nyers adatokhoz. ' + addedQ + ' új kérdés!' - var useNetDB = GM_getValue('useNetDB') + var useNetDB = getVal('useNetDB') if (useNetDB !== undefined && useNetDB === 1) { if (!sendSuccess) { msg += ' Nem sikerült kérdéseket elküldeni szervernek. Ha gondolod utánanézhetsz.' } else { msg += 'Az új kérdések elküldve.' } } else { msg += 'Ne felejtsd el bemásolni a fő txt-be!' } @@ -1288,7 +1286,7 @@ function ShowSaveQuizDialog (addedQ, allQ, allOutput, output, sendSuccess, sentD var towrite = '

' + sentData.subj + '
TXT-ben nem szereplő kérdések: ' + addedQ + '/' + allQ + '


' + output.replace(/\n/g, '
') + '

Összes kérdés/válasz:

' + allOutput.replace( /\n/g, '
') - var useNetDB = GM_getValue('useNetDB') + var useNetDB = getVal('useNetDB') if (useNetDB !== undefined && useNetDB === 1) { try { towrite += '

Elküldött adatok:

' + JSON.stringify(sentData) @@ -1374,11 +1372,11 @@ function SaveQuiz (quiz, questionData) { sentData.subj = 'NOSUBJ' Log('unable to get subject name :c') } - var useNetDB = GM_getValue('useNetDB') + var useNetDB = getVal('useNetDB') if (useNetDB !== undefined && useNetDB === 1) { sentData.allData = quiz sentData.data = newQuestions - sentData.version = GM_info.script.version + sentData.version = info().script.version SendXHRMessage('datatoadd=' + JSON.stringify(sentData)) sendSuccess = true } @@ -1819,7 +1817,7 @@ function ShowMenu () { // passive mode stuff var questionsTickBox = document.createElement('input') questionsTickBox.type = 'checkbox' - questionsTickBox.checked = GM_getValue('skipLoad') + questionsTickBox.checked = getVal('skipLoad') questionsTickBox.style.position = '' questionsTickBox.style.left = 10 + 'px' questionsTickBox.style.margin = '5px 5px 5px 5px' // fancy margin @@ -1828,9 +1826,9 @@ function ShowMenu () { menuButtonDiv.appendChild(questionsTickBox) // adding to main div questionsTickBox.addEventListener('click', function () { - GM_setValue('skipLoad', questionsTickBox.checked) + setVal('skipLoad', questionsTickBox.checked) var msg = '' - if (GM_getValue('skipLoad')) { msg = 'Passzív mód bekapcsolva, mostantól kérdések nem lesznek betöltve/lekérve.' } else { msg = 'Passzív mód kikapcsolva, frissíts az érvénybe lépéshez!' } + if (getVal('skipLoad')) { msg = 'Passzív mód bekapcsolva, mostantól kérdések nem lesznek betöltve/lekérve.' } else { msg = 'Passzív mód kikapcsolva, frissíts az érvénybe lépéshez!' } ShowMessage({ m: msg, @@ -1943,7 +1941,7 @@ function ShowMenuList () { var noDataRow = tbl.insertRow() var noDataRowCell = noDataRow.insertCell() - if (GM_getValue('skipLoad')) { + if (getVal('skipLoad')) { textBox = CreateNodeWithText(noDataRowCell, 'Passszív mód bekapcsolva. Kapcsold ki a kérdések betöltéséhez!' ) @@ -1961,7 +1959,7 @@ function ShowMenuList () { var splashTickBox = document.createElement('input') splashTickBox.type = 'checkbox' - splashTickBox.checked = GM_getValue('showSplash') || false + splashTickBox.checked = getVal('showSplash') || false splashTickBox.style.position = '' // splashTickBox.style.background = "white"; splashTickBox.style.left = 10 + 'px' @@ -1970,7 +1968,7 @@ function ShowMenuList () { splashTickboxCell.appendChild(splashTickBox) // adding to main div splashTickBox.addEventListener('click', function () { - GM_setValue('showSplash', splashTickBox.checked) + setVal('showSplash', splashTickBox.checked) }) // adding clicktextNode CreateNodeWithText(splashTickboxCell, 'Üdvözlő üzenet mutatása minden oldalon', 'span') @@ -1981,7 +1979,7 @@ function ShowMenuList () { var questionsTickBox = document.createElement('input') questionsTickBox.type = 'checkbox' - questionsTickBox.checked = GM_getValue('showQuestions') + questionsTickBox.checked = getVal('showQuestions') questionsTickBox.style.position = '' // questionsTickBox.style.background = "white"; questionsTickBox.style.left = 10 + 'px' @@ -1990,7 +1988,7 @@ function ShowMenuList () { questionTickboxCell.appendChild(questionsTickBox) // adding to main div questionsTickBox.addEventListener('click', function () { - GM_setValue('showQuestions', questionsTickBox.checked) + setVal('showQuestions', questionsTickBox.checked) if (!questionsTickBox.checked) { ShowMessage({ m: 'Szinte mindég jó az talált válasz a kérdésre, de attól még könnyen előfordulhat, hogy rosz kérdésre írja ki a választ! Ez a opció nélkül ezt az ellenőrzési lehetőséget nem tudod kihasználni', @@ -2007,7 +2005,7 @@ function ShowMenuList () { var databasemodeListbox = document.createElement('select') databasemodeListbox.type = 'checkbox' - // databasemodeListbox.checked = GM_getValue("showSplash") || false; + // databasemodeListbox.checked = getVal("showSplash") || false; databasemodeListbox.style.position = '' // databasemodeListbox.style.background = "white"; databasemodeListbox.style.left = 10 + 'px' @@ -2022,7 +2020,7 @@ function ShowMenuList () { databasemodeListbox.addEventListener('change', function (e) { // sorry for using selectedindex :c - GM_setValue('useNetDB', databasemodeListbox.selectedIndex) + setVal('useNetDB', databasemodeListbox.selectedIndex) }) var uselocal = document.createElement('option') @@ -2035,7 +2033,7 @@ function ShowMenuList () { usenetsafe.value = 0 databasemodeListbox.add(usenetsafe, 1) - var selected = GM_getValue('useNetDB') + var selected = getVal('useNetDB') if (selected !== undefined) { databasemodeListbox.selectedIndex = selected } var databasemodeListboxElement = document.createElement('span') // new paragraph @@ -2118,7 +2116,7 @@ function CreateNodeWithText (to, text, type) { function SendXHRMessage (message) { var url = serverAdress + 'isAdding' - GM_xmlhttpRequest({ + xmlhttpRequest({ method: 'POST', url: url, data: message, @@ -2141,7 +2139,7 @@ var assert = (val) => { // shows some neat help function ShowHelp () { - GM_openInTab(serverAdress + 'manual', { + openInTab(serverAdress + 'manual', { active: true }) }