From 8aeb5ecf63dd9fc0853d713acf7b780a6728eda2 Mon Sep 17 00:00:00 2001
From: YourFriendlyNeighborhoodDealer <qminer@2girls1dj.com>
Date: Mon, 4 Mar 2019 20:58:39 +0100
Subject: [PATCH 1/5] More question formatting before parsing, some constant
 modification, and better error messages

---
 main.js | 64 +++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 44 insertions(+), 20 deletions(-)

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);

From 6fa1625755544420d1e87aac3ccfeed98edf0d56 Mon Sep 17 00:00:00 2001
From: YourFriendlyNeighborhoodDealer <qminer@2girls1dj.com>
Date: Mon, 4 Mar 2019 21:07:25 +0100
Subject: [PATCH 2/5] Removing line breaks from the to-be-saved
 questions/answers

---
 main.js | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/main.js b/main.js
index 13861ef..268a81f 100644
--- a/main.js
+++ b/main.js
@@ -28,8 +28,8 @@ 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 = true;
-const forceResultPage = false;
+const forceTestPage = false;
+const forceResultPage = true;
 const forceDefaultPage = false;
 const logElementGetting = false;
 const log = true;
@@ -954,7 +954,7 @@ function NLoad(resource, cwith) {
 			} 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!", 
+					m: "Nem sikerült betölteni az adatokat! Ellenőriz a megadott fájlt, vagy az internetelérésed!",
 					isSimple: true
 				});
 				return;
@@ -1301,6 +1301,7 @@ function GetQuiz() {
 			var q = GetQuestionFromResult(i);
 			if (q != undefined)
 				question.q = SimplifyQuery(q);
+
 			// RIGHTANSWER ---------------------------------------------------------------------------------------------------------------------
 			var a = GetRightAnswerFromResultv2(i);
 			if (a == undefined)
@@ -1311,6 +1312,9 @@ function GetQuiz() {
 			var img = GetImageFormResult(i);
 			question.i = img;
 
+			q = ReplaceCharsWithSpace(q, "\n");
+			a = ReplaceCharsWithSpace(a, "\n");
+
 			if (question.a != undefined) // adding only if has question
 			{
 				quiz.push(new Question(question.q, question.a, question.i)); // adding current question to quiz

From 932f215f79ba0b66c4aca3bda99296498e7842bb Mon Sep 17 00:00:00 2001
From: YourFriendlyNeighborhoodDealer <qminer@2girls1dj.com>
Date: Mon, 4 Mar 2019 21:52:43 +0100
Subject: [PATCH 3/5] Passive mode, and buttons for that one

---
 main.js | 56 ++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 42 insertions(+), 14 deletions(-)

diff --git a/main.js b/main.js
index 268a81f..00d400b 100644
--- a/main.js
+++ b/main.js
@@ -29,7 +29,7 @@ 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 forceResultPage = true;
+const forceResultPage = false;
 const forceDefaultPage = false;
 const logElementGetting = false;
 const log = true;
@@ -912,8 +912,10 @@ function Load(cwith) {
 	var useNetDB = GM_getValue("useNetDB");
 	let skipLoad = GM_getValue("skipLoad");
 
-	if (skipLoad)
+	if (skipLoad) {
+		console.log("HAAAAAAAAAAA");
 		return -1;
+	}
 
 	if (useNetDB != undefined && useNetDB == 1)
 		return ReadNetDB(cwith, useNetDB);
@@ -1727,12 +1729,12 @@ function ShowMessage(msgItem, timeout, funct) {
 // shows a fancy menu
 function ShowMenu() {
 	try {
-		var buttonWidth = 75; // button size ;)
-		var buttonHeight = 55;
+		var buttonWidth = 100; // button size ;)
+		var buttonHeight = 85;
 		var appedtTo = document.body; // will be appended here
 
 		// mainDiv.style.left = (window.innerWidth - width) / 2 + 'px';
-
+		
 		var menuButtonDiv = document.createElement("div");
 		menuButtonDiv.setAttribute("id", "HelperMenuButton");
 		menuButtonDiv.style.width = buttonWidth + 'px';
@@ -1745,16 +1747,21 @@ function ShowMenu() {
 		// design
 		menuButtonDiv.style.textAlign = "center";
 		menuButtonDiv.style.padding = "0px";
-		menuButtonDiv.style.background = "#222d32"; // background color
-		menuButtonDiv.style.color = "#ffffff"; // text color
-		menuButtonDiv.style.borderColor = "#035a8f"; // border color
-		menuButtonDiv.style.border = "solid";
-		menuButtonDiv.style.opacity = "0.9"; // setting starting opacity
+		menuButtonDiv.style.margin = "0px";
+		menuButtonDiv.style.background = "transparent"; // background color
 
 		// 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, "Helper Menu", "button");
+		menuButton.style.width = buttonWidth + 'px';
+		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) {
 				ShowMenuList();
 			} else {
@@ -1762,8 +1769,29 @@ function ShowMenu() {
 			}
 		}); // adding click
 
-		let skipLoad = GM_getValue("skipLoad");
-		// TODO: add switch, and test loading stuff
+		// passive mode stuff
+		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")){
+				// TODO show msgbox eplaining this, but only once
+			}
+			
+		}); 
+		var loadDataCheckBoxText = CreateNodeWithText(questionsTickBox,
+			"Passzív mód", "span");
+		loadDataCheckBoxText.style.fontSize = "12px";
+
+		menuButtonDiv.appendChild(loadDataCheckBoxText);
 
 		addEventListener(window, 'resize', function() {
 			menuButtonDiv.style.left = window.innerWidth - buttonWidth * 2 + 'px';

From b646640993ded8dcbe28b5906f7ebc1f3da05506 Mon Sep 17 00:00:00 2001
From: YourFriendlyNeighborhoodDealer <qminer@2girls1dj.com>
Date: Mon, 4 Mar 2019 22:07:26 +0100
Subject: [PATCH 4/5] Passive mode improvements

---
 main.js | 31 +++++++++++++++++++------------
 1 file changed, 19 insertions(+), 12 deletions(-)

diff --git a/main.js b/main.js
index 00d400b..1885203 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 =
-	'TODO';
+	'- Passzív mód: ha bepipálod a menü gomb alatt, akkor nem tölti be minden alkalommal a kérdéseket.\n - Pár lényeges bugfix\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!
@@ -912,10 +912,8 @@ function Load(cwith) {
 	var useNetDB = GM_getValue("useNetDB");
 	let skipLoad = GM_getValue("skipLoad");
 
-	if (skipLoad) {
-		console.log("HAAAAAAAAAAA");
+	if (skipLoad)
 		return -1;
-	}
 
 	if (useNetDB != undefined && useNetDB == 1)
 		return ReadNetDB(cwith, useNetDB);
@@ -1734,7 +1732,7 @@ function ShowMenu() {
 		var appedtTo = document.body; // will be appended here
 
 		// mainDiv.style.left = (window.innerWidth - width) / 2 + 'px';
-		
+
 		var menuButtonDiv = document.createElement("div");
 		menuButtonDiv.setAttribute("id", "HelperMenuButton");
 		menuButtonDiv.style.width = buttonWidth + 'px';
@@ -1782,11 +1780,14 @@ function ShowMenu() {
 
 		questionsTickBox.addEventListener("click", function() {
 			GM_setValue("skipLoad", questionsTickBox.checked);
-			if (!GM_getValue("skipLoad")){
-				// TODO show msgbox eplaining this, but only once
+			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";
@@ -1896,10 +1897,16 @@ function ShowMenuList() {
 		{
 			var noDataRow = tbl.insertRow();
 			var noDataRowCell = noDataRow.insertCell();
+			var textBox;
 
-			var 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!"
-			);
+			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!"
+				);
 			textBox.style.margin = fiveMargin; // fancy margin
 
 		}

From 69e32bd3bcd945a046163321d5083b4d69e58675 Mon Sep 17 00:00:00 2001
From: YourFriendlyNeighborhoodDealer <qminer@2girls1dj.com>
Date: Tue, 5 Mar 2019 08:23:28 +0100
Subject: [PATCH 5/5] Dropdown box question getting fix, small design changes

---
 main.js | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/main.js b/main.js
index 1885203..d296bb9 100644
--- a/main.js
+++ b/main.js
@@ -23,12 +23,12 @@
 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.\n - Pár lényeges bugfix\n - Ha találkoztok bugokkal, akkor pls report! thanx';
+	'- 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/";
 
 // 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;
@@ -38,7 +38,7 @@ const motdShowCount = 3;
 var motd = "";
 var lastestVersion = "";
 
-const minMatchAmmount = 60;
+const minMatchAmmount = 55;
 const lengthDiffMultiplier = 10;
 
 //: Class descriptions {{{
@@ -264,7 +264,14 @@ function Main() {
 function GetAllQuestionsDropdown() {
 	if (logElementGetting)
 		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() {
@@ -772,8 +779,13 @@ function ReadFile(cwith) {
 	var resource = "";
 	try {
 		resource = GM_getResourceText("data"); // getting data from txt
-		if (resource == null) {
-			return; // TODO show some msg what happened
+		if (resource == undefined) {
+
+			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)) {
 			throw {
@@ -812,7 +824,6 @@ function ReadNetDB(cwith, useNetDB) {
 /*
  * Returns a question database from the given data.
  * Parameter should be raw read file in string with "\n"-s
- * TODO: ??? -s are not listed as errors, tho works correctly
  * */
 function ParseRawData(data) {
 
@@ -1112,7 +1123,6 @@ function HandleQuiz() {
 			answers.push(r);
 		HighLightAnswer(result, j); // highlights the answer for the current result
 	}
-	console.log(GetAnswerOptions());
 	ShowAnswers(answers);
 }
 
@@ -1741,6 +1751,8 @@ function ShowMenu() {
 		menuButtonDiv.style.left = window.innerWidth - buttonWidth * 1.5 + 'px';
 		menuButtonDiv.style.zIndex = 999999; // TO THE MAX
 		menuButtonDiv.style.position = "fixed";
+		// menuButtonDiv.style.borderStyle = "solid";
+		// menuButtonDiv.style.borderWidth = "1px";
 
 		// design
 		menuButtonDiv.style.textAlign = "center";
@@ -1751,8 +1763,9 @@ function ShowMenu() {
 		// menu text
 		// var menuTextBox = CreateNodeWithText(menuButtonDiv, "Kérdések\nMenü");
 
-		var menuButton = CreateNodeWithText(menuButtonDiv, "Helper Menu", "button");
+		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
@@ -2007,7 +2020,6 @@ function ShowMenuList() {
 		var xButton = CreateNodeWithText(buttonCell, "Bezárás", "button");
 
 		xButton.style.position = "";
-		xButton.style.background = "white";
 		xButton.style.left = 10 + 'px';
 		xButton.style.margin = "5px 5px 5px 5px"; // fancy margin
 		xButton.style.top = menuDiv.offsetHeight + 'px';
@@ -2019,7 +2031,6 @@ function ShowMenuList() {
 		var helpButton = CreateNodeWithText(buttonCell, "Help", "button");
 
 		helpButton.style.position = "";
-		helpButton.style.background = "white";
 		helpButton.style.left = 10 + 'px';
 		helpButton.style.margin = "5px 5px 5px 5px"; // fancy margin
 		helpButton.style.top = menuDiv.offsetHeight + 'px';