Answer highlight changes

This commit is contained in:
mrfry 2020-10-21 14:47:18 +02:00
parent 96483c4b69
commit 0a7ccf2398

View file

@ -50,7 +50,7 @@
// TODO: // TODO:
// grabboxes test on quiz page // grabboxes test on quiz page
// TODO: test if this ; does not fuck up things // TODO: test if this ; does not fuck up things (it seams it does not)
;(function() { ;(function() {
// eslint-disable-line // eslint-disable-line
// GM functions, only to disable ESLINT errors // GM functions, only to disable ESLINT errors
@ -84,7 +84,7 @@
// forcing pages for testing. unless you test, do not set these to true! // forcing pages for testing. unless you test, do not set these to true!
// only one of these should be true for testing // only one of these should be true for testing
const forceTestPage = true // TODO: remove const forceTestPage = false
const forceResultPage = false const forceResultPage = false
const forceDefaultPage = false const forceDefaultPage = false
const logElementGetting = false const logElementGetting = false
@ -96,7 +96,7 @@
var lastestVersion = '' var lastestVersion = ''
var subjInfo var subjInfo
setVal('ISDEVEL', true) // TODO: remove // setVal('ISDEVEL', true)
if (getVal('ISDEVEL')) { if (getVal('ISDEVEL')) {
console.log('Moodle script running in developement mode!') console.log('Moodle script running in developement mode!')
@ -351,35 +351,23 @@
function createHoverOver(target) { function createHoverOver(target) {
const overlayElement = document.createElement('div') const overlayElement = document.createElement('div')
overlayElement.style.cssText =
'position:fixed; pointer-events: none; user-select: none; z-index:10000'
overlay.append(overlayElement) overlay.append(overlayElement)
let currX, currY, currWidth, currHeight let currX, currY, currWidth, currHeight
const copyBoundingRect = () => { let { left, top, width, height } = target.getBoundingClientRect()
let { x, y, width, height } = target.getBoundingClientRect() left += window.scrollX
if (x !== currX) { top += window.scrollY
overlayElement.style.left = x + 'px'
currX = x SetStyle(overlayElement, {
} pointerEvents: 'none',
if (y !== currY) { userSelect: 'none',
overlayElement.style.top = y + 'px' position: 'absolute',
currY = y zIndex: 999999,
} top: top + 'px',
if (width !== currWidth) { left: left + 'px',
overlayElement.style.width = width + 'px' width: width + 'px',
currWidth = width height: height - 10 + 'px',
} })
if (height !== currHeight) {
overlayElement.style.height = height + 'px'
currHeight = height
}
}
copyBoundingRect()
const interval = setInterval(copyBoundingRect, 30)
overlayElement.destroy = () => {
clearInterval(interval)
overlayElement.remove()
}
return overlayElement return overlayElement
} }
@ -1697,9 +1685,8 @@
// going through "toColor" // going through "toColor"
let highlight = createHoverOver(answers[toColor[i]]) let highlight = createHoverOver(answers[toColor[i]])
Object.assign(highlight.style, { Object.assign(highlight.style, {
border: '7px solid rgba(100, 240, 100, 0.8)', border: '4px solid rgba(100, 240, 100, 0.8)',
borderRadius: '10px', borderRadius: '10px',
margin: '-13px 0 0 -8px',
}) })
} }
} }