mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Moving overlay elements to target every seconds, so it wont slip
This commit is contained in:
parent
00d24c8b46
commit
3cc6a915db
1 changed files with 29 additions and 15 deletions
|
@ -101,6 +101,11 @@
|
||||||
var lastestVersion = ''
|
var lastestVersion = ''
|
||||||
var subjInfo
|
var subjInfo
|
||||||
|
|
||||||
|
// array, where elems are added to shadow-root, but its position should be at target.
|
||||||
|
var updatableElements = [] // { elem: ..., target: ... }
|
||||||
|
var elementUpdaterInterval = -1
|
||||||
|
const overlayElemUpdateInterval = 2 // seconds
|
||||||
|
|
||||||
if (getVal('ISDEVEL')) {
|
if (getVal('ISDEVEL')) {
|
||||||
console.log('Moodle script running in developement mode!')
|
console.log('Moodle script running in developement mode!')
|
||||||
infoExpireTime = 1
|
infoExpireTime = 1
|
||||||
|
@ -362,15 +367,21 @@
|
||||||
overlay.appendChild(toAppend)
|
overlay.appendChild(toAppend)
|
||||||
}
|
}
|
||||||
|
|
||||||
function createHoverOver(target) {
|
function createHoverOver(appendTo) {
|
||||||
const overlayElement = document.createElement('div')
|
const overlayElement = document.createElement('div')
|
||||||
overlay.append(overlayElement)
|
overlay.append(overlayElement)
|
||||||
|
|
||||||
|
updatableElements.push({ elem: overlayElement, target: appendTo })
|
||||||
|
|
||||||
|
if (elementUpdaterInterval === -1) {
|
||||||
|
elementUpdaterInterval = setInterval(() => {
|
||||||
|
updatableElements.forEach(({ elem, target }) => {
|
||||||
let currX, currY, currWidth, currHeight
|
let currX, currY, currWidth, currHeight
|
||||||
let { left, top, width, height } = target.getBoundingClientRect()
|
let { left, top, width, height } = target.getBoundingClientRect()
|
||||||
left += window.scrollX
|
left += window.scrollX
|
||||||
top += window.scrollY
|
top += window.scrollY
|
||||||
|
|
||||||
SetStyle(overlayElement, {
|
SetStyle(elem, {
|
||||||
pointerEvents: 'none',
|
pointerEvents: 'none',
|
||||||
userSelect: 'none',
|
userSelect: 'none',
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
@ -380,6 +391,9 @@
|
||||||
width: width + 'px',
|
width: width + 'px',
|
||||||
height: height - 10 + 'px',
|
height: height - 10 + 'px',
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
}, overlayElemUpdateInterval * 1000)
|
||||||
|
}
|
||||||
|
|
||||||
return overlayElement
|
return overlayElement
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue