Added MOTD

This commit is contained in:
YourFriendlyNeighborhoodDealer 2018-12-01 20:40:08 +01:00
parent 20fd1bec9e
commit cba6321e74

83
main.js
View file

@ -22,15 +22,18 @@
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
var lastChangeLog = var lastChangeLog =
'- Kis fixek'; '- MOTD';
var serverAdress = "http://questionmining.tk/"; var serverAdress = "http://questionmining.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
var forceTestPage = false; const forceTestPage = false;
var forceResultPage = false; const forceResultPage = false;
var forceDefaultPage = false; const forceDefaultPage = false;
var logElementGetting = false; const logElementGetting = false;
var motdShowCount = 3;
var motd = "";
function Main() { function Main() {
'use strict'; 'use strict';
@ -614,7 +617,8 @@ function HandleUI(url, count) {
} }
} else // if there are no subje loaded or it has no name } 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; timeout = 5;
} }
@ -633,6 +637,30 @@ function HandleUI(url, count) {
"-re. Changelog:\n" + lastChangeLog; "-re. Changelog:\n" + lastChangeLog;
GM_setValue("lastVerson", GM_info.script.version); // setting lastVersion 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({ ShowMessage({
m: greetMsg, m: greetMsg,
isSimple: true isSimple: true
@ -718,6 +746,48 @@ function Load(cwith) {
return ReadFile(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 // loading stuff
function NLoad(resource, cwith) { function NLoad(resource, cwith) {
var count = -1; var count = -1;
@ -725,6 +795,7 @@ function NLoad(resource, cwith) {
var allCount = 0; var allCount = 0;
var currIndex = -1; var currIndex = -1;
resource = resource.split("\n"); // splitting by enters resource = resource.split("\n"); // splitting by enters
LoadMOTD(resource);
data = []; // initializing data declared at the begining data = []; // initializing data declared at the begining
function AddNewSubj(name) // adds a new subject to the data function AddNewSubj(name) // adds a new subject to the data