Checking kgk site changes with interval

This commit is contained in:
mrfry 2021-12-14 17:27:29 +01:00
parent 960c5503df
commit 3a5e0c6a0c

View file

@ -1094,6 +1094,24 @@
return x.join(' ') return x.join(' ')
} }
function handleKGKSite(url) {
let prevLength = -1
setInterval(() => {
const kkerdesElements = document.getElementsByClassName('kkerdes')
if (prevLength !== kkerdesElements.length) {
prevLength = kkerdesElements.length
console.log('PL', prevLength, 'NL', kkerdesElements.length)
if (kkerdesElements.length > 0) {
console.log('Handling quiz')
handleKGKQuiz(url)
} else {
console.log('Handling results')
HandleKGKResults(url)
}
}
}, 1 * 1000)
}
function handleKGKQuiz(url) { function handleKGKQuiz(url) {
try { try {
const { removeMessage: removeLoadingMessage } = ShowMessage( const { removeMessage: removeLoadingMessage } = ShowMessage(
@ -1135,6 +1153,17 @@
// : }}} // : }}}
// : Canvas {{{
function handleCanvasQuiz() {
console.trace()
}
function HandleCanvasResults() {
console.trace()
}
// : }}}
// : Misc {{{ // : Misc {{{
function getVideo() { function getVideo() {
@ -1318,13 +1347,13 @@
const pageMatchers = [ const pageMatchers = [
{ {
matchString: 'portal.kgk', matchString: 'canvas',
testPage: { testPage: {
match: (url) => { match: (url) => {
return url.includes('vizsga') return true // TODO :insert real url
}, },
action: (url) => { action: (url) => {
handleKGKQuiz(url) handleCanvasQuiz(url)
}, },
}, },
resultPage: { resultPage: {
@ -1332,7 +1361,7 @@
return false // TODO :insert real url return false // TODO :insert real url
}, },
action: (url) => { action: (url) => {
HandleKGKResults(url) HandleCanvasResults(url)
}, },
}, },
default: { default: {
@ -1344,6 +1373,33 @@
}, },
}, },
}, },
{
matchString: 'portal.kgk',
// testPage: {
// match: (url) => {
// return url.includes('vizsga')
// },
// action: (url) => {
// handleKGKSite(url)
// },
// },
// resultPage: {
// match: (url) => {
// return false // TODO :insert real url
// },
// action: (url) => {
// handleKGKSite(url)
// },
// },
default: {
match: (url) => {
return true // TODO :insert real url
},
action: (url) => {
handleKGKSite(url)
},
},
},
{ {
matchString: 'default', // moodle, elearning, mooc matchString: 'default', // moodle, elearning, mooc
testPage: { testPage: {
@ -1392,7 +1448,7 @@
if ( if (
url.includes(matcher.matchString) || url.includes(matcher.matchString) ||
matcher.matchString === 'default' || matcher.matchString === 'default' ||
matcher.matchString === forcedMatchString matcher.matchString.includes(forcedMatchString)
) { ) {
if (matcher.testPage && matcher.testPage.match(url)) { if (matcher.testPage && matcher.testPage.match(url)) {
matcher.testPage.action(url) matcher.testPage.action(url)
@ -1412,15 +1468,9 @@
} }
}) })
} catch (e) { } catch (e) {
ShowMessage( ShowMessage(texts.fatalError, undefined, () => {
texts.fatalError, OpenErrorPage(e)
})
undefined,
() => {
OpenErrorPage(e)
}
)
Exception(e, 'script error at main:') Exception(e, 'script error at main:')
} }
if (url.includes('eduplayer')) { if (url.includes('eduplayer')) {