mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Merge branch 'master' into devel
This commit is contained in:
commit
3ad9e897f3
1 changed files with 99 additions and 36 deletions
135
stable.user.js
135
stable.user.js
|
@ -46,31 +46,33 @@
|
||||||
// : Script header {{{
|
// : Script header {{{
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Moodle/Elearning/KMOOC test help
|
// @name Moodle/Elearning/KMOOC test help
|
||||||
// @version 2.1.3.10
|
// @version 2.1.3.15
|
||||||
// @description Online Moodle/Elearning/KMOOC test help
|
// @description Online Moodle/Elearning/KMOOC test help
|
||||||
// @author MrFry
|
// @author MrFry
|
||||||
// @match https://elearning.uni-obuda.hu/*
|
// @match https://elearning.uni-obuda.hu/*
|
||||||
// @match https://exam.elearning.uni-obuda.hu/*
|
// @match https://exam.elearning.uni-obuda.hu/*
|
||||||
|
// @match https://oktatas.mai.kvk.uni-obuda.hu/*
|
||||||
|
// @match https://portal.kgk.uni-obuda.hu/*
|
||||||
// @match https://mooc.unideb.hu/*
|
// @match https://mooc.unideb.hu/*
|
||||||
// @match https://elearning.unideb.hu/*
|
// @match https://elearning.unideb.hu/*
|
||||||
|
// @match https://elearning.med.unideb.hu/*
|
||||||
|
// @match https://exam.unideb.hu/*
|
||||||
// @match https://itc.semmelweis.hu/moodle/*
|
// @match https://itc.semmelweis.hu/moodle/*
|
||||||
// @match https://moodle.gtk.uni-pannon.hu/*
|
|
||||||
// @match https://oktatas.mai.kvk.uni-obuda.hu/*
|
|
||||||
// @match https://moodle.pte.hu/*
|
|
||||||
// @match https://szelearning.sze.hu/*
|
// @match https://szelearning.sze.hu/*
|
||||||
// @match https://moodle.kre.hu/*
|
// @match https://moodle.kre.hu/*
|
||||||
// @match https://moodle.pte.hu/*
|
// @match https://moodle.pte.hu/*
|
||||||
// @match https://portal.kgk.uni-obuda.hu/*
|
|
||||||
// @match https://elearning.uni-miskolc.hu/*
|
// @match https://elearning.uni-miskolc.hu/*
|
||||||
// @match https://elearning.uni-mate.hu/*
|
// @match https://elearning.uni-mate.hu/*
|
||||||
// @match https://edu.gpk.bme.hu/*
|
// @match https://moodle.gtk.uni-pannon.hu/*
|
||||||
// @match https://edu.gtk.bme.hu/*
|
// @match https://edu.gtk.bme.hu/*
|
||||||
|
// @match https://edu.gpk.bme.hu/*
|
||||||
// @match https://iktblog.hu/*
|
// @match https://iktblog.hu/*
|
||||||
// @match https://moodle.ms.sapientia.ro/*
|
// @match https://moodle.ms.sapientia.ro/*
|
||||||
// @match https://moodle.uni-corvinus.hu/*
|
// @match https://moodle.uni-corvinus.hu/*
|
||||||
// @match https://v39.moodle.uniduna.hu/*
|
// @match https://v39.moodle.uniduna.hu/*
|
||||||
// @noframes
|
// @match https://mentok.net/*
|
||||||
// @match https://qmining.frylabs.net/*
|
// @match https://qmining.frylabs.net/*
|
||||||
|
// @noframes
|
||||||
// @run-at document-start
|
// @run-at document-start
|
||||||
// @grant GM_getResourceText
|
// @grant GM_getResourceText
|
||||||
// @grant GM_info
|
// @grant GM_info
|
||||||
|
@ -146,6 +148,7 @@
|
||||||
var motd = ''
|
var motd = ''
|
||||||
var lastestVersion = ''
|
var lastestVersion = ''
|
||||||
var subjInfo
|
var subjInfo
|
||||||
|
var uiShowing = true
|
||||||
|
|
||||||
// array, where elems are added to shadow-root, but its position should be at target.
|
// array, where elems are added to shadow-root, but its position should be at target.
|
||||||
var updatableElements = [] // { elem: ..., target: ... }
|
var updatableElements = [] // { elem: ..., target: ... }
|
||||||
|
@ -260,6 +263,10 @@
|
||||||
if (img.title) {
|
if (img.title) {
|
||||||
promises.push({ type: 'txt', val: img.title, node: elem })
|
promises.push({ type: 'txt', val: img.title, node: elem })
|
||||||
} else {
|
} else {
|
||||||
|
const originalBase64 = img.src.startsWith('data:image/')
|
||||||
|
? img.src
|
||||||
|
: null
|
||||||
|
|
||||||
promises.push(
|
promises.push(
|
||||||
new Promise((resolve) => {
|
new Promise((resolve) => {
|
||||||
digestMessage(getBase64Image(img)).then((res) => {
|
digestMessage(getBase64Image(img)).then((res) => {
|
||||||
|
@ -267,6 +274,7 @@
|
||||||
type: 'img',
|
type: 'img',
|
||||||
val: res,
|
val: res,
|
||||||
node: img,
|
node: img,
|
||||||
|
base64: originalBase64,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -310,7 +318,11 @@
|
||||||
if (element.type === 'img') {
|
if (element.type === 'img') {
|
||||||
// FIXME: include check needed?
|
// FIXME: include check needed?
|
||||||
if (!acc.includes(element.val)) {
|
if (!acc.includes(element.val)) {
|
||||||
acc.push({ val: element.val, node: element.node })
|
acc.push({
|
||||||
|
val: element.val,
|
||||||
|
node: element.node,
|
||||||
|
base64: element.base64,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return acc
|
return acc
|
||||||
|
@ -336,7 +348,8 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog("Couldn't get images from result (old)")
|
warn(e)
|
||||||
|
warn("Couldn't get images from result (old)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -395,7 +408,7 @@
|
||||||
uid: getUid(),
|
uid: getUid(),
|
||||||
}
|
}
|
||||||
|
|
||||||
debugLog('Sent data', sentData)
|
log('Sent data', sentData)
|
||||||
post('ask', sentData).then((results) => {
|
post('ask', sentData).then((results) => {
|
||||||
removeLoadingMessage()
|
removeLoadingMessage()
|
||||||
ShowAnswers(
|
ShowAnswers(
|
||||||
|
@ -472,7 +485,13 @@
|
||||||
let questionNodes
|
let questionNodes
|
||||||
Object.keys(questionNodeVariants).some((key) => {
|
Object.keys(questionNodeVariants).some((key) => {
|
||||||
const variant = questionNodeVariants[key]
|
const variant = questionNodeVariants[key]
|
||||||
if (variant.criteria()) {
|
let criteriaPassed = false
|
||||||
|
try {
|
||||||
|
criteriaPassed = variant.criteria()
|
||||||
|
} catch (e) {
|
||||||
|
debugLog('Criteria check failed with error (question nodes)', e)
|
||||||
|
}
|
||||||
|
if (criteriaPassed) {
|
||||||
questionNodes = variant.getter()
|
questionNodes = variant.getter()
|
||||||
if (questionNodes.length === 0) {
|
if (questionNodes.length === 0) {
|
||||||
warn(
|
warn(
|
||||||
|
@ -706,7 +725,7 @@
|
||||||
...possibleAnswerArray,
|
...possibleAnswerArray,
|
||||||
])
|
])
|
||||||
const data = getDataFromTest(
|
const data = getDataFromTest(
|
||||||
node,
|
question,
|
||||||
images,
|
images,
|
||||||
getLegacyImageID(imageNodes)
|
getLegacyImageID(imageNodes)
|
||||||
)
|
)
|
||||||
|
@ -732,7 +751,7 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDataFromTest(_node, hashedImages, legacyImages) {
|
function getDataFromTest(questions, hashedImages, legacyImages) {
|
||||||
if (hashedImages.length > 0) {
|
if (hashedImages.length > 0) {
|
||||||
return {
|
return {
|
||||||
type: 'image',
|
type: 'image',
|
||||||
|
@ -740,6 +759,11 @@
|
||||||
return x.val
|
return x.val
|
||||||
}),
|
}),
|
||||||
images: legacyImages,
|
images: legacyImages,
|
||||||
|
base64: questions
|
||||||
|
.map((x) => {
|
||||||
|
return x.base64
|
||||||
|
})
|
||||||
|
.filter((x) => !!x),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
|
@ -763,7 +787,7 @@
|
||||||
try {
|
try {
|
||||||
criteriaPassed = variant.criteria()
|
criteriaPassed = variant.criteria()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog('Criteria check failed with error', e)
|
debugLog('Criteria check failed with error (result nodes)', e)
|
||||||
}
|
}
|
||||||
if (criteriaPassed) {
|
if (criteriaPassed) {
|
||||||
resultNodes = variant.getter()
|
resultNodes = variant.getter()
|
||||||
|
@ -1153,7 +1177,7 @@
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
debugLog(sentData)
|
log(sentData)
|
||||||
post('isAdding', sentData).then((res) => {
|
post('isAdding', sentData).then((res) => {
|
||||||
ShowSaveQuizDialog(res.success, sentData, res.totalNewQuestions)
|
ShowSaveQuizDialog(res.success, sentData, res.totalNewQuestions)
|
||||||
})
|
})
|
||||||
|
@ -1227,7 +1251,7 @@
|
||||||
testUrl: url,
|
testUrl: url,
|
||||||
}
|
}
|
||||||
|
|
||||||
debugLog('Sent data', sentData)
|
log('Sent data', sentData)
|
||||||
post('ask', sentData).then((results) => {
|
post('ask', sentData).then((results) => {
|
||||||
removeLoadingMessage()
|
removeLoadingMessage()
|
||||||
ShowAnswers(
|
ShowAnswers(
|
||||||
|
@ -1240,8 +1264,8 @@
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog('Error in handleAVRQuiz')
|
warn('Error in handleAVRQuiz')
|
||||||
debugLog(e)
|
warn(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1258,6 +1282,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// : }}}
|
// : }}}
|
||||||
|
|
||||||
// : Misc {{{
|
// : Misc {{{
|
||||||
|
|
||||||
function getVideo() {
|
function getVideo() {
|
||||||
|
@ -1427,9 +1452,17 @@
|
||||||
// window.addEventListener("load", () => {})
|
// window.addEventListener("load", () => {})
|
||||||
Main()
|
Main()
|
||||||
|
|
||||||
|
function preventWindowClose() {
|
||||||
|
usf.close = () => {
|
||||||
|
log('Prevented window.close() ...')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function Main() {
|
function Main() {
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
log('Moodle / E-Learning script')
|
||||||
|
preventWindowClose()
|
||||||
console.log(
|
console.log(
|
||||||
'%c Moodle / E-Learning script',
|
'%c Moodle / E-Learning script',
|
||||||
'font-weight: bold; font-size: 50px;color: yellow; text-shadow: 3px 3px 0 rgb(245,221,8) , 6px 6px 0 rgb(226,91,14) , 9px 9px 0 rgb(217,31,38) , 12px 12px 0 rgb(5,148,68) , 15px 15px 0 rgb(2,135,206) , 18px 18px 0 rgb(4,77,145) , 21px 21px 0 rgb(42,21,113)'
|
'font-weight: bold; font-size: 50px;color: yellow; text-shadow: 3px 3px 0 rgb(245,221,8) , 6px 6px 0 rgb(226,91,14) , 9px 9px 0 rgb(217,31,38) , 12px 12px 0 rgb(5,148,68) , 15px 15px 0 rgb(2,135,206) , 18px 18px 0 rgb(4,77,145) , 21px 21px 0 rgb(42,21,113)'
|
||||||
|
@ -1658,6 +1691,7 @@
|
||||||
}
|
}
|
||||||
VersionActions()
|
VersionActions()
|
||||||
if (!url.includes('.pdf')) {
|
if (!url.includes('.pdf')) {
|
||||||
|
SetupMenu()
|
||||||
ShowMenu()
|
ShowMenu()
|
||||||
}
|
}
|
||||||
ConnectToServer(AfterLoad)
|
ConnectToServer(AfterLoad)
|
||||||
|
@ -1722,6 +1756,7 @@
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
NoServerAction()
|
NoServerAction()
|
||||||
|
warn(texts.noServerConsoleMessage)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1747,7 +1782,6 @@
|
||||||
SafeGetElementById('retryContainer', (elem) => {
|
SafeGetElementById('retryContainer', (elem) => {
|
||||||
elem.style.display = 'flex'
|
elem.style.display = 'flex'
|
||||||
})
|
})
|
||||||
log(texts.noServerConsoleMessage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function VersionActions() {
|
function VersionActions() {
|
||||||
|
@ -1923,7 +1957,7 @@
|
||||||
// }
|
// }
|
||||||
// }>
|
// }>
|
||||||
function ShowAnswers(results) {
|
function ShowAnswers(results) {
|
||||||
debugLog(results)
|
log(results)
|
||||||
try {
|
try {
|
||||||
const answers = results.reduce((acc, res) => {
|
const answers = results.reduce((acc, res) => {
|
||||||
const prepared = PrepareAnswers(res)
|
const prepared = PrepareAnswers(res)
|
||||||
|
@ -1952,8 +1986,8 @@
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog('Error showing answers')
|
warn('Error showing answers')
|
||||||
debugLog(e)
|
warn(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2017,9 +2051,9 @@
|
||||||
sentData.subj = getCurrentSubjectName()
|
sentData.subj = getCurrentSubjectName()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
sentData.subj = 'NOSUBJ'
|
sentData.subj = 'NOSUBJ'
|
||||||
debugLog('unable to get subject name :c')
|
warn('unable to get subject name :c')
|
||||||
}
|
}
|
||||||
debugLog('SENT DATA', sentData)
|
log('SENT DATA', sentData)
|
||||||
post('isAdding', sentData).then((res) => {
|
post('isAdding', sentData).then((res) => {
|
||||||
ShowSaveQuizDialog(res.success, sentData, res.totalNewQuestions)
|
ShowSaveQuizDialog(res.success, sentData, res.totalNewQuestions)
|
||||||
})
|
})
|
||||||
|
@ -2077,8 +2111,8 @@
|
||||||
installSource: info().script.updateURL,
|
installSource: info().script.updateURL,
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debugLog('Unexpected error while registering script')
|
warn('Unexpected error while registering script')
|
||||||
debugLog(err)
|
warn(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2111,8 +2145,8 @@
|
||||||
video.currentTime -= seekTime
|
video.currentTime -= seekTime
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
debugLog('Hotkey error.')
|
warn('Hotkey error.')
|
||||||
debugLog(err.message)
|
warn(err.message)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
var toadd = getVideoElement()
|
var toadd = getVideoElement()
|
||||||
|
@ -2212,6 +2246,34 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ToggleUIElements() {
|
||||||
|
const newVal = uiShowing ? 'none' : ''
|
||||||
|
SafeGetElementById(
|
||||||
|
'scriptMessage',
|
||||||
|
(elem) => {
|
||||||
|
elem.style.display = newVal
|
||||||
|
},
|
||||||
|
true
|
||||||
|
)
|
||||||
|
SafeGetElementById(
|
||||||
|
'scriptMenuDiv',
|
||||||
|
(elem) => {
|
||||||
|
elem.style.display = newVal
|
||||||
|
},
|
||||||
|
true
|
||||||
|
)
|
||||||
|
uiShowing = !uiShowing
|
||||||
|
}
|
||||||
|
|
||||||
|
function SetupMenu() {
|
||||||
|
document.addEventListener('keydown', (event) => {
|
||||||
|
if (event.ctrlKey && event.key === 'h') {
|
||||||
|
event.preventDefault()
|
||||||
|
ToggleUIElements()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function ShowMessage(msgItem, timeout, funct) {
|
function ShowMessage(msgItem, timeout, funct) {
|
||||||
let isSimpleMessage = false
|
let isSimpleMessage = false
|
||||||
let simpleMessageText = ''
|
let simpleMessageText = ''
|
||||||
|
@ -2457,8 +2519,8 @@
|
||||||
|
|
||||||
result.msgContainer.child.msgDiv.elem.innerText = getCurrMsg().m
|
result.msgContainer.child.msgDiv.elem.innerText = getCurrMsg().m
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
debugLog('Error in message updating')
|
warn('Error in message updating')
|
||||||
debugLog(e)
|
warn(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateMessageText()
|
updateMessageText()
|
||||||
|
@ -2710,23 +2772,23 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logHelper(logMethod, ...value) {
|
function logHelper(logMethod, style, ...value) {
|
||||||
if (logEnabled) {
|
if (logEnabled) {
|
||||||
logMethod('[Moodle Script]: ', ...value)
|
logMethod('%c[Moodle Script]:', style, ...value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function warn(value) {
|
function warn(value) {
|
||||||
logHelper(console.warn, value)
|
logHelper(console.warn, 'color:yellow', value)
|
||||||
}
|
}
|
||||||
|
|
||||||
function log() {
|
function log() {
|
||||||
logHelper(console.log, ...arguments)
|
logHelper(console.log, 'color:green', ...arguments)
|
||||||
}
|
}
|
||||||
|
|
||||||
function debugLog() {
|
function debugLog() {
|
||||||
if (isDevel) {
|
if (isDevel) {
|
||||||
logHelper(console.log, ...arguments)
|
logHelper(console.log, 'color:grey', ...arguments)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2758,11 +2820,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function SafeGetElementById(id, next) {
|
function SafeGetElementById(id, next, silent) {
|
||||||
const element = overlay.querySelector('#' + id)
|
const element = overlay.querySelector('#' + id)
|
||||||
if (element) {
|
if (element) {
|
||||||
next(element)
|
next(element)
|
||||||
} else {
|
} else {
|
||||||
|
if (silent) return
|
||||||
log(`Unable to safe get element by id: ${id}`)
|
log(`Unable to safe get element by id: ${id}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue