mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Merge branch 'devel'
This commit is contained in:
commit
e15b078dd6
1 changed files with 113 additions and 39 deletions
144
main.js
144
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.';
|
'- 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';
|
||||||
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 = 55;
|
||||||
|
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;
|
||||||
|
@ -268,7 +264,14 @@ function Main() {
|
||||||
function GetAllQuestionsDropdown() {
|
function GetAllQuestionsDropdown() {
|
||||||
if (logElementGetting)
|
if (logElementGetting)
|
||||||
Log("getting dropdown question");
|
Log("getting dropdown question");
|
||||||
return document.getElementById("responseform").getElementsByTagName("p")[0].innerText;
|
let items = document.getElementById("responseform").getElementsByTagName("p")[0].childNodes;
|
||||||
|
let r = "";
|
||||||
|
items.forEach((item) => {
|
||||||
|
if (item.tagName == undefined)
|
||||||
|
r += item.nodeValue;
|
||||||
|
|
||||||
|
});
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetAllQuestionsQtext() {
|
function GetAllQuestionsQtext() {
|
||||||
|
@ -290,7 +293,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 +533,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,
|
||||||
|
@ -772,8 +779,13 @@ function ReadFile(cwith) {
|
||||||
var resource = "";
|
var resource = "";
|
||||||
try {
|
try {
|
||||||
resource = GM_getResourceText("data"); // getting data from txt
|
resource = GM_getResourceText("data"); // getting data from txt
|
||||||
if (resource == null) {
|
if (resource == undefined) {
|
||||||
return; // TODO show some msg what happened
|
|
||||||
|
ShowMessage({
|
||||||
|
m: "Nem lehetett beolvasni a fájlt :c Ellenőrizd az elérési utat, vagy a fájl jogosultságokat",
|
||||||
|
isSimple: true
|
||||||
|
});
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if (EmptyOrWhiteSpace(resource)) {
|
if (EmptyOrWhiteSpace(resource)) {
|
||||||
throw {
|
throw {
|
||||||
|
@ -812,7 +824,6 @@ function ReadNetDB(cwith, useNetDB) {
|
||||||
/*
|
/*
|
||||||
* Returns a question database from the given data.
|
* Returns a question database from the given data.
|
||||||
* Parameter should be raw read file in string with "\n"-s
|
* Parameter should be raw read file in string with "\n"-s
|
||||||
* TODO: ??? -s are not listed as errors, tho works correctly
|
|
||||||
* */
|
* */
|
||||||
function ParseRawData(data) {
|
function ParseRawData(data) {
|
||||||
|
|
||||||
|
@ -910,6 +921,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 +960,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....");
|
||||||
|
try {
|
||||||
d = ParseRawData(resource).result;
|
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 +1028,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
|
||||||
|
@ -1098,7 +1123,6 @@ function HandleQuiz() {
|
||||||
answers.push(r);
|
answers.push(r);
|
||||||
HighLightAnswer(result, j); // highlights the answer for the current result
|
HighLightAnswer(result, j); // highlights the answer for the current result
|
||||||
}
|
}
|
||||||
console.log(GetAnswerOptions());
|
|
||||||
ShowAnswers(answers);
|
ShowAnswers(answers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1156,7 +1180,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 +1188,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.";
|
||||||
|
@ -1285,6 +1311,7 @@ function GetQuiz() {
|
||||||
var q = GetQuestionFromResult(i);
|
var q = GetQuestionFromResult(i);
|
||||||
if (q != undefined)
|
if (q != undefined)
|
||||||
question.q = SimplifyQuery(q);
|
question.q = SimplifyQuery(q);
|
||||||
|
|
||||||
// RIGHTANSWER ---------------------------------------------------------------------------------------------------------------------
|
// RIGHTANSWER ---------------------------------------------------------------------------------------------------------------------
|
||||||
var a = GetRightAnswerFromResultv2(i);
|
var a = GetRightAnswerFromResultv2(i);
|
||||||
if (a == undefined)
|
if (a == undefined)
|
||||||
|
@ -1295,6 +1322,9 @@ function GetQuiz() {
|
||||||
var img = GetImageFormResult(i);
|
var img = GetImageFormResult(i);
|
||||||
question.i = img;
|
question.i = img;
|
||||||
|
|
||||||
|
q = ReplaceCharsWithSpace(q, "\n");
|
||||||
|
a = ReplaceCharsWithSpace(a, "\n");
|
||||||
|
|
||||||
if (question.a != undefined) // adding only if has question
|
if (question.a != undefined) // adding only if has question
|
||||||
{
|
{
|
||||||
quiz.push(new Question(question.q, question.a, question.i)); // adding current question to quiz
|
quiz.push(new Question(question.q, question.a, question.i)); // adding current question to quiz
|
||||||
|
@ -1707,8 +1737,8 @@ function ShowMessage(msgItem, timeout, funct) {
|
||||||
// shows a fancy menu
|
// shows a fancy menu
|
||||||
function ShowMenu() {
|
function ShowMenu() {
|
||||||
try {
|
try {
|
||||||
var buttonWidth = 75; // button size ;)
|
var buttonWidth = 100; // button size ;)
|
||||||
var buttonHeight = 55;
|
var buttonHeight = 85;
|
||||||
var appedtTo = document.body; // will be appended here
|
var appedtTo = document.body; // will be appended here
|
||||||
|
|
||||||
// mainDiv.style.left = (window.innerWidth - width) / 2 + 'px';
|
// mainDiv.style.left = (window.innerWidth - width) / 2 + 'px';
|
||||||
|
@ -1721,20 +1751,28 @@ function ShowMenu() {
|
||||||
menuButtonDiv.style.left = window.innerWidth - buttonWidth * 1.5 + 'px';
|
menuButtonDiv.style.left = window.innerWidth - buttonWidth * 1.5 + 'px';
|
||||||
menuButtonDiv.style.zIndex = 999999; // TO THE MAX
|
menuButtonDiv.style.zIndex = 999999; // TO THE MAX
|
||||||
menuButtonDiv.style.position = "fixed";
|
menuButtonDiv.style.position = "fixed";
|
||||||
|
// menuButtonDiv.style.borderStyle = "solid";
|
||||||
|
// menuButtonDiv.style.borderWidth = "1px";
|
||||||
|
|
||||||
// design
|
// design
|
||||||
menuButtonDiv.style.textAlign = "center";
|
menuButtonDiv.style.textAlign = "center";
|
||||||
menuButtonDiv.style.padding = "0px";
|
menuButtonDiv.style.padding = "0px";
|
||||||
menuButtonDiv.style.background = "#222d32"; // background color
|
menuButtonDiv.style.margin = "0px";
|
||||||
menuButtonDiv.style.color = "#ffffff"; // text color
|
menuButtonDiv.style.background = "transparent"; // background color
|
||||||
menuButtonDiv.style.borderColor = "#035a8f"; // border color
|
|
||||||
menuButtonDiv.style.border = "solid";
|
|
||||||
menuButtonDiv.style.opacity = "0.9"; // setting starting opacity
|
|
||||||
|
|
||||||
// menu text
|
// menu text
|
||||||
var menuTextBox = CreateNodeWithText(menuButtonDiv, "Kérdések\nMenü");
|
// var menuTextBox = CreateNodeWithText(menuButtonDiv, "Kérdések\nMenü");
|
||||||
|
|
||||||
menuButtonDiv.addEventListener("click", function() {
|
var menuButton = CreateNodeWithText(menuButtonDiv, "Kérdések Menu", "button");
|
||||||
|
menuButton.style.width = buttonWidth + 'px';
|
||||||
|
menuButton.style.border = 'none';
|
||||||
|
menuButton.style.height = buttonHeight - 20 + 'px';
|
||||||
|
menuButton.style.background = "#222d32"; // background color
|
||||||
|
menuButton.style.color = "#ffffff"; // background color
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
menuButton.addEventListener("click", function() {
|
||||||
if (document.getElementById("HelperMenu") == null) {
|
if (document.getElementById("HelperMenu") == null) {
|
||||||
ShowMenuList();
|
ShowMenuList();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1742,9 +1780,32 @@ function ShowMenu() {
|
||||||
}
|
}
|
||||||
}); // adding click
|
}); // adding click
|
||||||
|
|
||||||
//addEventListener(window, 'scroll', function () {
|
// passive mode stuff
|
||||||
// menuButtonDiv.style.top = (pageYOffset + window.innerHeight - buttonHeight * 2) + 'px';
|
var questionsTickBox = document.createElement("input");
|
||||||
//})
|
questionsTickBox.type = "checkbox";
|
||||||
|
questionsTickBox.checked = GM_getValue("skipLoad");
|
||||||
|
questionsTickBox.style.position = "";
|
||||||
|
questionsTickBox.style.left = 10 + 'px';
|
||||||
|
questionsTickBox.style.margin = "5px 5px 5px 5px"; // fancy margin
|
||||||
|
questionsTickBox.style.top = 0 + 'px';
|
||||||
|
|
||||||
|
menuButtonDiv.appendChild(questionsTickBox); // adding to main div
|
||||||
|
|
||||||
|
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 loadDataCheckBoxText = CreateNodeWithText(questionsTickBox,
|
||||||
|
"Passzív mód", "span");
|
||||||
|
loadDataCheckBoxText.style.fontSize = "12px";
|
||||||
|
|
||||||
|
menuButtonDiv.appendChild(loadDataCheckBoxText);
|
||||||
|
|
||||||
addEventListener(window, 'resize', function() {
|
addEventListener(window, 'resize', function() {
|
||||||
menuButtonDiv.style.left = window.innerWidth - buttonWidth * 2 + 'px';
|
menuButtonDiv.style.left = window.innerWidth - buttonWidth * 2 + 'px';
|
||||||
|
@ -1849,8 +1910,14 @@ function ShowMenuList() {
|
||||||
{
|
{
|
||||||
var noDataRow = tbl.insertRow();
|
var noDataRow = tbl.insertRow();
|
||||||
var noDataRowCell = noDataRow.insertCell();
|
var noDataRowCell = noDataRow.insertCell();
|
||||||
|
var textBox;
|
||||||
|
|
||||||
var textBox = CreateNodeWithText(noDataRowCell,
|
if (GM_getValue("skipLoad"))
|
||||||
|
textBox = CreateNodeWithText(noDataRowCell,
|
||||||
|
"Passszív mód bekapcsolva. Kapcsold ki a kérdések betöltéséhez!"
|
||||||
|
);
|
||||||
|
else
|
||||||
|
textBox = CreateNodeWithText(noDataRowCell,
|
||||||
"A kérdéseket nem lehetett beolvasni. Vagy nem elérhető a szerver, vagy ha offline módot használsz, akkor hibás a fájl elérési útja, vagy a fájl maga. Olvasd el a manualt!"
|
"A kérdéseket nem lehetett beolvasni. Vagy nem elérhető a szerver, vagy ha offline módot használsz, akkor hibás a fájl elérési útja, vagy a fájl maga. Olvasd el a manualt!"
|
||||||
);
|
);
|
||||||
textBox.style.margin = fiveMargin; // fancy margin
|
textBox.style.margin = fiveMargin; // fancy margin
|
||||||
|
@ -1953,7 +2020,6 @@ function ShowMenuList() {
|
||||||
var xButton = CreateNodeWithText(buttonCell, "Bezárás", "button");
|
var xButton = CreateNodeWithText(buttonCell, "Bezárás", "button");
|
||||||
|
|
||||||
xButton.style.position = "";
|
xButton.style.position = "";
|
||||||
xButton.style.background = "white";
|
|
||||||
xButton.style.left = 10 + 'px';
|
xButton.style.left = 10 + 'px';
|
||||||
xButton.style.margin = "5px 5px 5px 5px"; // fancy margin
|
xButton.style.margin = "5px 5px 5px 5px"; // fancy margin
|
||||||
xButton.style.top = menuDiv.offsetHeight + 'px';
|
xButton.style.top = menuDiv.offsetHeight + 'px';
|
||||||
|
@ -1965,7 +2031,6 @@ function ShowMenuList() {
|
||||||
var helpButton = CreateNodeWithText(buttonCell, "Help", "button");
|
var helpButton = CreateNodeWithText(buttonCell, "Help", "button");
|
||||||
|
|
||||||
helpButton.style.position = "";
|
helpButton.style.position = "";
|
||||||
helpButton.style.background = "white";
|
|
||||||
helpButton.style.left = 10 + 'px';
|
helpButton.style.left = 10 + 'px';
|
||||||
helpButton.style.margin = "5px 5px 5px 5px"; // fancy margin
|
helpButton.style.margin = "5px 5px 5px 5px"; // fancy margin
|
||||||
helpButton.style.top = menuDiv.offsetHeight + 'px';
|
helpButton.style.top = menuDiv.offsetHeight + 'px';
|
||||||
|
@ -2054,6 +2119,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