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
259
stable.user.js
259
stable.user.js
|
@ -1,3 +1,4 @@
|
|||
// vim:foldmethod=marker
|
||||
/* ----------------------------------------------------------------------------
|
||||
|
||||
Online Moodle/Elearning/KMOOC test help
|
||||
|
@ -21,7 +22,7 @@
|
|||
|
||||
// ==UserScript==
|
||||
// @name Moodle/Elearning/KMOOC test help
|
||||
// @version 2.0.1.21
|
||||
// @version 2.1.0.0
|
||||
// @description Online Moodle/Elearning/KMOOC test help
|
||||
// @author MrFry
|
||||
// @match https://elearning.uni-obuda.hu/main/*
|
||||
|
@ -46,12 +47,10 @@
|
|||
// @namespace https://qmining.frylabs.net
|
||||
// @updateURL https://qmining.frylabs.net/moodle-test-userscript/stable.user.js?up
|
||||
// ==/UserScript==
|
||||
//
|
||||
// TODO:
|
||||
// grabboxes test on quiz page
|
||||
|
||||
// TODO: test if this ; does not fuck up things (it seams it does not)
|
||||
;(function() {
|
||||
// : ESLINT bs {{{
|
||||
|
||||
// eslint-disable-line
|
||||
// GM functions, only to disable ESLINT errors
|
||||
/* eslint-disable */
|
||||
|
@ -77,6 +76,10 @@
|
|||
}
|
||||
/* eslint-enable */
|
||||
|
||||
// : }}}
|
||||
|
||||
// : Constants and global variables {{{
|
||||
|
||||
var addEventListener // add event listener function
|
||||
let serverAdress = 'https://qmining.frylabs.net/'
|
||||
let apiAdress = 'https://api.frylabs.net/'
|
||||
|
@ -113,6 +116,8 @@
|
|||
apiAdress = 'http://localhost:8080/'
|
||||
}
|
||||
|
||||
// : Localisation {{{
|
||||
|
||||
const huTexts = {
|
||||
lastChangeLog: '',
|
||||
fatalError:
|
||||
|
@ -150,18 +155,13 @@
|
|||
|
||||
var texts = huTexts
|
||||
|
||||
// : question-classes {{{
|
||||
const specialChars = ['&', '\\+']
|
||||
// : }}}
|
||||
|
||||
const assert = val => {
|
||||
if (!val) {
|
||||
throw new Error('Assertion failed')
|
||||
}
|
||||
}
|
||||
// : }}}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
// Basic processing helpers
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
// : HTML parsers {{{
|
||||
|
||||
// : Basic processing helpers {{{
|
||||
|
||||
function getTextPromisesFromNode(node) {
|
||||
const promises = []
|
||||
|
@ -218,9 +218,9 @@
|
|||
return [...new Set(a)]
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
// Test page processing functions
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
// : }}}
|
||||
|
||||
// : Test page processing functions {{{
|
||||
|
||||
function handleQuiz() {
|
||||
getQuizData().then(res => {
|
||||
|
@ -366,9 +366,9 @@
|
|||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
// Result page processing functions
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
// : }}}
|
||||
|
||||
// : Result page processing functions {{{
|
||||
|
||||
function getQuiz() {
|
||||
return new Promise(resolve => {
|
||||
|
@ -383,13 +383,6 @@
|
|||
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)
|
||||
.then(result => {
|
||||
resolve(result)
|
||||
|
@ -608,55 +601,30 @@
|
|||
return dataURL.replace(/^data:image\/(png|jpg);base64,/, '')
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
// String utils 2
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
// : }}}
|
||||
|
||||
function removeUnnecesarySpaces(toremove) {
|
||||
// TODO: check if this doesnt kill if question / answer is empty
|
||||
if (!toremove) {
|
||||
return ''
|
||||
}
|
||||
// : Misc {{{
|
||||
|
||||
toremove = normalizeSpaces(toremove).replace(/\t/g, '')
|
||||
while (toremove.includes(' ')) {
|
||||
toremove = toremove.replace(/ {2}/g, ' ')
|
||||
function getVideo() {
|
||||
if (logElementGetting) {
|
||||
Log('getting video stuff')
|
||||
}
|
||||
while (toremove.includes('\n\n')) {
|
||||
toremove = toremove.replace(/\n{2}/g, ' ')
|
||||
}
|
||||
return toremove.trim()
|
||||
return document.getElementsByTagName('video')[0]
|
||||
}
|
||||
|
||||
function normalizeSpaces(input) {
|
||||
assert(input)
|
||||
|
||||
return input.replace(/\s/g, ' ')
|
||||
}
|
||||
|
||||
function emptyOrWhiteSpace(value) {
|
||||
if (value === undefined) {
|
||||
return true
|
||||
function getVideoElement() {
|
||||
if (logElementGetting) {
|
||||
Log('getting video element')
|
||||
}
|
||||
|
||||
return (
|
||||
value
|
||||
.replace(/\n/g, '')
|
||||
.replace(/\t/g, '')
|
||||
.replace(/ /g, '')
|
||||
.replace(/\s/g, ' ') === ''
|
||||
)
|
||||
return document.getElementById('videoElement').parentNode
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
|
||||
// : }}}
|
||||
|
||||
// : 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() {
|
||||
//call this before the document scripts
|
||||
const document = window.document
|
||||
|
@ -748,21 +716,6 @@
|
|||
|
||||
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) {
|
||||
const overlayElement = document.createElement('div')
|
||||
overlay.append(overlayElement)
|
||||
|
@ -794,29 +747,27 @@
|
|||
return overlayElement
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
// Misc
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
function appendBelowElement(el, toAppend) {
|
||||
const rect = el.getBoundingClientRect()
|
||||
const left = rect.left + window.scrollX
|
||||
const top = rect.top + window.scrollY
|
||||
|
||||
function getVideo() {
|
||||
if (logElementGetting) {
|
||||
Log('getting video stuff')
|
||||
}
|
||||
return document.getElementsByTagName('video')[0]
|
||||
SetStyle(toAppend, {
|
||||
position: 'absolute',
|
||||
zIndex: 999999,
|
||||
top: top + 'px',
|
||||
left: left + 'px',
|
||||
})
|
||||
|
||||
overlay.appendChild(toAppend)
|
||||
}
|
||||
|
||||
function getVideoElement() {
|
||||
if (logElementGetting) {
|
||||
Log('getting video element')
|
||||
}
|
||||
return document.getElementById('videoElement').parentNode
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------------
|
||||
|
||||
// : }}}
|
||||
|
||||
// : Main logic stuff {{{
|
||||
|
||||
// : Main function {{{
|
||||
|
||||
let timerStarted = false
|
||||
|
||||
// window.addEventListener("load", () => {})
|
||||
|
@ -893,8 +844,6 @@
|
|||
}
|
||||
// : }}}
|
||||
|
||||
// : Main logic stuff {{{
|
||||
|
||||
// : Loading {{{
|
||||
function HandleQminingSite(url) {
|
||||
try {
|
||||
|
@ -1065,6 +1014,8 @@
|
|||
FreshStart()
|
||||
}
|
||||
|
||||
// : }}}
|
||||
|
||||
// : Version action functions {{{
|
||||
|
||||
function FreshStart() {
|
||||
|
@ -1285,7 +1236,7 @@
|
|||
|
||||
// : }}}
|
||||
|
||||
// : Helpers {{{
|
||||
// : Video hotkey stuff {{{
|
||||
|
||||
// this function adds basic hotkeys for video controll.
|
||||
function AddVideoHotkeys(url) {
|
||||
|
@ -1321,50 +1272,12 @@
|
|||
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) {
|
||||
if (log) {
|
||||
console.log(value)
|
||||
}
|
||||
}
|
||||
// : Show message, and script menu stuff {{{
|
||||
|
||||
function Exception(e, msg) {
|
||||
Log('------------------------------------------')
|
||||
Log(msg)
|
||||
Log(e.message)
|
||||
Log('------------------------------------------')
|
||||
Log(e.stack)
|
||||
Log('------------------------------------------')
|
||||
}
|
||||
|
||||
// : }}}
|
||||
|
||||
// : Minor UI stuff {{{
|
||||
function ClearAllMessages() {
|
||||
overlay.querySelectorAll('#scriptMessage').forEach(x => x.remove())
|
||||
}
|
||||
|
@ -1927,6 +1840,70 @@
|
|||
// : }}}
|
||||
|
||||
// : 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() {
|
||||
let currId = getVal('clientId')
|
||||
if (currId) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue