mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Merging master
This commit is contained in:
commit
cb9ea19699
2 changed files with 85 additions and 21 deletions
|
@ -25,6 +25,8 @@
|
|||
// @author Yout
|
||||
// @match https://elearning.uni-obuda.hu/main/*
|
||||
// @match https://elearning.uni-obuda.hu/kmooc/*
|
||||
// @match https://qmining.frylabs.net/*
|
||||
// @match http://qmining.frylabs.net/*
|
||||
// @match file:///*
|
||||
// @grant GM_getResourceText
|
||||
// @grant GM_info
|
||||
|
|
104
stable.user.js
104
stable.user.js
|
@ -27,6 +27,8 @@
|
|||
// @match https://elearning.uni-obuda.hu/main/*
|
||||
// @match https://elearning.uni-obuda.hu/kmooc/*
|
||||
// @match https://mooc.unideb.hu/*
|
||||
// @match https://qmining.frylabs.net/*
|
||||
// @match http://qmining.frylabs.net/*
|
||||
// @grant GM_getResourceText
|
||||
// @grant GM_info
|
||||
// @grant GM_getValue
|
||||
|
@ -72,6 +74,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
|
||||
|
@ -611,7 +614,7 @@
|
|||
}
|
||||
|
||||
function AfterLoad () {
|
||||
var url = location.href // eslint-disable-line
|
||||
const url = location.href // eslint-disable-line
|
||||
|
||||
try {
|
||||
if ((url.includes('/quiz/') && url.includes('attempt.php')) || forceTestPage) { // if the current page is a test
|
||||
|
@ -652,8 +655,46 @@
|
|||
// : Main logic stuff {{{
|
||||
|
||||
// : Loading {{{
|
||||
function HandleQminingSite (url) {
|
||||
try {
|
||||
Array.from(document.getElementById('sideBarLinks').childNodes).forEach((link) => {
|
||||
link.addEventListener('mousedown', () => {
|
||||
FillFeedbackCID(url, link)
|
||||
})
|
||||
})
|
||||
|
||||
FillFeedbackCID(url,
|
||||
document.getElementById('sideBarLinks').getElementsByClassName('active')[0]
|
||||
)
|
||||
} catch (e) {
|
||||
console.info('Error filling client ID input', e)
|
||||
}
|
||||
}
|
||||
|
||||
function FillFeedbackCID (url, link) {
|
||||
try {
|
||||
if (link.id === 'feedback') {
|
||||
const cidSetInterval = setInterval(() => {
|
||||
const cid = document.getElementById('cid')
|
||||
if (cid) {
|
||||
cid.value = GetId()
|
||||
window.clearInterval(cidSetInterval)
|
||||
}
|
||||
}, 100)
|
||||
}
|
||||
} catch (e) {
|
||||
console.info('Error filling client ID input', e)
|
||||
}
|
||||
}
|
||||
|
||||
function Init () {
|
||||
const url = location.href // eslint-disable-line
|
||||
|
||||
if (url.includes(serverAdress.split('/')[2])) {
|
||||
HandleQminingSite(url)
|
||||
return
|
||||
}
|
||||
|
||||
if (false) { // eslint-disable-line
|
||||
setVal('version16', undefined)
|
||||
setVal('version15', undefined)
|
||||
|
@ -661,7 +702,6 @@
|
|||
setVal('showQuestions', undefined)
|
||||
setVal('showSplash', undefined)
|
||||
}
|
||||
var url = location.href // eslint-disable-line
|
||||
// --------------------------------------------------------------------------------------
|
||||
// event listener fuckery
|
||||
// --------------------------------------------------------------------------------------
|
||||
|
@ -1575,31 +1615,53 @@
|
|||
}
|
||||
|
||||
function GetXHRInfos () {
|
||||
const url = apiAdress +
|
||||
'infos?version=true&motd=true&subjinfo=true&cversion=' +
|
||||
info().script.version +
|
||||
'&cid=' + GetId()
|
||||
const now = new Date().getTime()
|
||||
const lastCheck = getVal('lastInfoCheckTime')
|
||||
if (!lastCheck) {
|
||||
setVal('lastInfoCheckTime', now)
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
xmlhttpRequest({
|
||||
method: 'GET',
|
||||
url: url,
|
||||
onload: function (response) {
|
||||
try {
|
||||
const res = JSON.parse(response.responseText)
|
||||
resolve(res)
|
||||
} catch (e) {
|
||||
Log('Errro paring JSON in GetXHRInfos')
|
||||
Log(e)
|
||||
if (now > lastCheck + (infoExpireTime * 1000)) {
|
||||
console.log('GETTING DATA FROM SREVER')
|
||||
setVal('lastInfoCheckTime', now)
|
||||
return new Promise((resolve, reject) => {
|
||||
const url = apiAdress +
|
||||
'infos?version=true&motd=true&subjinfo=true&cversion=' +
|
||||
info().script.version +
|
||||
'&cid=' + GetId()
|
||||
|
||||
xmlhttpRequest({
|
||||
method: 'GET',
|
||||
url: url,
|
||||
onload: function (response) {
|
||||
try {
|
||||
const res = JSON.parse(response.responseText)
|
||||
setVal('lastInfo', response.responseText)
|
||||
resolve(res)
|
||||
} catch (e) {
|
||||
Log('Errro paring JSON in GetXHRInfos')
|
||||
Log(e)
|
||||
reject(e)
|
||||
}
|
||||
},
|
||||
onerror: (e) => {
|
||||
Log('Info get Error', e)
|
||||
reject(e)
|
||||
}
|
||||
},
|
||||
onerror: (e) => {
|
||||
Log('Info get Error', e)
|
||||
})
|
||||
})
|
||||
} 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