From ec176c9d1517aeac2065158b13389721291fbd1f Mon Sep 17 00:00:00 2001 From: YourFriendlyNeighborhoodDealer Date: Wed, 6 Mar 2019 09:45:25 +0100 Subject: [PATCH 1/3] Merging with master branch --- main.js | 2 +- stable.js | 37 ++++++++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/main.js b/main.js index 3ee51c1..cea9bbc 100644 --- a/main.js +++ b/main.js @@ -23,7 +23,7 @@ var data; // all data, which is in the resource txt var addEventListener; // add event listener function const lastChangeLog = - '- Passzív mód: ha bepipálod a menü gomb alatt, akkor nem tölti be minden alkalommal a kérdéseket (csak csendben vár).\n - Pár lényeges bugfix\n - Ha találkoztok bugokkal, akkor pls report! thanx'; + '- Apró, de lényeges fixek\n - Ha találkoztok bugokkal, akkor pls report! thanx'; const serverAdress = "https://qmining.tk/"; // forcing pages for testing. unless you test, do not set these to true! diff --git a/stable.js b/stable.js index 4e60174..40d2ca0 100644 --- a/stable.js +++ b/stable.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 1.6.2.5 +// @version 1.6.2.6 // @description Online Moodle/Elearning/KMOOC test help // @author YourFriendlyNeighborhoodDealer // @match https://elearning.uni-obuda.hu/main/* @@ -44,7 +44,7 @@ var data; // all data, which is in the resource txt var addEventListener; // add event listener function const lastChangeLog = - '- Passzív mód: ha bepipálod a menü gomb alatt, akkor nem tölti be minden alkalommal a kérdéseket (csak csendben vár).\n - Pár lényeges bugfix\n - Ha találkoztok bugokkal, akkor pls report! thanx'; + '- Apró, de lényeges fixek\n - Ha találkoztok bugokkal, akkor pls report! thanx'; const serverAdress = "https://qmining.tk/"; // forcing pages for testing. unless you test, do not set these to true! @@ -60,6 +60,7 @@ var lastestVersion = ""; const minMatchAmmount = 55; + const minResultMatchPercent = 99; const lengthDiffMultiplier = 10; //: Class descriptions {{{ @@ -251,6 +252,17 @@ 'use strict'; Init(function(count, subjCount) { var url = location.href; + + let skipLoad = GM_getValue("skipLoad"); + if (count == -2 && subjCount == -2 && skipLoad) { + if (url.includes("/quiz/") && url.includes("attempt.php")) + ShowMessage({ + m: "Passzív mód bekapcsolva, válaszok megjelenítéséhez menü gomb alatt kapcsold ki, és frissíts!", + isSimple: true + }); + return; + } + try { if ((url.includes("/quiz/") && url.includes("attempt.php")) || forceTestPage) { // if the current page is a test HandleQuiz(); @@ -277,6 +289,9 @@ "Itteni hibák 100% a moodle hiba. Kivéve, ha oda van írva hogy script error ;) Ha ilyesmi szerepel itt, akkor olvasd el a segítség szekciót! Nagy esélyel a kérdéseket nem lehetett beolvasni." ); }); + + if (forceTestPage || forceResultPage || forceDefaultPage) + alert("TEST MODE"); } //: }}} @@ -946,8 +961,10 @@ var useNetDB = GM_getValue("useNetDB"); let skipLoad = GM_getValue("skipLoad"); - if (skipLoad) + if (skipLoad) { + cwith(-2, -2); return -1; + } if (useNetDB != undefined && useNetDB == 1) return ReadNetDB(cwith, useNetDB); @@ -1051,7 +1068,7 @@ if (!newVersion && !loaded) // -------------------------------------------------------------------------------------------------------------- { greetMsg = - "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!"; + "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 // no new version, everything loaded, and show splash is enabled. otherwise something happened, so showing it @@ -1240,7 +1257,14 @@ function SearchSameQuestion(questionData, quiz, i) { var r = questionData.Search(quiz[i].Q); - return r.length == 0 ? -1 : r.length; + + let count = 0; + r.forEach((item) => { + if (item.match > minResultMatchPercent) + count++; + }); + + return count == 0 ? -1 : count; } // this should get the image url from a result page @@ -1768,7 +1792,6 @@ // mainDiv.style.left = (window.innerWidth - width) / 2 + 'px'; var menuButtonDiv = document.createElement("div"); - menuButtonDiv.setAttribute("id", "HelperMenuButton"); menuButtonDiv.style.width = buttonWidth + 'px'; menuButtonDiv.style.height = buttonHeight + 'px'; menuButtonDiv.style.top = (window.innerHeight - buttonHeight * 1.5) + 'px'; @@ -1793,6 +1816,7 @@ menuButton.style.height = buttonHeight - 20 + 'px'; menuButton.style.background = "#222d32"; // background color menuButton.style.color = "#ffffff"; // background color + menuButton.setAttribute("id", "HelperMenuButton"); @@ -2237,5 +2261,4 @@ // O deepest wound of all that he should die // On that darkest day. - })(); From 477d10123e78379960f838ca28ffaf5423672bc7 Mon Sep 17 00:00:00 2001 From: YourFriendlyNeighborhoodDealer Date: Sat, 9 Mar 2019 14:43:16 +0100 Subject: [PATCH 2/3] Small design change, small bug fix, smol msg on passive mode --- frame.js | 2 +- main.js | 2 +- stable.js | 80 ++++++++++++++++++++++++++++++------------------------- 3 files changed, 46 insertions(+), 38 deletions(-) diff --git a/frame.js b/frame.js index 772c9bd..f48f6b8 100644 --- a/frame.js +++ b/frame.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 1.6.2.6 +// @version 1.6.2.7 // @description Online Moodle/Elearning/KMOOC test help // @author YourFriendlyNeighborhoodDealer // @match https://elearning.uni-obuda.hu/main/* diff --git a/main.js b/main.js index afcc1ed..b804e8d 100644 --- a/main.js +++ b/main.js @@ -32,7 +32,7 @@ const forceTestPage = false; const forceResultPage = false; const forceDefaultPage = false; const logElementGetting = false; -const log = true; +const log = false; const motdShowCount = 3; var motd = ""; diff --git a/stable.js b/stable.js index 40d2ca0..7b776cd 100644 --- a/stable.js +++ b/stable.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 1.6.2.6 +// @version 1.6.2.7 // @description Online Moodle/Elearning/KMOOC test help // @author YourFriendlyNeighborhoodDealer // @match https://elearning.uni-obuda.hu/main/* @@ -250,6 +250,8 @@ //: Main function {{{ function Main() { 'use strict'; + console.time('main'); + Init(function(count, subjCount) { var url = location.href; @@ -260,36 +262,38 @@ m: "Passzív mód bekapcsolva, válaszok megjelenítéséhez menü gomb alatt kapcsold ki, és frissíts!", isSimple: true }); - return; - } - - try { - if ((url.includes("/quiz/") && url.includes("attempt.php")) || forceTestPage) { // if the current page is a test - HandleQuiz(); - } else if ((url.includes("/quiz/") && url.includes("review.php")) || forceResultPage) { // if the current window is a test-s result - HandleResults(url); - } else if ((!url.includes("/quiz/") && !url.includes("review.php") && !url.includes(".pdf")) || - (forceDefaultPage)) { // if the current window is any other window than a quiz or pdf. - HandleUI(url, count, subjCount); - } - } catch (e) { - ShowMessage({ - 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 + 'legacy', { - active: true + } else { + try { + if ((url.includes("/quiz/") && url.includes("attempt.php")) || forceTestPage) { // if the current page is a test + HandleQuiz(); + } else if ((url.includes("/quiz/") && url.includes("review.php")) || forceResultPage) { // if the current window is a test-s result + HandleResults(url); + } else if ((!url.includes("/quiz/") && !url.includes("review.php") && !url.includes(".pdf")) || + (forceDefaultPage)) { // if the current window is any other window than a quiz or pdf. + HandleUI(url, count, subjCount); + } + } catch (e) { + ShowMessage({ + 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 + 'legacy', { + active: true + }); }); - }); - Exception(e, "script error at main:"); + Exception(e, "script error at main:"); + } + if (url.includes("eduplayer")) // if the current site is a video site + AddVideoHotkeys(url); // adding video hotkeys + Log( + "Itteni hibák 100% a moodle hiba. Kivéve, ha oda van írva hogy script error ;) Ha ilyesmi szerepel itt, akkor olvasd el a segítség szekciót! Nagy esélyel a kérdéseket nem lehetett beolvasni." + ); } - if (url.includes("eduplayer")) // if the current site is a video site - AddVideoHotkeys(url); // adding video hotkeys - Log( - "Itteni hibák 100% a moodle hiba. Kivéve, ha oda van írva hogy script error ;) Ha ilyesmi szerepel itt, akkor olvasd el a segítség szekciót! Nagy esélyel a kérdéseket nem lehetett beolvasni." - ); }); + console.log("Moodle Test Script run time:"); + console.timeEnd('main'); + if (forceTestPage || forceResultPage || forceDefaultPage) alert("TEST MODE"); } @@ -1611,7 +1615,7 @@ mainDiv.style.background = "#222d32"; // background color mainDiv.style.color = "#ffffff"; // text color mainDiv.style.borderColor = "#035a8f"; // border color - mainDiv.style.border = "solid"; + mainDiv.style.border = "none"; mainDiv.style.top = (startFromTop) + 'px'; mainDiv.style.left = (window.innerWidth - width) / 2 + 'px'; mainDiv.style.opacity = "0.9"; // setting starting opacity @@ -1841,12 +1845,16 @@ questionsTickBox.addEventListener("click", function() { GM_setValue("skipLoad", questionsTickBox.checked); - if (GM_getValue("skipLoad")) { - ShowMessage({ - m: "Passzív mód bekapcsolva, mostantól kérdések nem lesznek betöltve/lekérve.", - isSimple: true - }, 10); - } + 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!"; + + ShowMessage({ + m: msg, + isSimple: true + }, 6); }); var loadDataCheckBoxText = CreateNodeWithText(questionsTickBox, @@ -1884,7 +1892,7 @@ menuDiv.style.background = "#222d32"; // background color menuDiv.style.color = "#ffffff"; // text color menuDiv.style.borderColor = "#035a8f"; // border color - menuDiv.style.border = "solid"; + menuDiv.style.border = "none"; menuDiv.style.opacity = "1"; // setting starting opacity var fiveMargin = "5px 5px 5px 5px"; @@ -2145,7 +2153,7 @@ // removes some crap from "q" function SimplifyQuery(q) { - var result = q.replace(/\n/g, "").replace(/\s/g, ' '); // WHY TF ARE THERE TWO KINDA SPACES??? (charcode 160 n 32) + var result = q.replace(/\n/g, " ").replace(/\s/g, ' '); // WHY TF ARE THERE TWO KINDA SPACES??? (charcode 160 n 32) return RemoveUnnecesarySpaces(result); } From 812e139a7c6fc0dff8e0b77029a39c97fdb3c788 Mon Sep 17 00:00:00 2001 From: YourFriendlyNeighborhoodDealer Date: Wed, 13 Mar 2019 10:19:56 +0100 Subject: [PATCH 3/3] Plaintext image data reading fix --- main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.js b/main.js index b804e8d..66ec83b 100644 --- a/main.js +++ b/main.js @@ -924,7 +924,7 @@ function ParseRawData(data) { try { currQuestion.I = JSON.parse(currData); } catch (e) { - currQuestion.I = [currData]; + currQuestion.I = currData.split(','); } } ExpectedIdentifier = ['?', '+'];