From 02461eb74af5695434ddffb0cbe1b99a8561bfd9 Mon Sep 17 00:00:00 2001 From: YourFriendlyNeighborhoodDealer <3167982-YourFriendlyNeighborhoodDealer@users.noreply.gitlab.com> Date: Sat, 1 Dec 2018 20:45:37 +0100 Subject: [PATCH] Added MOTD to stable.js --- frame.js | 2 +- stable.js | 90 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 83 insertions(+), 9 deletions(-) diff --git a/frame.js b/frame.js index 3cc8501..2c407cd 100644 --- a/frame.js +++ b/frame.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 1.5.4.0 +// @version 1.5.4.1 // @description Online Moodle/Elearning/KMOOC test help // @author YourFriendlyNeighborhoodDealer // @match https://elearning.uni-obuda.hu/main/* diff --git a/stable.js b/stable.js index 7d69661..543040d 100644 --- a/stable.js +++ b/stable.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 1.5.4.0 +// @version 1.5.4.1 // @description Online Moodle/Elearning/KMOOC test help // @author YourFriendlyNeighborhoodDealer // @match https://elearning.uni-obuda.hu/main/* @@ -38,18 +38,22 @@ // ==/UserScript== (function() { + var data; // all data, which is in the resource txt var addEventListener; // add event listener function var lastChangeLog = - '- Kis fixek'; + '- MOTD'; var serverAdress = "http://questionmining.tk/"; // forcing pages for testing. unless you test, do not set these to true! // only one of these should be true for testing - var forceTestPage = false; - var forceResultPage = false; - var forceDefaultPage = false; - var logElementGetting = false; + const forceTestPage = false; + const forceResultPage = false; + const forceDefaultPage = false; + const logElementGetting = false; + + var motdShowCount = 3; + var motd = ""; Main(); @@ -635,7 +639,9 @@ } } else // if there are no subje loaded or it has no name { - greetMsg += " Az adatfájlban nem adtál meg nevet. Katt a helpért!"; + greetMsg += + " Az adatfájlban nem adtál meg nevet. Vagy nem elérhető a szerver. Katt a helpért!"; + // TODO if online mode print another error! } timeout = 5; } @@ -654,6 +660,30 @@ "-re. Changelog:\n" + lastChangeLog; GM_setValue("lastVerson", GM_info.script.version); // setting lastVersion } + if (!EmptyOrWhiteSpace(motd)) { + + var prevmotd = GM_getValue("motd"); + if (prevmotd != motd) { + greetMsg += "\nMOTD:\n" + motd; + timeout = null; + GM_setValue("motdcount", motdShowCount); + GM_setValue("motd", motd); + } else { + var motdcount = GM_getValue("motdcount"); + if (motdcount == undefined) { + GM_setValue("motdcount", motdShowCount); + motdcount = motdShowCount; + } + + motdcount--; + if (motdcount > 0) { + greetMsg += "\nMOTD:\n" + motd; + timeout = null; + GM_setValue("motdcount", motdcount); + } + + } + } ShowMessage({ m: greetMsg, isSimple: true @@ -739,6 +769,48 @@ return ReadFile(cwith); } + // Creates a Question. + // q: question + // a: answer + // i: image + function Question(q, a, i) { + this.question = q; + this.answer = a; + this.image = i; + // Compares to another question. Simplifies question before comparing + // returns: true, if its matching + this.Compare = function(q2) { + var j = 0; + for (var j = 0; j < questionData.length; j++) { + var q1 = SimplifyStringForComparison(this.question); + var q2 = SimplifyStringForComparison(q2.question); + var a1 = SimplifyStringForComparison(); + var a2 = SimplifyStringForComparison(); + if (q1.includes(q2) && a2.includes(a2)) { // if the questions and the answers match + if (quiz[i].i && questionData[j].i) { // if it has image questionData + if (questionData[j].i.includes(quiz[i].i)) // if they are the same + return j; + } else { + return j; + } + } + } + return -1; + }; + } + + function LoadMOTD(resource) { + try { + if (resource[0][0] == '@') + motd = resource[0].substr(1).replace(/#/g, "\n"); + + } catch (e) { + console.log("Error loading motd :c"); + console.log(e); + } + } + + // loading stuff function NLoad(resource, cwith) { var count = -1; @@ -746,6 +818,7 @@ var allCount = 0; var currIndex = -1; resource = resource.split("\n"); // splitting by enters + LoadMOTD(resource); data = []; // initializing data declared at the begining function AddNewSubj(name) // adds a new subject to the data @@ -950,7 +1023,8 @@ dataToSend.push(output); dataToSend = dataToSend.join("\n"); } - sentData = "datatoadd=alldata<=>" + allOutput + "<#>data<=>" + dataToSend + "<#>subj<=>" + subj + + sentData = "datatoadd=alldata<=>" + allOutput + "<#>data<=>" + dataToSend + "<#>subj<=>" + + subj + "<#>type<=>" + useNetDB; SendXHRMessage(sentData); sendSuccess = true;