mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Bug fixes, an performance improvements
This commit is contained in:
parent
3fcd18670e
commit
51ad5d7d4f
1 changed files with 65 additions and 37 deletions
102
main.js
102
main.js
|
@ -21,13 +21,13 @@
|
||||||
------------------------------------------------------------------------- */
|
------------------------------------------------------------------------- */
|
||||||
|
|
||||||
// TODO:
|
// TODO:
|
||||||
// default is not active on new subjects
|
// default is not active on new subjects -> TEST
|
||||||
// send version, and check if new is avaible
|
// dropdown questions result gettin
|
||||||
|
|
||||||
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
|
||||||
var lastChangeLog =
|
var lastChangeLog =
|
||||||
' - Összes tárgy letiltása alapból, mert sok tárgy van, és belassulhat :c\n- Az azért jó, hogy sok tárgy van c:';
|
'- Performance javítások\n - Összes tárgy letiltása alapból, mert sok tárgy van, és belassulhat :c\n- Az azért jó, hogy sok tárgy van c:\nEllenőrizd, hogy mely tárgyak aktívak a menüben!';
|
||||||
var serverAdress = "https://questionmining.tk/";
|
var serverAdress = "https://questionmining.tk/";
|
||||||
|
|
||||||
// forcing pages for testing. unless you test, do not set these to true!
|
// forcing pages for testing. unless you test, do not set these to true!
|
||||||
|
@ -39,8 +39,9 @@ const logElementGetting = false;
|
||||||
|
|
||||||
var motdShowCount = 3;
|
var motdShowCount = 3;
|
||||||
var motd = "";
|
var motd = "";
|
||||||
|
var lastestVersion = "";
|
||||||
|
|
||||||
var minMatchAmmount = 50;
|
var minMatchAmmount = 49;
|
||||||
|
|
||||||
//: Class descriptions {{{
|
//: Class descriptions {{{
|
||||||
class Question {
|
class Question {
|
||||||
|
@ -229,21 +230,25 @@ class QuestionDB {
|
||||||
//: Main function {{{
|
//: Main function {{{
|
||||||
function Main() {
|
function Main() {
|
||||||
'use strict';
|
'use strict';
|
||||||
Init(function(count) {
|
Init(function(count, subjCount) {
|
||||||
var url = location.href;
|
var url = location.href;
|
||||||
try {
|
try {
|
||||||
if ((url.includes("/quiz/") && url.includes("attempt.php")) || forceTestPage) { // if the current page is a test
|
if ((url.includes("/quiz/") && url.includes("attempt.php")) || forceTestPage) { // if the current page is a test
|
||||||
HandleQuiz(url, count);
|
HandleQuiz();
|
||||||
} else if ((url.includes("/quiz/") && url.includes("review.php")) || forceResultPage) { // if the current window is a test-s result
|
} else if ((url.includes("/quiz/") && url.includes("review.php")) || forceResultPage) { // if the current window is a test-s result
|
||||||
HandleResults(url);
|
HandleResults(url);
|
||||||
} else if ((!url.includes("/quiz/") && !url.includes("review.php") && !url.includes(".pdf")) ||
|
} 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.
|
(forceDefaultPage)) { // if the current window is any other window than a quiz or pdf.
|
||||||
HandleUI(url, count);
|
HandleUI(url, count, subjCount);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
ShowMessage({
|
ShowMessage({
|
||||||
m: "Fatál error. Check console (f12). Ha élesbe megy, akkor ctrl-f a kérdések.txt-ben",
|
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() {
|
||||||
|
GM_openInTab(serverAdress + 'legacy', {
|
||||||
|
active: true
|
||||||
|
});
|
||||||
});
|
});
|
||||||
console.log("------------------------------------------");
|
console.log("------------------------------------------");
|
||||||
console.log("script error at main:");
|
console.log("script error at main:");
|
||||||
|
@ -877,10 +882,19 @@ function LoadMOTD(resource) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function LoadVersion(resource) {
|
||||||
|
try {
|
||||||
|
lastestVersion = resource.version;
|
||||||
|
} catch (e) {
|
||||||
|
console.log("Error loading version :c");
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// loading stuff
|
// loading stuff
|
||||||
function NLoad(resource, cwith) {
|
function NLoad(resource, cwith) {
|
||||||
var count = -1;
|
var count = -1;
|
||||||
|
var subjCount = 0;
|
||||||
try {
|
try {
|
||||||
var d = {};
|
var d = {};
|
||||||
try {
|
try {
|
||||||
|
@ -893,19 +907,23 @@ function NLoad(resource, cwith) {
|
||||||
var rt = [];
|
var rt = [];
|
||||||
var allCount = -1;
|
var allCount = -1;
|
||||||
LoadMOTD(d);
|
LoadMOTD(d);
|
||||||
|
LoadVersion(d);
|
||||||
|
|
||||||
for (var i = 0; i < d.Subjects.length; i++) {
|
for (var i = 0; i < d.Subjects.length; i++) {
|
||||||
let s = new Subject(d.Subjects[i].Name);
|
let s = new Subject(d.Subjects[i].Name);
|
||||||
var j = 0;
|
if (GM_getValue("Is" + i + "Active")) {
|
||||||
for (j = 0; j < d.Subjects[i].Questions.length; j++) {
|
var j = 0;
|
||||||
var currQ = d.Subjects[i].Questions[j];
|
for (j = 0; j < d.Subjects[i].Questions.length; j++) {
|
||||||
s.AddQuestion(new Question(currQ.Q, currQ.A, currQ.I));
|
var currQ = d.Subjects[i].Questions[j];
|
||||||
|
s.AddQuestion(new Question(currQ.Q, currQ.A, currQ.I));
|
||||||
|
}
|
||||||
|
rt.push({
|
||||||
|
name: d.Subjects[i].Name,
|
||||||
|
count: j
|
||||||
|
});
|
||||||
|
allCount += j;
|
||||||
|
subjCount++;
|
||||||
}
|
}
|
||||||
rt.push({
|
|
||||||
name: d.Subjects[i].Name,
|
|
||||||
count: j
|
|
||||||
});
|
|
||||||
allCount += j;
|
|
||||||
r.AddSubject(s);
|
r.AddSubject(s);
|
||||||
}
|
}
|
||||||
data = r;
|
data = r;
|
||||||
|
@ -926,14 +944,14 @@ function NLoad(resource, cwith) {
|
||||||
if (i >= data.length)
|
if (i >= data.length)
|
||||||
document.getElementById("HelperMenuButton").style.background = "yellow";
|
document.getElementById("HelperMenuButton").style.background = "yellow";
|
||||||
|
|
||||||
cwith(count);
|
cwith(count, subjCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
//: }}}
|
//: }}}
|
||||||
|
|
||||||
//: Answering stuffs {{{
|
//: Answering stuffs {{{
|
||||||
|
|
||||||
function HandleQuiz(url, count) {
|
function HandleQuiz() {
|
||||||
var q = GetQuestionFromTest();
|
var q = GetQuestionFromTest();
|
||||||
var questions = q.q;
|
var questions = q.q;
|
||||||
var allQuestions = q.allQ;
|
var allQuestions = q.allQ;
|
||||||
|
@ -944,7 +962,9 @@ function HandleQuiz(url, count) {
|
||||||
{
|
{
|
||||||
var question = RemoveUnnecesarySpaces(questions[j]); // simplifying question
|
var question = RemoveUnnecesarySpaces(questions[j]); // simplifying question
|
||||||
var result = data.Search(question, SimplifyImages(imgNodes));
|
var result = data.Search(question, SimplifyImages(imgNodes));
|
||||||
answers.push(PrepareAnswers(result, j));
|
var r = PrepareAnswers(result, j);
|
||||||
|
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);
|
||||||
|
@ -980,13 +1000,17 @@ function ShowAnswers(answers) {
|
||||||
ShowMessage(answers);
|
ShowMessage(answers);
|
||||||
} else {
|
} else {
|
||||||
ShowMessage({
|
ShowMessage({
|
||||||
m: "Nincs találat :( TXT-ben szerepelhet a képnév/kérdés részlet, ha rákeresel! Illetve előfordulhat, hogy a tárgyat nem válsztottad ki a menüben.",
|
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
|
isSimple: true
|
||||||
|
}, undefined, function() {
|
||||||
|
GM_openInTab(serverAdress + 'legacy', {
|
||||||
|
active: true
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function HandleUI(url, count) {
|
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
|
||||||
|
|
||||||
|
@ -1007,8 +1031,13 @@ function HandleUI(url, count) {
|
||||||
if (!newVersion && loaded && showSplash) // ------------------------------------------------------------------------------------------------
|
if (!newVersion && loaded && showSplash) // ------------------------------------------------------------------------------------------------
|
||||||
{
|
{
|
||||||
timeout = 5;
|
timeout = 5;
|
||||||
greetMsg = "Moodle/Elearning/KMOOC segéd v. " + GM_info.script.version + ". " + count +
|
greetMsg = "Moodle/Elearning/KMOOC segéd v. " + GM_info.script.version + ". ";
|
||||||
" kérdés és " + data.length + " tárgy betöltve. (click for help).";
|
|
||||||
|
if (GM_info.script.version != lastestVersion) {
|
||||||
|
greetMsg += "Új verzió elérhető: " + lastestVersion + " ";
|
||||||
|
timeout = undefined;
|
||||||
|
}
|
||||||
|
greetMsg += count + " kérdés és " + subjCount + " tárgy betöltve. (click for help).";
|
||||||
if (data.length > 0) {
|
if (data.length > 0) {
|
||||||
var toAdd = [];
|
var toAdd = [];
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (var i = 0; i < data.length; i++) {
|
||||||
|
@ -1037,7 +1066,7 @@ function HandleUI(url, count) {
|
||||||
if (newVersion && loaded) // --------------------------------------------------------------------------------------------------------------
|
if (newVersion && loaded) // --------------------------------------------------------------------------------------------------------------
|
||||||
{
|
{
|
||||||
greetMsg = "Moodle/Elearning/KMOOC segéd v. " + GM_info.script.version + ". " + count +
|
greetMsg = "Moodle/Elearning/KMOOC segéd v. " + GM_info.script.version + ". " + count +
|
||||||
" kérdés és " + data.length + " tárgy betöltve. Verzió frissítve " + GM_info.script.version +
|
" kérdés és " + subjCount + " tárgy betöltve. Verzió frissítve " + GM_info.script.version +
|
||||||
"-re. Changelog:\n" + lastChangeLog;
|
"-re. Changelog:\n" + lastChangeLog;
|
||||||
GM_setValue("lastVerson", GM_info.script.version); // setting lastVersion
|
GM_setValue("lastVerson", GM_info.script.version); // setting lastVersion
|
||||||
}
|
}
|
||||||
|
@ -1076,12 +1105,7 @@ function HandleUI(url, count) {
|
||||||
|
|
||||||
function HandleResults(url) {
|
function HandleResults(url) {
|
||||||
var allResults = new QuestionDB();
|
var allResults = new QuestionDB();
|
||||||
if (data)
|
SaveQuiz(GetQuiz(), data); // saves the quiz questions and answers
|
||||||
for (var i = 0; i < data.length; i++) // going trough all subjects
|
|
||||||
if (data.GetIfActive(i)) // if the subject is active
|
|
||||||
for (var j = 0; j < data.Subjects[i].Questions.length; j++)
|
|
||||||
allResults.AddQuestion("tmp", data.Subjects[i].Questions[j]);
|
|
||||||
SaveQuiz(GetQuiz(), allResults); // saves the quiz questions and answers
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function ShowSaveQuizDialog(addedQ, allQ, allOutput, output, sendSuccess, sentData) {
|
function ShowSaveQuizDialog(addedQ, allQ, allOutput, output, sendSuccess, sentData) {
|
||||||
|
@ -1540,7 +1564,6 @@ function ShowMessage(msgItem, timeout, funct) {
|
||||||
|
|
||||||
function SetQuestionText() {
|
function SetQuestionText() {
|
||||||
var relevantQuestion = GetRelevantQuestion();
|
var relevantQuestion = GetRelevantQuestion();
|
||||||
console.log("setting shit");
|
|
||||||
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) + ".";
|
||||||
|
@ -1708,7 +1731,7 @@ function ShowMenuList() {
|
||||||
menuDiv.style.color = "#ffffff"; // text color
|
menuDiv.style.color = "#ffffff"; // text color
|
||||||
menuDiv.style.borderColor = "#035a8f"; // border color
|
menuDiv.style.borderColor = "#035a8f"; // border color
|
||||||
menuDiv.style.border = "solid";
|
menuDiv.style.border = "solid";
|
||||||
menuDiv.style.opacity = "0.9"; // setting starting opacity
|
menuDiv.style.opacity = "1"; // setting starting opacity
|
||||||
|
|
||||||
var fiveMargin = "5px 5px 5px 5px";
|
var fiveMargin = "5px 5px 5px 5px";
|
||||||
var tbl = document.createElement('table');
|
var tbl = document.createElement('table');
|
||||||
|
@ -1720,7 +1743,7 @@ function ShowMenuList() {
|
||||||
var tr = tbl.insertRow();
|
var tr = tbl.insertRow();
|
||||||
var header1 = tr.insertCell();
|
var header1 = tr.insertCell();
|
||||||
|
|
||||||
var headerSubjInfoParagraph = CreateNodeWithText(header1, "Tárgynév (darab kérdés)", "center");
|
var headerSubjInfoParagraph = CreateNodeWithText(header1, "Tárgynév [darab kérdés]", "center");
|
||||||
headerSubjInfoParagraph.style.margin = fiveMargin; // fancy margin
|
headerSubjInfoParagraph.style.margin = fiveMargin; // fancy margin
|
||||||
|
|
||||||
var header2 = tr.insertCell();
|
var header2 = tr.insertCell();
|
||||||
|
@ -1733,15 +1756,20 @@ function ShowMenuList() {
|
||||||
subjRow.style.border = "1px solid #131319";
|
subjRow.style.border = "1px solid #131319";
|
||||||
|
|
||||||
var td = subjRow.insertCell();
|
var td = subjRow.insertCell();
|
||||||
var textBox = CreateNodeWithText(td, data.Subjects[i].Name + " (" + data.Subjects[i].length +
|
var text = data.Subjects[i].Name;
|
||||||
")");
|
if (data.Subjects[i].length != 0)
|
||||||
|
text += " [ " + data.Subjects[i].length + "db ]";
|
||||||
|
|
||||||
|
var textBox = CreateNodeWithText(td, text);
|
||||||
|
|
||||||
textBox.style.margin = fiveMargin; // fancy margin
|
textBox.style.margin = fiveMargin; // fancy margin
|
||||||
|
|
||||||
td = subjRow.insertCell();
|
td = subjRow.insertCell();
|
||||||
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 = "5px 5px 5px 5px"; // fancy margin
|
checkbox.style.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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue