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 {{{
|
// : Script header {{{
|
||||||
// ==UserScript==
|
// ==UserScript==
|
||||||
// @name Moodle/Elearning/KMOOC test help
|
// @name Moodle/Elearning/KMOOC test help
|
||||||
// @version 2.1.3.13
|
// @version 2.1.3.14
|
||||||
// @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/*
|
||||||
|
@ -70,6 +70,7 @@
|
||||||
// @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/*
|
||||||
|
// @match https://mentok.net/*
|
||||||
// @match https://qmining.frylabs.net/*
|
// @match https://qmining.frylabs.net/*
|
||||||
// @noframes
|
// @noframes
|
||||||
// @run-at document-start
|
// @run-at document-start
|
||||||
|
@ -147,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: ... }
|
||||||
|
@ -1465,6 +1467,21 @@
|
||||||
if (document.readyState === 'loading') {
|
if (document.readyState === 'loading') {
|
||||||
document.addEventListener('DOMContentLoaded', Init)
|
document.addEventListener('DOMContentLoaded', Init)
|
||||||
} else {
|
} 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()
|
Init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1668,23 +1685,9 @@
|
||||||
return
|
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()
|
VersionActions()
|
||||||
if (!url.includes('.pdf')) {
|
if (!url.includes('.pdf')) {
|
||||||
|
SetupMenu()
|
||||||
ShowMenu()
|
ShowMenu()
|
||||||
}
|
}
|
||||||
ConnectToServer(AfterLoad)
|
ConnectToServer(AfterLoad)
|
||||||
|
@ -1749,6 +1752,7 @@
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
NoServerAction()
|
NoServerAction()
|
||||||
|
warn(texts.noServerConsoleMessage)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1774,7 +1778,6 @@
|
||||||
SafeGetElementById('retryContainer', (elem) => {
|
SafeGetElementById('retryContainer', (elem) => {
|
||||||
elem.style.display = 'flex'
|
elem.style.display = 'flex'
|
||||||
})
|
})
|
||||||
warn(texts.noServerConsoleMessage)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function VersionActions() {
|
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) {
|
function ShowMessage(msgItem, timeout, funct) {
|
||||||
let isSimpleMessage = false
|
let isSimpleMessage = false
|
||||||
let simpleMessageText = ''
|
let simpleMessageText = ''
|
||||||
|
@ -2785,11 +2816,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