mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
added hotkey to hide ui elements
This commit is contained in:
parent
6f65538370
commit
5e086f461e
1 changed files with 50 additions and 18 deletions
|
@ -46,7 +46,7 @@
|
|||
// : Script header {{{
|
||||
// ==UserScript==
|
||||
// @name Moodle/Elearning/KMOOC test help
|
||||
// @version 2.1.3.13
|
||||
// @version 2.1.3.14
|
||||
// @description Online Moodle/Elearning/KMOOC test help
|
||||
// @author MrFry
|
||||
// @match https://elearning.uni-obuda.hu/*
|
||||
|
@ -70,6 +70,7 @@
|
|||
// @match https://moodle.ms.sapientia.ro/*
|
||||
// @match https://moodle.uni-corvinus.hu/*
|
||||
// @match https://v39.moodle.uniduna.hu/*
|
||||
// @match https://mentok.net/*
|
||||
// @match https://qmining.frylabs.net/*
|
||||
// @noframes
|
||||
// @run-at document-start
|
||||
|
@ -147,6 +148,7 @@
|
|||
var motd = ''
|
||||
var lastestVersion = ''
|
||||
var subjInfo
|
||||
var uiShowing = true
|
||||
|
||||
// array, where elems are added to shadow-root, but its position should be at target.
|
||||
var updatableElements = [] // { elem: ..., target: ... }
|
||||
|
@ -1465,6 +1467,21 @@
|
|||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', Init)
|
||||
} else {
|
||||
try {
|
||||
addEventListener = (function () {
|
||||
if (document.addEventListener) {
|
||||
return function (element, event, handler) {
|
||||
element.addEventListener(event, handler, false)
|
||||
}
|
||||
} else {
|
||||
return function (element, event, handler) {
|
||||
element.attachEvent('on' + event, handler)
|
||||
}
|
||||
}
|
||||
})()
|
||||
} catch (e) {
|
||||
Exception(e, 'script error at addEventListener:')
|
||||
}
|
||||
Init()
|
||||
}
|
||||
}
|
||||
|
@ -1668,23 +1685,9 @@
|
|||
return
|
||||
}
|
||||
|
||||
try {
|
||||
addEventListener = (function () {
|
||||
if (document.addEventListener) {
|
||||
return function (element, event, handler) {
|
||||
element.addEventListener(event, handler, false)
|
||||
}
|
||||
} else {
|
||||
return function (element, event, handler) {
|
||||
element.attachEvent('on' + event, handler)
|
||||
}
|
||||
}
|
||||
})()
|
||||
} catch (e) {
|
||||
Exception(e, 'script error at addEventListener:')
|
||||
}
|
||||
VersionActions()
|
||||
if (!url.includes('.pdf')) {
|
||||
SetupMenu()
|
||||
ShowMenu()
|
||||
}
|
||||
ConnectToServer(AfterLoad)
|
||||
|
@ -1749,6 +1752,7 @@
|
|||
})
|
||||
.catch(() => {
|
||||
NoServerAction()
|
||||
warn(texts.noServerConsoleMessage)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1774,7 +1778,6 @@
|
|||
SafeGetElementById('retryContainer', (elem) => {
|
||||
elem.style.display = 'flex'
|
||||
})
|
||||
warn(texts.noServerConsoleMessage)
|
||||
}
|
||||
|
||||
function VersionActions() {
|
||||
|
@ -2239,6 +2242,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) {
|
||||
let isSimpleMessage = false
|
||||
let simpleMessageText = ''
|
||||
|
@ -2785,11 +2816,12 @@
|
|||
}
|
||||
}
|
||||
|
||||
function SafeGetElementById(id, next) {
|
||||
function SafeGetElementById(id, next, silent) {
|
||||
const element = overlay.querySelector('#' + id)
|
||||
if (element) {
|
||||
next(element)
|
||||
} else {
|
||||
if (silent) return
|
||||
log(`Unable to safe get element by id: ${id}`)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue