mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Passive mode
This commit is contained in:
parent
65819a44b8
commit
b9beca75a2
1 changed files with 77 additions and 31 deletions
108
stable.user.js
108
stable.user.js
|
@ -89,7 +89,11 @@
|
|||
donate: 'Donate',
|
||||
search: 'Keresés ...',
|
||||
loading: 'Betöltés ...',
|
||||
noServer: 'Nem elérhető a szerver!'
|
||||
noServer: 'Nem elérhető a szerver!',
|
||||
passiveModeActivated: 'Passzív mód bekapcsolva, nem lesz mostantól a szerver piszkálva',
|
||||
passiveModeDeactivated: 'Passzív mód kikapcsolva, frissíts az érvénybe lépéshez!',
|
||||
passiveMode: 'Passzív mód',
|
||||
passiveModeMenuBoxText: 'Passzív mód aktív'
|
||||
}
|
||||
|
||||
var texts = huTexts
|
||||
|
@ -676,44 +680,52 @@
|
|||
// : }}}
|
||||
|
||||
// : Main function {{{
|
||||
let timerStarted = false
|
||||
|
||||
Main()
|
||||
function Main () {
|
||||
'use strict'
|
||||
console.time('main')
|
||||
timerStarted = true
|
||||
|
||||
Init(function () {
|
||||
var url = location.href // eslint-disable-line
|
||||
|
||||
try {
|
||||
if ((url.includes('/quiz/') && url.includes('attempt.php')) || forceTestPage) { // if the current page is a test
|
||||
HandleQuiz()
|
||||
} else if ((url.includes('/quiz/') && url.includes('review.php')) || forceResultPage) { // if the current window is a test-s result
|
||||
HandleResults(url)
|
||||
} else if ((!url.includes('/quiz/') && !url.includes('review.php') && !url.includes('.pdf')) ||
|
||||
(forceDefaultPage)) { // if the current window is any other window than a quiz or pdf.
|
||||
HandleUI(url)
|
||||
}
|
||||
} catch (e) {
|
||||
ShowMessage({
|
||||
m: texts.fatalError,
|
||||
isSimple: true
|
||||
}, undefined, () => {
|
||||
OpenErrorPage(e)
|
||||
})
|
||||
|
||||
Exception(e, 'script error at main:')
|
||||
}
|
||||
if (url.includes('eduplayer')) { AddVideoHotkeys(url) } // adding video hotkeys
|
||||
Log(texts.consoleErrorInfo)
|
||||
|
||||
console.log('Moodle Test Script run time:')
|
||||
console.timeEnd('main')
|
||||
})
|
||||
Init(AfterLoad)
|
||||
|
||||
if (forceTestPage || forceResultPage || forceDefaultPage) {
|
||||
if (document.getElementById('scriptMessage')) { document.getElementById('scriptMessage').style.background = 'green' }
|
||||
}
|
||||
}
|
||||
|
||||
function AfterLoad () {
|
||||
var url = location.href // eslint-disable-line
|
||||
|
||||
try {
|
||||
if ((url.includes('/quiz/') && url.includes('attempt.php')) || forceTestPage) { // if the current page is a test
|
||||
HandleQuiz()
|
||||
} else if ((url.includes('/quiz/') && url.includes('review.php')) || forceResultPage) { // if the current window is a test-s result
|
||||
HandleResults(url)
|
||||
} else if ((!url.includes('/quiz/') && !url.includes('review.php') && !url.includes('.pdf')) ||
|
||||
(forceDefaultPage)) { // if the current window is any other window than a quiz or pdf.
|
||||
HandleUI(url)
|
||||
}
|
||||
} catch (e) {
|
||||
ShowMessage({
|
||||
m: texts.fatalError,
|
||||
isSimple: true
|
||||
}, undefined, () => {
|
||||
OpenErrorPage(e)
|
||||
})
|
||||
|
||||
Exception(e, 'script error at main:')
|
||||
}
|
||||
if (url.includes('eduplayer')) { AddVideoHotkeys(url) } // adding video hotkeys
|
||||
Log(texts.consoleErrorInfo)
|
||||
|
||||
if (timerStarted) {
|
||||
console.log('Moodle Test Script run time:')
|
||||
console.timeEnd('main')
|
||||
timerStarted = false
|
||||
}
|
||||
}
|
||||
// : }}}
|
||||
|
||||
// : Main logic stuff {{{
|
||||
|
@ -750,6 +762,12 @@
|
|||
}
|
||||
VersionActions()
|
||||
if (!url.includes('.pdf')) { ShowMenu() }
|
||||
if (!getVal('skipLoad')) {
|
||||
ConnectToServer(cwith)
|
||||
}
|
||||
}
|
||||
|
||||
function ConnectToServer (cwith) {
|
||||
GetXHRInfos().then((inf) => {
|
||||
lastestVersion = inf.version
|
||||
motd = inf.motd
|
||||
|
@ -1468,14 +1486,16 @@
|
|||
SetStyle(donateLink, buttonStyle)
|
||||
|
||||
donateLink.addEventListener('click', function () {
|
||||
location.href = serverAdress + 'donate' // eslint-disable-line
|
||||
openInTab(serverAdress + 'donate', {
|
||||
active: true
|
||||
})
|
||||
})
|
||||
|
||||
addEventListener(window, 'resize', function () {
|
||||
menuButtonDiv.style.top = (window.innerHeight - 70) + 'px'
|
||||
})
|
||||
|
||||
// TODO: add this only after stuff loaded ( or not loaded )
|
||||
// INFO DIV ---------------------------------------------------------------------------------
|
||||
let infoDiv = CreateNodeWithText(menuButtonDiv, texts.loading, 'div')
|
||||
infoDiv.setAttribute('id', 'infoMainDiv')
|
||||
SetStyle(infoDiv, {
|
||||
|
@ -1483,6 +1503,32 @@
|
|||
margin: '5px'
|
||||
})
|
||||
|
||||
// passive button ----------------------------------------------------------------------------------------------------------------
|
||||
let passiveButton = CreateNodeWithText(buttonCell, texts.passiveMode, 'button')
|
||||
SetStyle(passiveButton, buttonStyle)
|
||||
|
||||
let setPassiveButtonState = (isPassive) => {
|
||||
if (isPassive) {
|
||||
ConnectToServer(AfterLoad)
|
||||
} else {
|
||||
infoDiv.innerText = texts.passiveModeMenuBoxText
|
||||
}
|
||||
}
|
||||
setPassiveButtonState(getVal('skipLoad'))
|
||||
|
||||
passiveButton.addEventListener('click', function () {
|
||||
let sl = getVal('skipLoad')
|
||||
setVal('skipLoad', !sl)
|
||||
setPassiveButtonState(sl)
|
||||
|
||||
if (!sl) {
|
||||
ShowMessage({
|
||||
m: texts.passiveModeActivated,
|
||||
isSimple: true
|
||||
}, 6)
|
||||
}
|
||||
})
|
||||
|
||||
appedtTo.appendChild(menuButtonDiv)
|
||||
} catch (e) {
|
||||
Exception(e, 'script error at showing menu:')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue