mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Info getting only every x seconds
This commit is contained in:
parent
2f9446157b
commit
bf2b44ee56
1 changed files with 39 additions and 16 deletions
|
@ -21,7 +21,7 @@
|
|||
|
||||
// ==UserScript==
|
||||
// @name Moodle/Elearning/KMOOC test help
|
||||
// @version 2.0.0.4
|
||||
// @version 2.0.0.5
|
||||
// @description Online Moodle/Elearning/KMOOC test help
|
||||
// @author MrFry
|
||||
// @match https://elearning.uni-obuda.hu/main/*
|
||||
|
@ -73,6 +73,7 @@
|
|||
const log = true
|
||||
|
||||
const motdShowCount = 3 /* Ammount of times to show motd */
|
||||
const infoExpireTime = 60 // Every n seconds basic info should be loaded from server
|
||||
var motd = ''
|
||||
var lastestVersion = ''
|
||||
var subjInfo
|
||||
|
@ -1613,6 +1614,15 @@
|
|||
}
|
||||
|
||||
function GetXHRInfos () {
|
||||
const now = new Date().getTime()
|
||||
const lastCheck = getVal('lastInfoCheckTime')
|
||||
if (!lastCheck) {
|
||||
setVal('lastInfoCheckTime', now)
|
||||
}
|
||||
|
||||
if (now > lastCheck + (infoExpireTime * 1000)) {
|
||||
console.log('GETTING DATA FROM SREVER')
|
||||
setVal('lastInfoCheckTime', now)
|
||||
return new Promise((resolve, reject) => {
|
||||
xmlhttpRequest({
|
||||
method: 'GET',
|
||||
|
@ -1620,6 +1630,7 @@
|
|||
onload: function (response) {
|
||||
try {
|
||||
const res = JSON.parse(response.responseText)
|
||||
setVal('lastInfo', response.responseText)
|
||||
resolve(res)
|
||||
} catch (e) {
|
||||
Log('Errro paring JSON in GetXHRInfos')
|
||||
|
@ -1633,6 +1644,18 @@
|
|||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
console.log('USING OLD')
|
||||
return new Promise((resolve, reject) => {
|
||||
try {
|
||||
resolve(JSON.parse(getVal('lastInfo')))
|
||||
} catch (e) {
|
||||
Log('Errro paring JSON in GetXHRInfos, when using old data!')
|
||||
Log(e)
|
||||
reject(e)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
function GetXHRQuestionAnswer (question) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue