mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Added MOTD
This commit is contained in:
parent
20fd1bec9e
commit
cba6321e74
1 changed files with 77 additions and 6 deletions
83
main.js
83
main.js
|
@ -22,15 +22,18 @@
|
|||
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 = "";
|
||||
|
||||
function Main() {
|
||||
'use strict';
|
||||
|
@ -614,7 +617,8 @@ function HandleUI(url, count) {
|
|||
}
|
||||
} 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;
|
||||
}
|
||||
|
@ -633,6 +637,30 @@ function HandleUI(url, count) {
|
|||
"-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
|
||||
|
@ -718,6 +746,48 @@ function Load(cwith) {
|
|||
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;
|
||||
|
@ -725,6 +795,7 @@ function NLoad(resource, cwith) {
|
|||
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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue