mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Added corect source checker, minor ui changes
This commit is contained in:
parent
dc2cb72dfd
commit
771b37d59f
1 changed files with 81 additions and 49 deletions
130
stable.user.js
130
stable.user.js
|
@ -86,7 +86,7 @@
|
||||||
// forcing pages for testing. unless you test, do not set these to true!
|
// forcing pages for testing. unless you test, do not set these to true!
|
||||||
setVal('ISDEVEL', true)
|
setVal('ISDEVEL', true)
|
||||||
// only one of these should be true for testing
|
// only one of these should be true for testing
|
||||||
const forceTestPage = true
|
const forceTestPage = false
|
||||||
const forceResultPage = false
|
const forceResultPage = false
|
||||||
const forceDefaultPage = false
|
const forceDefaultPage = false
|
||||||
|
|
||||||
|
@ -94,6 +94,8 @@
|
||||||
let serverAdress = 'https://qmining.frylabs.net/'
|
let serverAdress = 'https://qmining.frylabs.net/'
|
||||||
let apiAdress = 'https://api.frylabs.net/'
|
let apiAdress = 'https://api.frylabs.net/'
|
||||||
const ircAddress = 'https://kiwiirc.com/nextclient/irc.sub.fm/#qmining'
|
const ircAddress = 'https://kiwiirc.com/nextclient/irc.sub.fm/#qmining'
|
||||||
|
const correctSource =
|
||||||
|
'https://qmining.frylabs.net/moodle-test-userscript/stable.user.js?up'
|
||||||
|
|
||||||
const motdShowCount = 3 /* Ammount of times to show motd */
|
const motdShowCount = 3 /* Ammount of times to show motd */
|
||||||
let infoExpireTime = 60 // Every n seconds basic info should be loaded from server
|
let infoExpireTime = 60 // Every n seconds basic info should be loaded from server
|
||||||
|
@ -119,7 +121,6 @@
|
||||||
// : Localisation {{{
|
// : Localisation {{{
|
||||||
|
|
||||||
const huTexts = {
|
const huTexts = {
|
||||||
lastChangeLog: '',
|
|
||||||
fatalError:
|
fatalError:
|
||||||
'Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!',
|
'Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!',
|
||||||
consoleErrorInfo:
|
consoleErrorInfo:
|
||||||
|
@ -469,7 +470,6 @@
|
||||||
const questionGetters = {
|
const questionGetters = {
|
||||||
getSimpleQuestion: {
|
getSimpleQuestion: {
|
||||||
description: 'Basic question getter',
|
description: 'Basic question getter',
|
||||||
index: 0,
|
|
||||||
requirement: node => {
|
requirement: node => {
|
||||||
return node.getElementsByClassName('qtext').length > 0
|
return node.getElementsByClassName('qtext').length > 0
|
||||||
},
|
},
|
||||||
|
@ -483,7 +483,6 @@
|
||||||
const answerGetters = {
|
const answerGetters = {
|
||||||
getSimpleAnswer: {
|
getSimpleAnswer: {
|
||||||
description: 'Basic answer getter',
|
description: 'Basic answer getter',
|
||||||
index: 0,
|
|
||||||
requirement: node => {
|
requirement: node => {
|
||||||
return node.getElementsByClassName('rightanswer').length > 0
|
return node.getElementsByClassName('rightanswer').length > 0
|
||||||
},
|
},
|
||||||
|
@ -494,7 +493,6 @@
|
||||||
},
|
},
|
||||||
noCorrect: {
|
noCorrect: {
|
||||||
description: 'Gets correct answer, even if the correct is not shown',
|
description: 'Gets correct answer, even if the correct is not shown',
|
||||||
index: 2,
|
|
||||||
requirement: node => {
|
requirement: node => {
|
||||||
return (
|
return (
|
||||||
node.getElementsByClassName('rightanswer').length === 0 &&
|
node.getElementsByClassName('rightanswer').length === 0 &&
|
||||||
|
@ -529,7 +527,6 @@
|
||||||
},
|
},
|
||||||
getDropdownAnswer: {
|
getDropdownAnswer: {
|
||||||
description: 'Dropdown answer getter',
|
description: 'Dropdown answer getter',
|
||||||
index: 1,
|
|
||||||
requirement: node => {
|
requirement: node => {
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
|
@ -540,7 +537,6 @@
|
||||||
},
|
},
|
||||||
getTextareaAnswer: {
|
getTextareaAnswer: {
|
||||||
description: 'Get complex answer',
|
description: 'Get complex answer',
|
||||||
index: 1,
|
|
||||||
requirement: node => {
|
requirement: node => {
|
||||||
return false
|
return false
|
||||||
},
|
},
|
||||||
|
@ -778,6 +774,8 @@
|
||||||
|
|
||||||
function Main() {
|
function Main() {
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
|
// https://qmining.frylabs.net/moodle-test-userscript/stable.user.js?up
|
||||||
console.log('Moodle / E-Learning script')
|
console.log('Moodle / E-Learning script')
|
||||||
console.time('main')
|
console.time('main')
|
||||||
timerStarted = true
|
timerStarted = true
|
||||||
|
@ -1019,22 +1017,6 @@
|
||||||
|
|
||||||
// : }}}
|
// : }}}
|
||||||
|
|
||||||
// : Version action functions {{{
|
|
||||||
|
|
||||||
function FreshStart() {
|
|
||||||
var firstRun = getVal('firstRun') // if the current run is the frst
|
|
||||||
if (firstRun === undefined || firstRun === true) {
|
|
||||||
setVal('firstRun', false)
|
|
||||||
ShowHelp() // showing help
|
|
||||||
|
|
||||||
document.write(texts.freshStartWarning)
|
|
||||||
document.close()
|
|
||||||
throw new Error('something, so this stuff stops')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// : }}}
|
|
||||||
|
|
||||||
// : UI handling {{{
|
// : UI handling {{{
|
||||||
function HandleUI(url) {
|
function HandleUI(url) {
|
||||||
// FIXME: normal string building with localisation :/
|
// FIXME: normal string building with localisation :/
|
||||||
|
@ -1084,14 +1066,13 @@
|
||||||
timeout = undefined
|
timeout = undefined
|
||||||
}
|
}
|
||||||
if (newVersion) {
|
if (newVersion) {
|
||||||
// --------------------------------------------------------------------------------------------------------------
|
greetMsg += 'Verzió frissítve ' + info().script.version + '-re.'
|
||||||
greetMsg +=
|
|
||||||
'Verzió frissítve ' +
|
|
||||||
info().script.version +
|
|
||||||
'-re. Changelog:\n' +
|
|
||||||
texts.lastChangeLog
|
|
||||||
setVal('lastVerson', info().script.version) // setting lastVersion
|
setVal('lastVerson', info().script.version) // setting lastVersion
|
||||||
}
|
}
|
||||||
|
if (!installedFromCorrectSource(correctSource)) {
|
||||||
|
greetMsg +=
|
||||||
|
'\nScriptet nem a weboldalról raktad fel. PLS reinstall (a href = ...)'
|
||||||
|
}
|
||||||
if (showMOTD) {
|
if (showMOTD) {
|
||||||
greetMsg += '\nMOTD:\n' + motd
|
greetMsg += '\nMOTD:\n' + motd
|
||||||
timeout = null
|
timeout = null
|
||||||
|
@ -1239,6 +1220,33 @@
|
||||||
|
|
||||||
// : }}}
|
// : }}}
|
||||||
|
|
||||||
|
// : Misc {{{
|
||||||
|
|
||||||
|
// : Install source checker {{{
|
||||||
|
|
||||||
|
function installedFromCorrectSource(source) {
|
||||||
|
// TODO: test this
|
||||||
|
return info().script.updateURL === correctSource
|
||||||
|
}
|
||||||
|
|
||||||
|
// : }}}
|
||||||
|
|
||||||
|
// : Version action functions {{{
|
||||||
|
|
||||||
|
function FreshStart() {
|
||||||
|
var firstRun = getVal('firstRun') // if the current run is the frst
|
||||||
|
if (firstRun === undefined || firstRun === true) {
|
||||||
|
setVal('firstRun', false)
|
||||||
|
ShowHelp() // showing help
|
||||||
|
|
||||||
|
document.write(texts.freshStartWarning)
|
||||||
|
document.close()
|
||||||
|
throw new Error('something, so this stuff stops')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// : }}}
|
||||||
|
|
||||||
// : Video hotkey stuff {{{
|
// : Video hotkey stuff {{{
|
||||||
|
|
||||||
// this function adds basic hotkeys for video controll.
|
// this function adds basic hotkeys for video controll.
|
||||||
|
@ -1279,6 +1287,8 @@
|
||||||
|
|
||||||
// : }}}
|
// : }}}
|
||||||
|
|
||||||
|
// : }}}
|
||||||
|
|
||||||
// : Show message, and script menu stuff {{{
|
// : Show message, and script menu stuff {{{
|
||||||
|
|
||||||
function ClearAllMessages() {
|
function ClearAllMessages() {
|
||||||
|
@ -1287,6 +1297,7 @@
|
||||||
|
|
||||||
// shows a message with "msg" text, "matchPercent" tip and transp, and "timeout" time
|
// shows a message with "msg" text, "matchPercent" tip and transp, and "timeout" time
|
||||||
function ShowMessage(msgItem, timeout, funct) {
|
function ShowMessage(msgItem, timeout, funct) {
|
||||||
|
// TODO: simple message not selectable
|
||||||
// msgItem help:
|
// msgItem help:
|
||||||
// [ [ {}{}{}{} ] [ {}{}{} ] ]
|
// [ [ {}{}{}{} ] [ {}{}{} ] ]
|
||||||
// msgItem[] <- a questions stuff
|
// msgItem[] <- a questions stuff
|
||||||
|
@ -1294,7 +1305,7 @@
|
||||||
// msgItem[][].p <- a questions precent
|
// msgItem[][].p <- a questions precent
|
||||||
// msgItem[][].m <- a questions message
|
// msgItem[][].m <- a questions message
|
||||||
try {
|
try {
|
||||||
var defMargin = '0px 5px 0px 5px'
|
var defMargin = '0px 5px'
|
||||||
var isSimpleMessage = false
|
var isSimpleMessage = false
|
||||||
var simpleMessageText = ''
|
var simpleMessageText = ''
|
||||||
if (msgItem.isSimple) {
|
if (msgItem.isSimple) {
|
||||||
|
@ -1365,23 +1376,7 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const xrow = document.createElement('div')
|
const xButton = CreateNodeWithText(null, '❌', 'div')
|
||||||
xrow.setAttribute('id', 'msgHeader')
|
|
||||||
SetStyle(xrow, {
|
|
||||||
height: '20px',
|
|
||||||
userSelect: 'none',
|
|
||||||
})
|
|
||||||
mainDiv.appendChild(xrow)
|
|
||||||
|
|
||||||
const headerText = CreateNodeWithText(xrow, 'asd', 'div')
|
|
||||||
headerText.title = 'Talált kérdés tárgy neve'
|
|
||||||
SetStyle(headerText, {
|
|
||||||
padding: '2px 5px',
|
|
||||||
textAlign: 'center',
|
|
||||||
display: 'inline',
|
|
||||||
})
|
|
||||||
|
|
||||||
const xButton = CreateNodeWithText(xrow, '❌', 'div')
|
|
||||||
SetStyle(xButton, {
|
SetStyle(xButton, {
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
@ -1396,14 +1391,20 @@
|
||||||
// ------------------------------------------------------------------
|
// ------------------------------------------------------------------
|
||||||
var matchPercent = msgItem[0][0].p
|
var matchPercent = msgItem[0][0].p
|
||||||
if (isSimpleMessage) {
|
if (isSimpleMessage) {
|
||||||
|
mainDiv.appendChild(xButton)
|
||||||
var simpleMessageParagrapg = document.createElement('p') // new paragraph
|
var simpleMessageParagrapg = document.createElement('p') // new paragraph
|
||||||
simpleMessageParagrapg.style.margin = defMargin // fancy margin
|
simpleMessageParagrapg.style.margin = defMargin // fancy margin
|
||||||
|
|
||||||
var mesageNode = document.createElement('p') // new paragraph
|
var mesageNode = document.createElement('p') // new paragraph
|
||||||
mesageNode.innerHTML = simpleMessageText.replace(/\n/g, '</br>')
|
mesageNode.innerHTML = simpleMessageText.replace(/\n/g, '</br>')
|
||||||
simpleMessageParagrapg.appendChild(mesageNode)
|
simpleMessageParagrapg.appendChild(mesageNode)
|
||||||
|
mesageNode.addEventListener('mousedown', e => {
|
||||||
|
e.stopPropagation()
|
||||||
|
})
|
||||||
|
// TODO: edit this margin to make simple message draggable
|
||||||
SetStyle(mesageNode, {
|
SetStyle(mesageNode, {
|
||||||
margin: defMargin,
|
margin: '10px 0px',
|
||||||
|
cursor: 'auto',
|
||||||
})
|
})
|
||||||
|
|
||||||
Array.from(mesageNode.getElementsByTagName('a')).forEach(anchorElem => {
|
Array.from(mesageNode.getElementsByTagName('a')).forEach(anchorElem => {
|
||||||
|
@ -1412,6 +1413,23 @@
|
||||||
|
|
||||||
mainDiv.appendChild(simpleMessageParagrapg) // adding text box to main div
|
mainDiv.appendChild(simpleMessageParagrapg) // adding text box to main div
|
||||||
} else {
|
} else {
|
||||||
|
const headerRow = document.createElement('div')
|
||||||
|
headerRow.setAttribute('id', 'msgHeader')
|
||||||
|
SetStyle(headerRow, {
|
||||||
|
height: '20px',
|
||||||
|
userSelect: 'none',
|
||||||
|
})
|
||||||
|
mainDiv.appendChild(headerRow)
|
||||||
|
|
||||||
|
const headerText = CreateNodeWithText(headerRow, '', 'div')
|
||||||
|
headerText.title = 'Talált kérdés tárgy neve'
|
||||||
|
SetStyle(headerText, {
|
||||||
|
padding: '2px 5px',
|
||||||
|
textAlign: 'center',
|
||||||
|
display: 'inline',
|
||||||
|
})
|
||||||
|
|
||||||
|
headerRow.appendChild(xButton)
|
||||||
// if its a fucking complicated message
|
// if its a fucking complicated message
|
||||||
// TABLE SETUP ------------------------------------------------------------------------------------------------------------
|
// TABLE SETUP ------------------------------------------------------------------------------------------------------------
|
||||||
var table = document.createElement('table')
|
var table = document.createElement('table')
|
||||||
|
@ -1644,6 +1662,18 @@
|
||||||
borderRadius: '5px',
|
borderRadius: '5px',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const xButton = CreateNodeWithText(menuButtonDiv, '❌', 'div')
|
||||||
|
SetStyle(xButton, {
|
||||||
|
cursor: 'pointer',
|
||||||
|
position: 'absolute',
|
||||||
|
right: '0px',
|
||||||
|
display: 'inline',
|
||||||
|
})
|
||||||
|
xButton.addEventListener('mousedown', e => {
|
||||||
|
e.stopPropagation()
|
||||||
|
menuButtonDiv.parentNode.removeChild(menuButtonDiv)
|
||||||
|
})
|
||||||
|
|
||||||
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'
|
||||||
|
@ -1980,7 +2010,9 @@
|
||||||
var paragraphElement = document.createElement(type || 'p') // new paragraph
|
var paragraphElement = document.createElement(type || 'p') // new paragraph
|
||||||
var textNode = document.createTextNode(text)
|
var textNode = document.createTextNode(text)
|
||||||
paragraphElement.appendChild(textNode)
|
paragraphElement.appendChild(textNode)
|
||||||
to.appendChild(paragraphElement)
|
if (to) {
|
||||||
|
to.appendChild(paragraphElement)
|
||||||
|
}
|
||||||
return paragraphElement
|
return paragraphElement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue