mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Added MOTD to stable.js
This commit is contained in:
parent
cba6321e74
commit
02461eb74a
2 changed files with 83 additions and 9 deletions
2
frame.js
2
frame.js
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Moodle/Elearning/KMOOC test help
|
// @name Moodle/Elearning/KMOOC test help
|
||||||
// @version 1.5.4.0
|
// @version 1.5.4.1
|
||||||
// @description Online Moodle/Elearning/KMOOC test help
|
// @description Online Moodle/Elearning/KMOOC test help
|
||||||
// @author YourFriendlyNeighborhoodDealer
|
// @author YourFriendlyNeighborhoodDealer
|
||||||
// @match https://elearning.uni-obuda.hu/main/*
|
// @match https://elearning.uni-obuda.hu/main/*
|
||||||
|
|
90
stable.js
90
stable.js
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Moodle/Elearning/KMOOC test help
|
// @name Moodle/Elearning/KMOOC test help
|
||||||
// @version 1.5.4.0
|
// @version 1.5.4.1
|
||||||
// @description Online Moodle/Elearning/KMOOC test help
|
// @description Online Moodle/Elearning/KMOOC test help
|
||||||
// @author YourFriendlyNeighborhoodDealer
|
// @author YourFriendlyNeighborhoodDealer
|
||||||
// @match https://elearning.uni-obuda.hu/main/*
|
// @match https://elearning.uni-obuda.hu/main/*
|
||||||
|
@ -38,18 +38,22 @@
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
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 = "";
|
||||||
|
|
||||||
Main();
|
Main();
|
||||||
|
|
||||||
|
@ -635,7 +639,9 @@
|
||||||
}
|
}
|
||||||
} 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;
|
||||||
}
|
}
|
||||||
|
@ -654,6 +660,30 @@
|
||||||
"-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
|
||||||
|
@ -739,6 +769,48 @@
|
||||||
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;
|
||||||
|
@ -746,6 +818,7 @@
|
||||||
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
|
||||||
|
@ -950,7 +1023,8 @@
|
||||||
dataToSend.push(output);
|
dataToSend.push(output);
|
||||||
dataToSend = dataToSend.join("\n");
|
dataToSend = dataToSend.join("\n");
|
||||||
}
|
}
|
||||||
sentData = "datatoadd=alldata<=>" + allOutput + "<#>data<=>" + dataToSend + "<#>subj<=>" + subj +
|
sentData = "datatoadd=alldata<=>" + allOutput + "<#>data<=>" + dataToSend + "<#>subj<=>" +
|
||||||
|
subj +
|
||||||
"<#>type<=>" + useNetDB;
|
"<#>type<=>" + useNetDB;
|
||||||
SendXHRMessage(sentData);
|
SendXHRMessage(sentData);
|
||||||
sendSuccess = true;
|
sendSuccess = true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue