mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Added fold markers
This commit is contained in:
parent
57274ad8d4
commit
6cded4b5a4
1 changed files with 118 additions and 141 deletions
261
stable.user.js
261
stable.user.js
|
@ -1,3 +1,4 @@
|
||||||
|
// vim:foldmethod=marker
|
||||||
/* ----------------------------------------------------------------------------
|
/* ----------------------------------------------------------------------------
|
||||||
|
|
||||||
Online Moodle/Elearning/KMOOC test help
|
Online Moodle/Elearning/KMOOC test help
|
||||||
|
@ -21,7 +22,7 @@
|
||||||
|
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Moodle/Elearning/KMOOC test help
|
// @name Moodle/Elearning/KMOOC test help
|
||||||
// @version 2.0.1.21
|
// @version 2.1.0.0
|
||||||
// @description Online Moodle/Elearning/KMOOC test help
|
// @description Online Moodle/Elearning/KMOOC test help
|
||||||
// @author MrFry
|
// @author MrFry
|
||||||
// @match https://elearning.uni-obuda.hu/main/*
|
// @match https://elearning.uni-obuda.hu/main/*
|
||||||
|
@ -46,12 +47,10 @@
|
||||||
// @namespace https://qmining.frylabs.net
|
// @namespace https://qmining.frylabs.net
|
||||||
// @updateURL https://qmining.frylabs.net/moodle-test-userscript/stable.user.js?up
|
// @updateURL https://qmining.frylabs.net/moodle-test-userscript/stable.user.js?up
|
||||||
// ==/UserScript==
|
// ==/UserScript==
|
||||||
//
|
|
||||||
// TODO:
|
|
||||||
// grabboxes test on quiz page
|
|
||||||
|
|
||||||
// TODO: test if this ; does not fuck up things (it seams it does not)
|
|
||||||
;(function() {
|
;(function() {
|
||||||
|
// : ESLINT bs {{{
|
||||||
|
|
||||||
// eslint-disable-line
|
// eslint-disable-line
|
||||||
// GM functions, only to disable ESLINT errors
|
// GM functions, only to disable ESLINT errors
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
@ -77,6 +76,10 @@
|
||||||
}
|
}
|
||||||
/* eslint-enable */
|
/* eslint-enable */
|
||||||
|
|
||||||
|
// : }}}
|
||||||
|
|
||||||
|
// : Constants and global variables {{{
|
||||||
|
|
||||||
var addEventListener // add event listener function
|
var addEventListener // add event listener function
|
||||||
let serverAdress = 'https://qmining.frylabs.net/'
|
let serverAdress = 'https://qmining.frylabs.net/'
|
||||||
let apiAdress = 'https://api.frylabs.net/'
|
let apiAdress = 'https://api.frylabs.net/'
|
||||||
|
@ -113,6 +116,8 @@
|
||||||
apiAdress = 'http://localhost:8080/'
|
apiAdress = 'http://localhost:8080/'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// : Localisation {{{
|
||||||
|
|
||||||
const huTexts = {
|
const huTexts = {
|
||||||
lastChangeLog: '',
|
lastChangeLog: '',
|
||||||
fatalError:
|
fatalError:
|
||||||
|
@ -150,18 +155,13 @@
|
||||||
|
|
||||||
var texts = huTexts
|
var texts = huTexts
|
||||||
|
|
||||||
// : question-classes {{{
|
// : }}}
|
||||||
const specialChars = ['&', '\\+']
|
|
||||||
|
|
||||||
const assert = val => {
|
// : }}}
|
||||||
if (!val) {
|
|
||||||
throw new Error('Assertion failed')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
// : HTML parsers {{{
|
||||||
// Basic processing helpers
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
// : Basic processing helpers {{{
|
||||||
|
|
||||||
function getTextPromisesFromNode(node) {
|
function getTextPromisesFromNode(node) {
|
||||||
const promises = []
|
const promises = []
|
||||||
|
@ -218,9 +218,9 @@
|
||||||
return [...new Set(a)]
|
return [...new Set(a)]
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
// : }}}
|
||||||
// Test page processing functions
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
// : Test page processing functions {{{
|
||||||
|
|
||||||
function handleQuiz() {
|
function handleQuiz() {
|
||||||
getQuizData().then(res => {
|
getQuizData().then(res => {
|
||||||
|
@ -366,9 +366,9 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
// : }}}
|
||||||
// Result page processing functions
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
// : Result page processing functions {{{
|
||||||
|
|
||||||
function getQuiz() {
|
function getQuiz() {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
@ -383,13 +383,6 @@
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
// [{
|
|
||||||
// "Q": "Mekkora tényezővel kell számolnunk, ha 100.000 Ft jelenértékét keressük 24% kamatláb, havi tőkésítés és 2,5 éves futamidő mellett?\n\n\n",
|
|
||||||
// "A": "c.\n\n0,552\n",
|
|
||||||
// "data": {
|
|
||||||
// "type": "simple"
|
|
||||||
// }
|
|
||||||
// }]
|
|
||||||
Promise.all(promises)
|
Promise.all(promises)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
resolve(result)
|
resolve(result)
|
||||||
|
@ -608,55 +601,30 @@
|
||||||
return dataURL.replace(/^data:image\/(png|jpg);base64,/, '')
|
return dataURL.replace(/^data:image\/(png|jpg);base64,/, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
// : }}}
|
||||||
// String utils 2
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
function removeUnnecesarySpaces(toremove) {
|
// : Misc {{{
|
||||||
// TODO: check if this doesnt kill if question / answer is empty
|
|
||||||
if (!toremove) {
|
function getVideo() {
|
||||||
return ''
|
if (logElementGetting) {
|
||||||
|
Log('getting video stuff')
|
||||||
|
}
|
||||||
|
return document.getElementsByTagName('video')[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
toremove = normalizeSpaces(toremove).replace(/\t/g, '')
|
function getVideoElement() {
|
||||||
while (toremove.includes(' ')) {
|
if (logElementGetting) {
|
||||||
toremove = toremove.replace(/ {2}/g, ' ')
|
Log('getting video element')
|
||||||
}
|
}
|
||||||
while (toremove.includes('\n\n')) {
|
return document.getElementById('videoElement').parentNode
|
||||||
toremove = toremove.replace(/\n{2}/g, ' ')
|
|
||||||
}
|
}
|
||||||
return toremove.trim()
|
|
||||||
}
|
|
||||||
|
|
||||||
function normalizeSpaces(input) {
|
|
||||||
assert(input)
|
|
||||||
|
|
||||||
return input.replace(/\s/g, ' ')
|
|
||||||
}
|
|
||||||
|
|
||||||
function emptyOrWhiteSpace(value) {
|
|
||||||
if (value === undefined) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
|
||||||
value
|
|
||||||
.replace(/\n/g, '')
|
|
||||||
.replace(/\t/g, '')
|
|
||||||
.replace(/ /g, '')
|
|
||||||
.replace(/\s/g, ' ') === ''
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// : }}}
|
// : }}}
|
||||||
|
|
||||||
// : DOM getting stuff {{{
|
// : }}}
|
||||||
// all dom getting stuff are in this sections, so on
|
|
||||||
// moodle dom change, stuff breaks here
|
// : Stealth by An0 with love {{{
|
||||||
|
|
||||||
//Stealth by An0 with love
|
|
||||||
function StealthOverlay() {
|
function StealthOverlay() {
|
||||||
//call this before the document scripts
|
//call this before the document scripts
|
||||||
const document = window.document
|
const document = window.document
|
||||||
|
@ -748,21 +716,6 @@
|
||||||
|
|
||||||
const overlay = StealthOverlay()
|
const overlay = StealthOverlay()
|
||||||
|
|
||||||
function appendBelowElement(el, toAppend) {
|
|
||||||
const rect = el.getBoundingClientRect()
|
|
||||||
const left = rect.left + window.scrollX
|
|
||||||
const top = rect.top + window.scrollY
|
|
||||||
|
|
||||||
SetStyle(toAppend, {
|
|
||||||
position: 'absolute',
|
|
||||||
zIndex: 999999,
|
|
||||||
top: top + 'px',
|
|
||||||
left: left + 'px',
|
|
||||||
})
|
|
||||||
|
|
||||||
overlay.appendChild(toAppend)
|
|
||||||
}
|
|
||||||
|
|
||||||
function createHoverOver(appendTo) {
|
function createHoverOver(appendTo) {
|
||||||
const overlayElement = document.createElement('div')
|
const overlayElement = document.createElement('div')
|
||||||
overlay.append(overlayElement)
|
overlay.append(overlayElement)
|
||||||
|
@ -794,29 +747,27 @@
|
||||||
return overlayElement
|
return overlayElement
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
function appendBelowElement(el, toAppend) {
|
||||||
// Misc
|
const rect = el.getBoundingClientRect()
|
||||||
// ----------------------------------------------------------------------------------------------
|
const left = rect.left + window.scrollX
|
||||||
|
const top = rect.top + window.scrollY
|
||||||
|
|
||||||
function getVideo() {
|
SetStyle(toAppend, {
|
||||||
if (logElementGetting) {
|
position: 'absolute',
|
||||||
Log('getting video stuff')
|
zIndex: 999999,
|
||||||
}
|
top: top + 'px',
|
||||||
return document.getElementsByTagName('video')[0]
|
left: left + 'px',
|
||||||
}
|
})
|
||||||
|
|
||||||
function getVideoElement() {
|
overlay.appendChild(toAppend)
|
||||||
if (logElementGetting) {
|
|
||||||
Log('getting video element')
|
|
||||||
}
|
}
|
||||||
return document.getElementById('videoElement').parentNode
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
// : }}}
|
// : }}}
|
||||||
|
|
||||||
|
// : Main logic stuff {{{
|
||||||
|
|
||||||
// : Main function {{{
|
// : Main function {{{
|
||||||
|
|
||||||
let timerStarted = false
|
let timerStarted = false
|
||||||
|
|
||||||
// window.addEventListener("load", () => {})
|
// window.addEventListener("load", () => {})
|
||||||
|
@ -893,8 +844,6 @@
|
||||||
}
|
}
|
||||||
// : }}}
|
// : }}}
|
||||||
|
|
||||||
// : Main logic stuff {{{
|
|
||||||
|
|
||||||
// : Loading {{{
|
// : Loading {{{
|
||||||
function HandleQminingSite(url) {
|
function HandleQminingSite(url) {
|
||||||
try {
|
try {
|
||||||
|
@ -1065,6 +1014,8 @@
|
||||||
FreshStart()
|
FreshStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// : }}}
|
||||||
|
|
||||||
// : Version action functions {{{
|
// : Version action functions {{{
|
||||||
|
|
||||||
function FreshStart() {
|
function FreshStart() {
|
||||||
|
@ -1285,7 +1236,7 @@
|
||||||
|
|
||||||
// : }}}
|
// : }}}
|
||||||
|
|
||||||
// : Helpers {{{
|
// : Video hotkey stuff {{{
|
||||||
|
|
||||||
// this function adds basic hotkeys for video controll.
|
// this function adds basic hotkeys for video controll.
|
||||||
function AddVideoHotkeys(url) {
|
function AddVideoHotkeys(url) {
|
||||||
|
@ -1321,50 +1272,12 @@
|
||||||
node.style.margin = '5px 5px 5px 5px' // fancy margin
|
node.style.margin = '5px 5px 5px 5px' // fancy margin
|
||||||
}
|
}
|
||||||
|
|
||||||
// removes stuff like " a. q1" -> "q1"
|
// : }}}
|
||||||
function RemoveLetterMarking(inp) {
|
|
||||||
let dotIndex = inp.indexOf('.')
|
|
||||||
let doubledotIndex = inp.indexOf(':')
|
|
||||||
let maxInd = 4 // inp.length * 0.2;
|
|
||||||
|
|
||||||
if (dotIndex < maxInd) {
|
|
||||||
return removeUnnecesarySpaces(
|
|
||||||
inp.substr(inp.indexOf('.') + 1, inp.length)
|
|
||||||
)
|
|
||||||
} else if (doubledotIndex < maxInd) {
|
|
||||||
return removeUnnecesarySpaces(
|
|
||||||
inp.substr(inp.indexOf(':') + 1, inp.length)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
return inp
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// highlights the possible solutions to the current question
|
|
||||||
function HighLightAnswer(results, currQuestionNumber) {
|
|
||||||
// TODO: fix this
|
|
||||||
}
|
|
||||||
|
|
||||||
// : }}}
|
// : }}}
|
||||||
|
|
||||||
function Log(value) {
|
// : Show message, and script menu stuff {{{
|
||||||
if (log) {
|
|
||||||
console.log(value)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function Exception(e, msg) {
|
|
||||||
Log('------------------------------------------')
|
|
||||||
Log(msg)
|
|
||||||
Log(e.message)
|
|
||||||
Log('------------------------------------------')
|
|
||||||
Log(e.stack)
|
|
||||||
Log('------------------------------------------')
|
|
||||||
}
|
|
||||||
|
|
||||||
// : }}}
|
|
||||||
|
|
||||||
// : Minor UI stuff {{{
|
|
||||||
function ClearAllMessages() {
|
function ClearAllMessages() {
|
||||||
overlay.querySelectorAll('#scriptMessage').forEach(x => x.remove())
|
overlay.querySelectorAll('#scriptMessage').forEach(x => x.remove())
|
||||||
}
|
}
|
||||||
|
@ -1927,6 +1840,70 @@
|
||||||
// : }}}
|
// : }}}
|
||||||
|
|
||||||
// : Generic utils {{{
|
// : Generic utils {{{
|
||||||
|
|
||||||
|
// : String utils 2 {{{
|
||||||
|
|
||||||
|
function removeUnnecesarySpaces(toremove) {
|
||||||
|
// TODO: check if this doesnt kill if question / answer is empty
|
||||||
|
if (!toremove) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
toremove = normalizeSpaces(toremove).replace(/\t/g, '')
|
||||||
|
while (toremove.includes(' ')) {
|
||||||
|
toremove = toremove.replace(/ {2}/g, ' ')
|
||||||
|
}
|
||||||
|
while (toremove.includes('\n\n')) {
|
||||||
|
toremove = toremove.replace(/\n{2}/g, ' ')
|
||||||
|
}
|
||||||
|
return toremove.trim()
|
||||||
|
}
|
||||||
|
|
||||||
|
function normalizeSpaces(input) {
|
||||||
|
assert(input)
|
||||||
|
|
||||||
|
return input.replace(/\s/g, ' ')
|
||||||
|
}
|
||||||
|
|
||||||
|
function emptyOrWhiteSpace(value) {
|
||||||
|
if (value === undefined) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
value
|
||||||
|
.replace(/\n/g, '')
|
||||||
|
.replace(/\t/g, '')
|
||||||
|
.replace(/ /g, '')
|
||||||
|
.replace(/\s/g, ' ') === ''
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// : }}}
|
||||||
|
|
||||||
|
const specialChars = ['&', '\\+']
|
||||||
|
|
||||||
|
const assert = val => {
|
||||||
|
if (!val) {
|
||||||
|
throw new Error('Assertion failed')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Log(value) {
|
||||||
|
if (log) {
|
||||||
|
console.log(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function Exception(e, msg) {
|
||||||
|
Log('------------------------------------------')
|
||||||
|
Log(msg)
|
||||||
|
Log(e.message)
|
||||||
|
Log('------------------------------------------')
|
||||||
|
Log(e.stack)
|
||||||
|
Log('------------------------------------------')
|
||||||
|
}
|
||||||
|
|
||||||
function GetId() {
|
function GetId() {
|
||||||
let currId = getVal('clientId')
|
let currId = getVal('clientId')
|
||||||
if (currId) {
|
if (currId) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue