mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
More question formatting before parsing, some constant modification, and better error messages
This commit is contained in:
parent
31951a5cb9
commit
8aeb5ecf63
1 changed files with 44 additions and 20 deletions
62
main.js
62
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 data; // all data, which is in the resource txt
|
||||||
var addEventListener; // add event listener function
|
var addEventListener; // add event listener function
|
||||||
const lastChangeLog =
|
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/";
|
const serverAdress = "https://qmining.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!
|
||||||
// only one of these should be true for testing
|
// only one of these should be true for testing
|
||||||
const forceTestPage = false;
|
const forceTestPage = true;
|
||||||
const forceResultPage = false;
|
const forceResultPage = false;
|
||||||
const forceDefaultPage = false;
|
const forceDefaultPage = false;
|
||||||
const logElementGetting = false;
|
const logElementGetting = false;
|
||||||
const log = false;
|
const log = true;
|
||||||
|
|
||||||
const motdShowCount = 3;
|
const motdShowCount = 3;
|
||||||
var motd = "";
|
var motd = "";
|
||||||
var lastestVersion = ""; // TODO: if undefined no new verion
|
var lastestVersion = "";
|
||||||
|
|
||||||
const minMatchAmmount = 49;
|
const minMatchAmmount = 60;
|
||||||
|
const lengthDiffMultiplier = 10;
|
||||||
|
|
||||||
//: Class descriptions {{{
|
//: Class descriptions {{{
|
||||||
class Question {
|
class Question {
|
||||||
|
@ -100,8 +98,6 @@ class Question {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static CompareString(s1, s2) {
|
static CompareString(s1, s2) {
|
||||||
//if (s1 == undefined || s2 == undefined)
|
|
||||||
// return 0;
|
|
||||||
s1 = SimplifyStringForComparison(s1).split(" ");
|
s1 = SimplifyStringForComparison(s1).split(" ");
|
||||||
s2 = SimplifyStringForComparison(s2).split(" ");
|
s2 = SimplifyStringForComparison(s2).split(" ");
|
||||||
var match = 0;
|
var match = 0;
|
||||||
|
@ -110,7 +106,7 @@ class Question {
|
||||||
match++;
|
match++;
|
||||||
var percent = Math.round(((match / s1.length) * 100).toFixed(2)); // matched words percent
|
var percent = Math.round(((match / s1.length) * 100).toFixed(2)); // matched words percent
|
||||||
var lengthDifference = Math.abs(s2.length - s1.length);
|
var lengthDifference = Math.abs(s2.length - s1.length);
|
||||||
percent -= lengthDifference * 3;
|
percent -= lengthDifference * lengthDiffMultiplier;
|
||||||
if (percent < 0)
|
if (percent < 0)
|
||||||
percent = 0;
|
percent = 0;
|
||||||
return percent;
|
return percent;
|
||||||
|
@ -290,7 +286,6 @@ function GetFormulationClearfix() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetAnswerOptions() {
|
function GetAnswerOptions() {
|
||||||
// TODO
|
|
||||||
if (logElementGetting)
|
if (logElementGetting)
|
||||||
Log("getting all answer options");
|
Log("getting all answer options");
|
||||||
return GetFormulationClearfix()[0].childNodes[3].innerText;
|
return GetFormulationClearfix()[0].childNodes[3].innerText;
|
||||||
|
@ -531,6 +526,11 @@ function GetQuestionFromTest() {
|
||||||
Log(e);
|
Log(e);
|
||||||
Log("Some error with images");
|
Log("Some error with images");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
questions = questions.map((item, ind) => {
|
||||||
|
return ReplaceCharsWithSpace(item, "\n");
|
||||||
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
imgnodes: imgNodes,
|
imgnodes: imgNodes,
|
||||||
allQ: allQuestions,
|
allQ: allQuestions,
|
||||||
|
@ -910,6 +910,11 @@ function ParseRawData(data) {
|
||||||
|
|
||||||
function Load(cwith) {
|
function Load(cwith) {
|
||||||
var useNetDB = GM_getValue("useNetDB");
|
var useNetDB = GM_getValue("useNetDB");
|
||||||
|
let skipLoad = GM_getValue("skipLoad");
|
||||||
|
|
||||||
|
if (skipLoad)
|
||||||
|
return -1;
|
||||||
|
|
||||||
if (useNetDB != undefined && useNetDB == 1)
|
if (useNetDB != undefined && useNetDB == 1)
|
||||||
return ReadNetDB(cwith, useNetDB);
|
return ReadNetDB(cwith, useNetDB);
|
||||||
else
|
else
|
||||||
|
@ -944,7 +949,16 @@ function NLoad(resource, cwith) {
|
||||||
d = JSON.parse(resource);
|
d = JSON.parse(resource);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Log("Old data, trying with old methods....");
|
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 r = new QuestionDB();
|
||||||
var rt = [];
|
var rt = [];
|
||||||
|
@ -1003,7 +1017,7 @@ function HandleUI(url, count, subjCount) {
|
||||||
if (!newVersion && !loaded) // --------------------------------------------------------------------------------------------------------------
|
if (!newVersion && !loaded) // --------------------------------------------------------------------------------------------------------------
|
||||||
{
|
{
|
||||||
greetMsg =
|
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
|
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
|
||||||
|
@ -1156,7 +1170,7 @@ function ShowSaveQuizDialog(addedQ, allQ, allOutput, output, sendSuccess, sentDa
|
||||||
if (addedQ > 0) // if there are more than 0 new question
|
if (addedQ > 0) // if there are more than 0 new question
|
||||||
{
|
{
|
||||||
msg = "Klikk ide a nyers adatokhoz. " + addedQ +
|
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");
|
var useNetDB = GM_getValue("useNetDB");
|
||||||
if (useNetDB != undefined && useNetDB == 1) {
|
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.";
|
msg += " Nem sikerült kérdéseket elküldeni szervernek. Ha gondolod utánanézhetsz.";
|
||||||
else
|
else
|
||||||
msg += "Az új kérdések elküldve.";
|
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
|
} 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.";
|
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
|
}); // adding click
|
||||||
|
|
||||||
//addEventListener(window, 'scroll', function () {
|
let skipLoad = GM_getValue("skipLoad");
|
||||||
// menuButtonDiv.style.top = (pageYOffset + window.innerHeight - buttonHeight * 2) + 'px';
|
// TODO: add switch, and test loading stuff
|
||||||
//})
|
|
||||||
|
|
||||||
addEventListener(window, 'resize', function() {
|
addEventListener(window, 'resize', function() {
|
||||||
menuButtonDiv.style.left = window.innerWidth - buttonWidth * 2 + 'px';
|
menuButtonDiv.style.left = window.innerWidth - buttonWidth * 2 + 'px';
|
||||||
|
@ -2054,6 +2069,15 @@ function CreateNodeWithText(to, text, type) {
|
||||||
return paragraphElement;
|
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
|
// removes whitespace from begining and and, and replaces multiple spaces with one space
|
||||||
function RemoveUnnecesarySpaces(toremove) {
|
function RemoveUnnecesarySpaces(toremove) {
|
||||||
toremove = NormalizeSpaces(toremove);
|
toremove = NormalizeSpaces(toremove);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue