diff --git a/main.js b/main.js index 6f6d461..13861ef 100644 --- a/main.js +++ b/main.js @@ -20,28 +20,26 @@ ------------------------------------------------------------------------- */ -// TODO: -// default is not active on new subjects -> TEST - var data; // all data, which is in the resource txt var addEventListener; // add event listener function const lastChangeLog = - '- Eredmények oldalon kérdésekre válasz szerzés mód váltás\n - Görgethető tárgyak, mert túl sok van már :p\nHa rosz választ szed ki a script pls küldj feedbacket! IRC is van.'; + 'TODO'; const serverAdress = "https://qmining.tk/"; // forcing pages for testing. unless you test, do not set these to true! // only one of these should be true for testing -const forceTestPage = false; +const forceTestPage = true; const forceResultPage = false; const forceDefaultPage = false; const logElementGetting = false; -const log = false; +const log = true; const motdShowCount = 3; var motd = ""; -var lastestVersion = ""; // TODO: if undefined no new verion +var lastestVersion = ""; -const minMatchAmmount = 49; +const minMatchAmmount = 60; +const lengthDiffMultiplier = 10; //: Class descriptions {{{ class Question { @@ -100,8 +98,6 @@ class Question { } } static CompareString(s1, s2) { - //if (s1 == undefined || s2 == undefined) - // return 0; s1 = SimplifyStringForComparison(s1).split(" "); s2 = SimplifyStringForComparison(s2).split(" "); var match = 0; @@ -110,7 +106,7 @@ class Question { match++; var percent = Math.round(((match / s1.length) * 100).toFixed(2)); // matched words percent var lengthDifference = Math.abs(s2.length - s1.length); - percent -= lengthDifference * 3; + percent -= lengthDifference * lengthDiffMultiplier; if (percent < 0) percent = 0; return percent; @@ -290,7 +286,6 @@ function GetFormulationClearfix() { } function GetAnswerOptions() { - // TODO if (logElementGetting) Log("getting all answer options"); return GetFormulationClearfix()[0].childNodes[3].innerText; @@ -531,6 +526,11 @@ function GetQuestionFromTest() { Log(e); Log("Some error with images"); } + + questions = questions.map((item, ind) => { + return ReplaceCharsWithSpace(item, "\n"); + }); + return { imgnodes: imgNodes, allQ: allQuestions, @@ -910,6 +910,11 @@ function ParseRawData(data) { function Load(cwith) { var useNetDB = GM_getValue("useNetDB"); + let skipLoad = GM_getValue("skipLoad"); + + if (skipLoad) + return -1; + if (useNetDB != undefined && useNetDB == 1) return ReadNetDB(cwith, useNetDB); else @@ -944,7 +949,16 @@ function NLoad(resource, cwith) { d = JSON.parse(resource); } catch (e) { Log("Old data, trying with old methods...."); - d = ParseRawData(resource).result; + try { + d = ParseRawData(resource).result; + } catch (e2) { + Log("Couldt parse data!"); + ShowMessage({ + m: "Nem sikerült betölteni az adatokat! Ellenőriz a megadott fájlt, vagy az internetelérésed!", + isSimple: true + }); + return; + } } var r = new QuestionDB(); var rt = []; @@ -1003,7 +1017,7 @@ 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.) 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!"; + "Hiba a @resource tagnál, vagy a fileval van gond! (Lehet át lett helyezve, vagy üres.) 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 // no new version, everything loaded, and show splash is enabled. otherwise something happened, so showing it @@ -1156,7 +1170,7 @@ function ShowSaveQuizDialog(addedQ, allQ, allOutput, output, sendSuccess, sentDa if (addedQ > 0) // if there are more than 0 new question { msg = "Klikk ide a nyers adatokhoz. " + addedQ + - " új kérdés! Ne felejtsd el bemásolni a fő txt-be!"; + " új kérdés!"; var useNetDB = GM_getValue("useNetDB"); if (useNetDB != undefined && useNetDB == 1) { @@ -1164,7 +1178,9 @@ function ShowSaveQuizDialog(addedQ, allQ, allOutput, output, sendSuccess, sentDa 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 { msg = "A kérdőívben nincsen új kérdés. Ha mégis le akarod menteni klikk ide."; @@ -1742,9 +1758,8 @@ function ShowMenu() { } }); // adding click - //addEventListener(window, 'scroll', function () { - // menuButtonDiv.style.top = (pageYOffset + window.innerHeight - buttonHeight * 2) + 'px'; - //}) + let skipLoad = GM_getValue("skipLoad"); + // TODO: add switch, and test loading stuff addEventListener(window, 'resize', function() { menuButtonDiv.style.left = window.innerWidth - buttonWidth * 2 + 'px'; @@ -1997,7 +2012,7 @@ function ShowMenuList() { Exception(e, "script error at showing menu list:"); } - document.addEventListener("keydown", EscClose); + document.addEventListener("keydown", EscClose); } function EscClose(e) { @@ -2054,6 +2069,15 @@ function CreateNodeWithText(to, text, type) { return paragraphElement; } +function ReplaceCharsWithSpace(val, char) { + toremove = NormalizeSpaces(val); + + var regex = new RegExp(char, "g"); + toremove.replace(regex, " "); + + return RemoveUnnecesarySpaces(toremove); +} + // removes whitespace from begining and and, and replaces multiple spaces with one space function RemoveUnnecesarySpaces(toremove) { toremove = NormalizeSpaces(toremove);