Merge branch 'devel'

This commit is contained in:
YourFriendlyNeighborhoodDealer 2019-03-09 14:40:55 +01:00
commit 73f3631f75

82
main.js
View file

@ -32,7 +32,7 @@ const forceTestPage = false;
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 = "";
@ -227,6 +227,8 @@ class QuestionDB {
//: Main function {{{ //: Main function {{{
function Main() { function Main() {
'use strict'; 'use strict';
console.time('main');
Init(function(count, subjCount) { Init(function(count, subjCount) {
var url = location.href; var url = location.href;
@ -237,36 +239,38 @@ function Main() {
m: "Passzív mód bekapcsolva, válaszok megjelenítéséhez menü gomb alatt kapcsold ki, és frissíts!", m: "Passzív mód bekapcsolva, válaszok megjelenítéséhez menü gomb alatt kapcsold ki, és frissíts!",
isSimple: true isSimple: true
}); });
return; } else {
} try {
if ((url.includes("/quiz/") && url.includes("attempt.php")) || forceTestPage) { // if the current page is a test
try { HandleQuiz();
if ((url.includes("/quiz/") && url.includes("attempt.php")) || forceTestPage) { // if the current page is a test } else if ((url.includes("/quiz/") && url.includes("review.php")) || forceResultPage) { // if the current window is a test-s result
HandleQuiz(); HandleResults(url);
} 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") && !url.includes(".pdf")) ||
HandleResults(url); (forceDefaultPage)) { // if the current window is any other window than a quiz or pdf.
} else if ((!url.includes("/quiz/") && !url.includes("review.php") && !url.includes(".pdf")) || HandleUI(url, count, subjCount);
(forceDefaultPage)) { // if the current window is any other window than a quiz or pdf. }
HandleUI(url, count, subjCount); } catch (e) {
} ShowMessage({
} catch (e) { m: "Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!",
ShowMessage({ isSimple: true
m: "Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!", }, undefined, function() {
isSimple: true GM_openInTab(serverAdress + 'legacy', {
}, undefined, function() { active: true
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) if (forceTestPage || forceResultPage || forceDefaultPage)
alert("TEST MODE"); alert("TEST MODE");
} }
@ -1237,7 +1241,7 @@ function SearchSameQuestion(questionData, quiz, i) {
let count = 0; let count = 0;
r.forEach((item) => { r.forEach((item) => {
if (item.match > minResultMatchPercent) if (item.match > minResultMatchPercent)
count ++; count++;
}); });
return count == 0 ? -1 : count; return count == 0 ? -1 : count;
@ -1587,7 +1591,7 @@ function ShowMessage(msgItem, timeout, funct) {
mainDiv.style.background = "#222d32"; // background color mainDiv.style.background = "#222d32"; // background color
mainDiv.style.color = "#ffffff"; // text color mainDiv.style.color = "#ffffff"; // text color
mainDiv.style.borderColor = "#035a8f"; // border color mainDiv.style.borderColor = "#035a8f"; // border color
mainDiv.style.border = "solid"; mainDiv.style.border = "none";
mainDiv.style.top = (startFromTop) + 'px'; mainDiv.style.top = (startFromTop) + 'px';
mainDiv.style.left = (window.innerWidth - width) / 2 + 'px'; mainDiv.style.left = (window.innerWidth - width) / 2 + 'px';
mainDiv.style.opacity = "0.9"; // setting starting opacity mainDiv.style.opacity = "0.9"; // setting starting opacity
@ -1817,12 +1821,16 @@ function ShowMenu() {
questionsTickBox.addEventListener("click", function() { questionsTickBox.addEventListener("click", function() {
GM_setValue("skipLoad", questionsTickBox.checked); GM_setValue("skipLoad", questionsTickBox.checked);
if (GM_getValue("skipLoad")) { var msg = "";
ShowMessage({ if (GM_getValue("skipLoad"))
m: "Passzív mód bekapcsolva, mostantól kérdések nem lesznek betöltve/lekérve.", msg = "Passzív mód bekapcsolva, mostantól kérdések nem lesznek betöltve/lekérve.";
isSimple: true else
}, 10); msg = "Passzív mód kikapcsolva, frissíts az érvénybe lépéshez!";
}
ShowMessage({
m: msg,
isSimple: true
}, 6);
}); });
var loadDataCheckBoxText = CreateNodeWithText(questionsTickBox, var loadDataCheckBoxText = CreateNodeWithText(questionsTickBox,
@ -1860,7 +1868,7 @@ function ShowMenuList() {
menuDiv.style.background = "#222d32"; // background color menuDiv.style.background = "#222d32"; // background color
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 = "none";
menuDiv.style.opacity = "1"; // setting starting opacity menuDiv.style.opacity = "1"; // setting starting opacity
var fiveMargin = "5px 5px 5px 5px"; var fiveMargin = "5px 5px 5px 5px";
@ -2121,7 +2129,7 @@ function RemoveMultipleItems(array) {
// removes some crap from "q" // removes some crap from "q"
function SimplifyQuery(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); return RemoveUnnecesarySpaces(result);
} }