mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Opacity change of script messages on mouse scroll
This commit is contained in:
parent
50b6b93a46
commit
dea0b115b7
1 changed files with 56 additions and 24 deletions
|
@ -88,7 +88,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!
|
||||||
setVal('ISDEVEL', true)
|
setVal('ISDEVEL', true)
|
||||||
// only one of these should be true for testing
|
// only one of these should be true for testing
|
||||||
const forceTestPage = true
|
const forceTestPage = false
|
||||||
const forceResultPage = false
|
const forceResultPage = false
|
||||||
const forceDefaultPage = false
|
const forceDefaultPage = false
|
||||||
|
|
||||||
|
@ -100,6 +100,8 @@
|
||||||
'https://qmining.frylabs.net/moodle-test-userscript/stable.user.js?up'
|
'https://qmining.frylabs.net/moodle-test-userscript/stable.user.js?up'
|
||||||
|
|
||||||
const motdShowCount = 3 /* Ammount of times to show motd */
|
const motdShowCount = 3 /* Ammount of times to show motd */
|
||||||
|
const messageOpacityDelta = 0.1
|
||||||
|
const minMessageOpacity = 0.2
|
||||||
let infoExpireTime = 60 // Every n seconds basic info should be loaded from server
|
let infoExpireTime = 60 // Every n seconds basic info should be loaded from server
|
||||||
var uid = 0
|
var uid = 0
|
||||||
var cid = 0
|
var cid = 0
|
||||||
|
@ -1495,6 +1497,29 @@
|
||||||
return resultNode
|
return resultNode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addOpacityChangeEvent(elem) {
|
||||||
|
if (!elem.id) {
|
||||||
|
console.warn('element must have ID to add opacity change event!')
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let currOpacity = getVal(`${elem.id}_opacity`)
|
||||||
|
elem.addEventListener('mousewheel', e => {
|
||||||
|
const isUp = e.deltaY < 0
|
||||||
|
if (isUp) {
|
||||||
|
if (currOpacity + messageOpacityDelta <= 1) {
|
||||||
|
currOpacity = currOpacity + messageOpacityDelta
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (currOpacity - messageOpacityDelta > minMessageOpacity) {
|
||||||
|
currOpacity = currOpacity - messageOpacityDelta
|
||||||
|
}
|
||||||
|
}
|
||||||
|
elem.style.opacity = currOpacity
|
||||||
|
setVal(`${elem.id}_opacity`, currOpacity)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// shows a message with "msg" text, "matchPercent" tip and transp, and "timeout" time
|
// shows a message with "msg" text, "matchPercent" tip and transp, and "timeout" time
|
||||||
function ShowMessage(msgItem, timeout, funct) {
|
function ShowMessage(msgItem, timeout, funct) {
|
||||||
// msgItem help:
|
// msgItem help:
|
||||||
|
@ -1504,9 +1529,9 @@
|
||||||
// msgItem[][].p <- a questions precent
|
// msgItem[][].p <- a questions precent
|
||||||
// msgItem[][].m <- a questions message
|
// msgItem[][].m <- a questions message
|
||||||
try {
|
try {
|
||||||
var defMargin = '0px 5px'
|
let defMargin = '0px 5px'
|
||||||
var isSimpleMessage = false
|
let isSimpleMessage = false
|
||||||
var simpleMessageText = ''
|
let simpleMessageText = ''
|
||||||
if (msgItem.isSimple) {
|
if (msgItem.isSimple) {
|
||||||
// parsing msgItem for easier use
|
// parsing msgItem for easier use
|
||||||
simpleMessageText = msgItem.m
|
simpleMessageText = msgItem.m
|
||||||
|
@ -1524,12 +1549,13 @@
|
||||||
isSimpleMessage = true
|
isSimpleMessage = true
|
||||||
}
|
}
|
||||||
|
|
||||||
var appedtTo = overlay // will be appended here
|
const appedtTo = overlay // will be appended here
|
||||||
var width = window.innerWidth - window.innerWidth / 6 // with of the box
|
const startFromTop = 25 // top distance
|
||||||
var startFromTop = 25 // top distance
|
let width = window.innerWidth - window.innerWidth / 6 // with of the box
|
||||||
|
|
||||||
var mainDiv = document.createElement('div') // the main divider, wich items will be attached to
|
const mainDiv = document.createElement('div') // the main divider, wich items will be attached to
|
||||||
mainDiv.setAttribute('id', 'messageMainDiv')
|
const id = 'scriptMessage'
|
||||||
|
mainDiv.setAttribute('id', id)
|
||||||
if (funct) {
|
if (funct) {
|
||||||
addEventListener(mainDiv, 'click', funct)
|
addEventListener(mainDiv, 'click', funct)
|
||||||
}
|
}
|
||||||
|
@ -1546,10 +1572,14 @@
|
||||||
borderRadius: '5px',
|
borderRadius: '5px',
|
||||||
top: startFromTop + 'px',
|
top: startFromTop + 'px',
|
||||||
left: (window.innerWidth - width) / 2 + 'px',
|
left: (window.innerWidth - width) / 2 + 'px',
|
||||||
opacity: '1',
|
opacity: getVal(`${id}_opacity`),
|
||||||
cursor: funct ? 'pointer' : 'move',
|
cursor: funct ? 'pointer' : 'move',
|
||||||
})
|
})
|
||||||
mainDiv.setAttribute('id', 'scriptMessage')
|
|
||||||
|
// ------------------------------------------------------------------
|
||||||
|
// transparencity
|
||||||
|
// ------------------------------------------------------------------
|
||||||
|
addOpacityChangeEvent(mainDiv)
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
// moving msg
|
// moving msg
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
|
@ -1837,27 +1867,24 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} catch (e) {
|
|
||||||
Exception(e, 'script error at showing message:')
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
messageElement: mainDiv,
|
messageElement: mainDiv,
|
||||||
removeMessage: () => {
|
removeMessage: () => {
|
||||||
mainDiv.parentNode.removeChild(mainDiv)
|
mainDiv.parentNode.removeChild(mainDiv)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
} catch (e) {
|
||||||
|
Exception(e, 'script error at showing message:')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// shows a fancy menu
|
// shows a fancy menu
|
||||||
function ShowMenu() {
|
function ShowMenu() {
|
||||||
try {
|
try {
|
||||||
var appedtTo = overlay // will be appended here
|
const appedtTo = overlay // will be appended here
|
||||||
|
const menuButtonDiv = document.createElement('div')
|
||||||
// mainDiv.style.left = (window.innerWidth - width) / 2 + 'px';
|
const id = 'menuButtonDiv'
|
||||||
|
menuButtonDiv.setAttribute('id', id)
|
||||||
var menuButtonDiv = document.createElement('div')
|
|
||||||
menuButtonDiv.setAttribute('id', 'menuButtonDiv')
|
|
||||||
SetStyle(menuButtonDiv, {
|
SetStyle(menuButtonDiv, {
|
||||||
width: '600px',
|
width: '600px',
|
||||||
// height: buttonHeight + 'px',
|
// height: buttonHeight + 'px',
|
||||||
|
@ -1871,7 +1898,12 @@
|
||||||
background: '#262626',
|
background: '#262626',
|
||||||
border: '3px solid #99f',
|
border: '3px solid #99f',
|
||||||
borderRadius: '5px',
|
borderRadius: '5px',
|
||||||
|
opacity: getVal(`${id}_opacity`),
|
||||||
})
|
})
|
||||||
|
// ------------------------------------------------------------------
|
||||||
|
// transparencity
|
||||||
|
// ------------------------------------------------------------------
|
||||||
|
addOpacityChangeEvent(menuButtonDiv)
|
||||||
|
|
||||||
const xButton = CreateNodeWithText(menuButtonDiv, '❌', 'div')
|
const xButton = CreateNodeWithText(menuButtonDiv, '❌', 'div')
|
||||||
SetStyle(xButton, {
|
SetStyle(xButton, {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue