mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
removed user specific motd, added hasnewmsg check
This commit is contained in:
parent
2f4786987d
commit
d213f2516b
1 changed files with 40 additions and 47 deletions
|
@ -120,7 +120,7 @@
|
||||||
const forcedMatchString = isDevel ? 'default' : null
|
const forcedMatchString = isDevel ? 'default' : null
|
||||||
// only one of these should be true for testing
|
// only one of these should be true for testing
|
||||||
const forceTestPage = isDevel && false
|
const forceTestPage = isDevel && false
|
||||||
const forceResultPage = isDevel && false
|
const forceResultPage = isDevel && true
|
||||||
const forceDefaultPage = isDevel && false
|
const forceDefaultPage = isDevel && false
|
||||||
// ------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
@ -137,7 +137,6 @@
|
||||||
const minMessageOpacity = 0.2
|
const minMessageOpacity = 0.2
|
||||||
let infoExpireTime = 60 * 5 // Every n seconds basic info should be loaded from server
|
let infoExpireTime = 60 * 5 // Every n seconds basic info should be loaded from server
|
||||||
var motd = ''
|
var motd = ''
|
||||||
var userSpecificMotd = undefined
|
|
||||||
var lastestVersion = ''
|
var lastestVersion = ''
|
||||||
var subjInfo
|
var subjInfo
|
||||||
|
|
||||||
|
@ -1650,13 +1649,6 @@
|
||||||
}
|
}
|
||||||
subjInfo = inf.subjinfo
|
subjInfo = inf.subjinfo
|
||||||
setVal('userId', inf.uid)
|
setVal('userId', inf.uid)
|
||||||
userSpecificMotd = inf.userSpecificMotd
|
|
||||||
if (userSpecificMotd) {
|
|
||||||
overlay.querySelector('#mailButton').style.cursor = 'pointer'
|
|
||||||
overlay.querySelector('#mailButton').innerText = userSpecificMotd.seen
|
|
||||||
? '📭'
|
|
||||||
: '📬'
|
|
||||||
}
|
|
||||||
overlay.querySelector(
|
overlay.querySelector(
|
||||||
'#infoMainDiv'
|
'#infoMainDiv'
|
||||||
).innerText = `${subjInfo.subjects.toLocaleString(
|
).innerText = `${subjInfo.subjects.toLocaleString(
|
||||||
|
@ -1664,6 +1656,9 @@
|
||||||
)} tárgy, ${subjInfo.questions.toLocaleString(
|
)} tárgy, ${subjInfo.questions.toLocaleString(
|
||||||
'hu'
|
'hu'
|
||||||
)} kérdés.\nUser ID: ${getUid()}`
|
)} kérdés.\nUser ID: ${getUid()}`
|
||||||
|
if (inf.unreads.length > 0) {
|
||||||
|
overlay.querySelector('#mailButton').innerText = '📬'
|
||||||
|
}
|
||||||
// FIXME: if cwith() throws an unhandled error it sais server is not avaible
|
// FIXME: if cwith() throws an unhandled error it sais server is not avaible
|
||||||
cwith()
|
cwith()
|
||||||
})
|
})
|
||||||
|
@ -1745,11 +1740,6 @@
|
||||||
greetMsg.push(texts.newVersionAvaible + lastestVersion)
|
greetMsg.push(texts.newVersionAvaible + lastestVersion)
|
||||||
timeout = undefined
|
timeout = undefined
|
||||||
}
|
}
|
||||||
if (userSpecificMotd && !userSpecificMotd.seen) {
|
|
||||||
timeout = null
|
|
||||||
greetMsg.push(texts.userSpecifitMotdAvailable)
|
|
||||||
timeout = undefined
|
|
||||||
}
|
|
||||||
if (newVersion) {
|
if (newVersion) {
|
||||||
greetMsg.push(texts.versionUpdated + info().script.version)
|
greetMsg.push(texts.versionUpdated + info().script.version)
|
||||||
setVal('lastVerson', info().script.version) // setting lastVersion
|
setVal('lastVerson', info().script.version) // setting lastVersion
|
||||||
|
@ -2481,24 +2471,13 @@
|
||||||
bottom: '15px',
|
bottom: '15px',
|
||||||
margin: '5px',
|
margin: '5px',
|
||||||
fontSize: '30px',
|
fontSize: '30px',
|
||||||
|
cursor: 'pointer',
|
||||||
},
|
},
|
||||||
|
title: 'Messages',
|
||||||
onClick: () => {
|
onClick: () => {
|
||||||
if (userSpecificMotd && !userSpecificMotd.seen) {
|
openInTab(serverAdress + 'chat', {
|
||||||
SafeGetElementById('mailButton', (elem) => {
|
active: true,
|
||||||
elem.innerText = '📭'
|
|
||||||
})
|
})
|
||||||
post('infos', {
|
|
||||||
userSpecificMotdSeen: true,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
if (!userSpecificMotd) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
clearAllMessages()
|
|
||||||
ShowMessage(
|
|
||||||
'Üzenet oldal készítéjétől (csak te látod):\n' +
|
|
||||||
userSpecificMotd.msg
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
buttonContainer: {
|
buttonContainer: {
|
||||||
|
@ -2802,31 +2781,25 @@
|
||||||
'&cid=' +
|
'&cid=' +
|
||||||
getCid()
|
getCid()
|
||||||
|
|
||||||
xmlhttpRequest({
|
Promise.all([get(url), get(apiAdress + 'hasNewMsg')])
|
||||||
method: 'GET',
|
.then(([{ responseText: infos }, { responseText: hasNewMsg }]) => {
|
||||||
url: url,
|
|
||||||
crossDomain: true,
|
|
||||||
xhrFields: { withCredentials: true },
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
onload: function (response) {
|
|
||||||
try {
|
try {
|
||||||
setVal('lastInfoCheckTime', now)
|
setVal('lastInfoCheckTime', now)
|
||||||
const res = JSON.parse(response.responseText)
|
const infosObj = JSON.parse(infos)
|
||||||
setVal('lastInfo', response.responseText)
|
const hasNewMsgsObj = JSON.parse(hasNewMsg)
|
||||||
resolve(res)
|
const merged = Object.assign({}, infosObj, hasNewMsgsObj)
|
||||||
|
setVal('lastInfo', JSON.stringify(merged))
|
||||||
|
resolve(merged)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log('Errro paring JSON in GetXHRInfos')
|
log('Errro paring JSON in GetXHRInfos')
|
||||||
log(response.responseText)
|
log({ infos: infos, hasNewMsg: hasNewMsg })
|
||||||
log(e)
|
log(e)
|
||||||
reject(e)
|
reject(e)
|
||||||
}
|
}
|
||||||
},
|
})
|
||||||
onerror: (e) => {
|
.catch((e) => {
|
||||||
log('Info get Error', e)
|
log('Info get Error', e)
|
||||||
reject(e)
|
reject(e)
|
||||||
},
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
@ -2842,6 +2815,26 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get(url) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
xmlhttpRequest({
|
||||||
|
method: 'GET',
|
||||||
|
url: url,
|
||||||
|
crossDomain: true,
|
||||||
|
xhrFields: { withCredentials: true },
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
onload: function (response) {
|
||||||
|
resolve(response)
|
||||||
|
},
|
||||||
|
onerror: (e) => {
|
||||||
|
reject(e)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
function post(path, message) {
|
function post(path, message) {
|
||||||
if (typeof message === 'object') {
|
if (typeof message === 'object') {
|
||||||
message = JSON.stringify(message)
|
message = JSON.stringify(message)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue