mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
User specific motd changes (again)
This commit is contained in:
parent
76c1492b85
commit
77dbde87e8
1 changed files with 51 additions and 44 deletions
|
@ -308,19 +308,16 @@
|
||||||
// : Test page processing functions {{{
|
// : Test page processing functions {{{
|
||||||
|
|
||||||
function handleQuiz() {
|
function handleQuiz() {
|
||||||
const { removeMessage: removeLoadingMessage } = ShowMessage({
|
const { removeMessage: removeLoadingMessage } = ShowMessage(
|
||||||
m: texts.loadingAnswer,
|
texts.loadingAnswer
|
||||||
isSimple: true,
|
)
|
||||||
})
|
|
||||||
|
|
||||||
getQuizData()
|
getQuizData()
|
||||||
.then(readQuestions => {
|
.then(readQuestions => {
|
||||||
if (readQuestions.length === 0) {
|
if (readQuestions.length === 0) {
|
||||||
ShowMessage(
|
ShowMessage(
|
||||||
{
|
texts.unableToParseTestQuestion,
|
||||||
m: texts.unableToParseTestQuestion,
|
|
||||||
isSimple: true,
|
|
||||||
},
|
|
||||||
undefined,
|
undefined,
|
||||||
() => {
|
() => {
|
||||||
OpenErrorPage({
|
OpenErrorPage({
|
||||||
|
@ -1003,10 +1000,8 @@
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
ShowMessage(
|
ShowMessage(
|
||||||
{
|
texts.fatalError,
|
||||||
m: texts.fatalError,
|
|
||||||
isSimple: true,
|
|
||||||
},
|
|
||||||
undefined,
|
undefined,
|
||||||
() => {
|
() => {
|
||||||
OpenErrorPage(e)
|
OpenErrorPage(e)
|
||||||
|
@ -1104,7 +1099,7 @@
|
||||||
post('login', { pw: pw, script: true }).then(res => {
|
post('login', { pw: pw, script: true }).then(res => {
|
||||||
if (res.result === 'success') {
|
if (res.result === 'success') {
|
||||||
ConnectToServer(AfterLoad)
|
ConnectToServer(AfterLoad)
|
||||||
ClearAllMessages()
|
clearAllMessages()
|
||||||
resetMenu()
|
resetMenu()
|
||||||
} else {
|
} else {
|
||||||
SafeGetElementById('infoMainDiv', elem => {
|
SafeGetElementById('infoMainDiv', elem => {
|
||||||
|
@ -1133,7 +1128,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function ConnectToServer(cwith) {
|
function ConnectToServer(cwith) {
|
||||||
ClearAllMessages()
|
clearAllMessages()
|
||||||
GetXHRInfos()
|
GetXHRInfos()
|
||||||
.then(inf => {
|
.then(inf => {
|
||||||
if (inf.result === 'nouser') {
|
if (inf.result === 'nouser') {
|
||||||
|
@ -1145,12 +1140,13 @@
|
||||||
if (getUid() !== inf.uid) {
|
if (getUid() !== inf.uid) {
|
||||||
setVal('userId', inf.uid)
|
setVal('userId', inf.uid)
|
||||||
}
|
}
|
||||||
userSpecificMotd = {
|
userSpecificMotd = inf.userSpecificMotd
|
||||||
show: inf.userShouldGetUserSpecificMOTD,
|
|
||||||
text: inf.userSpecificMotd,
|
|
||||||
}
|
|
||||||
subjInfo = inf.subjinfo
|
subjInfo = inf.subjinfo
|
||||||
setVal('userId', inf.uid)
|
setVal('userId', inf.uid)
|
||||||
|
|
||||||
|
overlay.querySelector('#mailButton').innerText = userSpecificMotd.seen
|
||||||
|
? '📭'
|
||||||
|
: '📬'
|
||||||
overlay.querySelector('#infoMainDiv').innerText = `${
|
overlay.querySelector('#infoMainDiv').innerText = `${
|
||||||
subjInfo.subjects
|
subjInfo.subjects
|
||||||
} tárgy, ${subjInfo.questions} kérdés. User ID: ${getUid()}`
|
} tárgy, ${subjInfo.questions} kérdés. User ID: ${getUid()}`
|
||||||
|
@ -1227,14 +1223,13 @@
|
||||||
function HandleUI(url) {
|
function HandleUI(url) {
|
||||||
const newVersion = info().script.version !== getVal('lastVerson')
|
const newVersion = info().script.version !== getVal('lastVerson')
|
||||||
const showMOTD = shouldShowMotd()
|
const showMOTD = shouldShowMotd()
|
||||||
const showUserSpecificMOTD = userSpecificMotd.show
|
|
||||||
const isNewVersionAvaible =
|
const isNewVersionAvaible =
|
||||||
lastestVersion !== undefined && info().script.version !== lastestVersion
|
lastestVersion !== undefined && info().script.version !== lastestVersion
|
||||||
|
|
||||||
let timeout = null
|
let timeout = null
|
||||||
const greetMsg = []
|
const greetMsg = []
|
||||||
|
|
||||||
if (isNewVersionAvaible || newVersion || showMOTD || showUserSpecificMOTD) {
|
if (isNewVersionAvaible || newVersion || showMOTD) {
|
||||||
greetMsg.push(texts.scriptName + info().script.version)
|
greetMsg.push(texts.scriptName + info().script.version)
|
||||||
}
|
}
|
||||||
if (isNewVersionAvaible) {
|
if (isNewVersionAvaible) {
|
||||||
|
@ -1253,16 +1248,10 @@
|
||||||
greetMsg.push(texts.motd + motd)
|
greetMsg.push(texts.motd + motd)
|
||||||
timeout = null
|
timeout = null
|
||||||
}
|
}
|
||||||
if (showUserSpecificMOTD) {
|
|
||||||
greetMsg.push(texts.userMOTD + userSpecificMotd.text)
|
|
||||||
timeout = null
|
|
||||||
}
|
|
||||||
|
|
||||||
ShowMessage(
|
ShowMessage(
|
||||||
{
|
greetMsg.join('\n'),
|
||||||
m: greetMsg.join('\n'),
|
|
||||||
isSimple: true,
|
|
||||||
},
|
|
||||||
timeout
|
timeout
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1328,10 +1317,8 @@
|
||||||
ShowMessage(answers)
|
ShowMessage(answers)
|
||||||
} else {
|
} else {
|
||||||
ShowMessage(
|
ShowMessage(
|
||||||
{
|
texts.noResult,
|
||||||
m: texts.noResult,
|
|
||||||
isSimple: true,
|
|
||||||
},
|
|
||||||
undefined,
|
undefined,
|
||||||
function() {
|
function() {
|
||||||
OpenErrorPage({
|
OpenErrorPage({
|
||||||
|
@ -1370,10 +1357,8 @@
|
||||||
}
|
}
|
||||||
// showing a message wit the click event, and the generated page
|
// showing a message wit the click event, and the generated page
|
||||||
ShowMessage(
|
ShowMessage(
|
||||||
{
|
msg,
|
||||||
m: msg,
|
|
||||||
isSimple: true,
|
|
||||||
},
|
|
||||||
null,
|
null,
|
||||||
function() {
|
function() {
|
||||||
let towrite = ''
|
let towrite = ''
|
||||||
|
@ -1393,10 +1378,7 @@
|
||||||
try {
|
try {
|
||||||
let sentData = {}
|
let sentData = {}
|
||||||
if (quiz.length === 0) {
|
if (quiz.length === 0) {
|
||||||
ShowMessage({
|
ShowMessage(texts.noParseableQuestionResult)
|
||||||
m: texts.noParseableQuestionResult,
|
|
||||||
isSimple: true,
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
@ -1530,7 +1512,7 @@
|
||||||
|
|
||||||
// : Show message, and script menu stuff {{{
|
// : Show message, and script menu stuff {{{
|
||||||
|
|
||||||
function ClearAllMessages() {
|
function clearAllMessages() {
|
||||||
overlay.querySelectorAll('#scriptMessage').forEach(x => x.remove())
|
overlay.querySelectorAll('#scriptMessage').forEach(x => x.remove())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1599,9 +1581,8 @@
|
||||||
let defMargin = '0px 5px'
|
let defMargin = '0px 5px'
|
||||||
let isSimpleMessage = false
|
let isSimpleMessage = false
|
||||||
let simpleMessageText = ''
|
let simpleMessageText = ''
|
||||||
if (msgItem.isSimple) {
|
if (typeof msgItem === 'string') {
|
||||||
// parsing msgItem for easier use
|
simpleMessageText = msgItem
|
||||||
simpleMessageText = msgItem.m
|
|
||||||
if (simpleMessageText === '') {
|
if (simpleMessageText === '') {
|
||||||
// if msg is empty
|
// if msg is empty
|
||||||
return
|
return
|
||||||
|
@ -1985,6 +1966,32 @@
|
||||||
menuButtonDiv.parentNode.removeChild(menuButtonDiv)
|
menuButtonDiv.parentNode.removeChild(menuButtonDiv)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const mailButton = CreateNodeWithText(menuButtonDiv, '📭', 'div')
|
||||||
|
mailButton.setAttribute('id', 'mailButton')
|
||||||
|
SetStyle(mailButton, {
|
||||||
|
fontSize: '30px',
|
||||||
|
cursor: 'pointer',
|
||||||
|
position: 'absolute',
|
||||||
|
left: '0px',
|
||||||
|
bottom: '0px',
|
||||||
|
display: 'inline',
|
||||||
|
margin: '5px',
|
||||||
|
})
|
||||||
|
mailButton.addEventListener('mousedown', e => {
|
||||||
|
e.stopPropagation()
|
||||||
|
if (!userSpecificMotd.seen) {
|
||||||
|
mailButton.innerText = '📭'
|
||||||
|
clearAllMessages()
|
||||||
|
ShowMessage(
|
||||||
|
'Üzenet oldal készítéjétől (csak te látod):\n' +
|
||||||
|
userSpecificMotd.msg
|
||||||
|
)
|
||||||
|
post('infos', {
|
||||||
|
userSpecificMotdSeen: true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
var tbl = document.createElement('table')
|
var tbl = document.createElement('table')
|
||||||
tbl.style.margin = '5px 5px 5px 5px'
|
tbl.style.margin = '5px 5px 5px 5px'
|
||||||
tbl.style.textAlign = 'left'
|
tbl.style.textAlign = 'left'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue