mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Removed some unnecesary stuff, script gui nicening
This commit is contained in:
parent
566321eed8
commit
57274ad8d4
1 changed files with 72 additions and 87 deletions
159
stable.user.js
159
stable.user.js
|
@ -130,17 +130,17 @@
|
||||||
showGreetingOnEveryPage: 'Üdvözlő üzenet mutatása minden oldalon',
|
showGreetingOnEveryPage: 'Üdvözlő üzenet mutatása minden oldalon',
|
||||||
close: 'Bezárás',
|
close: 'Bezárás',
|
||||||
help: 'Help',
|
help: 'Help',
|
||||||
websiteBugreport: 'Weboldal / Bug report',
|
websiteBugreport: 'Weboldal',
|
||||||
contribute: 'Contribute',
|
contribute: 'Bug report / Szavazás következő feature-re',
|
||||||
donate: 'Donate',
|
donate: 'Donate',
|
||||||
retry: 'Újrapróbálás',
|
retry: 'Újrapróbálás',
|
||||||
ircButton: 'IRC',
|
ircButton: 'IRC',
|
||||||
|
ircButtonTitle: 'IRC chat',
|
||||||
invalidPW: 'Hibás jelszó: ',
|
invalidPW: 'Hibás jelszó: ',
|
||||||
search: 'Keresés ...',
|
search: 'Keresés ...',
|
||||||
loading: 'Betöltés ...',
|
loading: 'Betöltés ...',
|
||||||
login: 'Belépés',
|
login: 'Belépés',
|
||||||
requestPWInsteadOfLogin: 'Jelszó igénylés',
|
requestPWInsteadOfLogin: 'Jelszó igénylés',
|
||||||
contributeTitle: 'Hozzájárulás a script és weboldal fejleszétéshez',
|
|
||||||
newPWTitle: 'Új jelszó új felhasználónak',
|
newPWTitle: 'Új jelszó új felhasználónak',
|
||||||
pwRequest: 'Új jelszó',
|
pwRequest: 'Új jelszó',
|
||||||
noServer: 'Nem elérhető a szerver!',
|
noServer: 'Nem elérhető a szerver!',
|
||||||
|
@ -250,6 +250,7 @@
|
||||||
function getQuizData() {
|
function getQuizData() {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
// TODO: dropdown in question
|
// TODO: dropdown in question
|
||||||
|
// TODO: get possible answers too
|
||||||
const promises = []
|
const promises = []
|
||||||
const questionNodes = Array.from(
|
const questionNodes = Array.from(
|
||||||
document.getElementsByTagName('form')[0].childNodes[0].childNodes
|
document.getElementsByTagName('form')[0].childNodes[0].childNodes
|
||||||
|
@ -612,7 +613,10 @@
|
||||||
// ----------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
function removeUnnecesarySpaces(toremove) {
|
function removeUnnecesarySpaces(toremove) {
|
||||||
assert(toremove)
|
// TODO: check if this doesnt kill if question / answer is empty
|
||||||
|
if (!toremove) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
toremove = normalizeSpaces(toremove).replace(/\t/g, '')
|
toremove = normalizeSpaces(toremove).replace(/\t/g, '')
|
||||||
while (toremove.includes(' ')) {
|
while (toremove.includes(' ')) {
|
||||||
|
@ -808,13 +812,6 @@
|
||||||
return document.getElementById('videoElement').parentNode
|
return document.getElementById('videoElement').parentNode
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInputType(answers, i) {
|
|
||||||
if (logElementGetting) {
|
|
||||||
Log('getting input type')
|
|
||||||
}
|
|
||||||
return answers[i].getElementsByTagName('input')[0].type
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// : }}}
|
// : }}}
|
||||||
|
@ -954,19 +951,7 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (false) {
|
|
||||||
// // eslint-disable-line
|
|
||||||
// setVal("version16", undefined);
|
|
||||||
// setVal("version15", undefined);
|
|
||||||
// setVal("firstRun", undefined);
|
|
||||||
// setVal("showQuestions", undefined);
|
|
||||||
// setVal("showSplash", undefined);
|
|
||||||
// }
|
|
||||||
// --------------------------------------------------------------------------------------
|
|
||||||
// event listener fuckery
|
|
||||||
// --------------------------------------------------------------------------------------
|
|
||||||
try {
|
try {
|
||||||
// adding addeventlistener stuff, for the ability to add more event listeners for the same event
|
|
||||||
addEventListener = (function() {
|
addEventListener = (function() {
|
||||||
if (document.addEventListener) {
|
if (document.addEventListener) {
|
||||||
return function(element, event, handler) {
|
return function(element, event, handler) {
|
||||||
|
@ -1077,12 +1062,6 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function VersionActions() {
|
function VersionActions() {
|
||||||
// FOR TESTING ONLY
|
|
||||||
// setVal("version15", true);
|
|
||||||
// setVal("firstRun", true);
|
|
||||||
// setVal("version16", true);
|
|
||||||
// throw "asd";
|
|
||||||
|
|
||||||
FreshStart()
|
FreshStart()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1181,7 +1160,6 @@
|
||||||
|
|
||||||
// : Answering stuffs {{{
|
// : Answering stuffs {{{
|
||||||
|
|
||||||
// TODO
|
|
||||||
function PrepareAnswers(result) {
|
function PrepareAnswers(result) {
|
||||||
assert(result)
|
assert(result)
|
||||||
|
|
||||||
|
@ -1198,22 +1176,19 @@
|
||||||
res.q.data.images.join(', ') // if it has image part, adding that too
|
res.q.data.images.join(', ') // if it has image part, adding that too
|
||||||
}
|
}
|
||||||
|
|
||||||
msg += '\n(Tárgy: ' + res.detailedMatch.matchedSubjName + ')'
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
m: msg,
|
m: msg,
|
||||||
p: res.match,
|
p: res.match,
|
||||||
|
header: res.detailedMatch.matchedSubjName,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
|
||||||
function ShowAnswers(answers, question) {
|
function ShowAnswers(answers, question) {
|
||||||
assert(answers)
|
assert(answers)
|
||||||
|
|
||||||
if (answers.length > 0) {
|
if (answers.length > 0) {
|
||||||
// if there are more than 0 answer
|
|
||||||
ShowMessage(answers)
|
ShowMessage(answers)
|
||||||
} else {
|
} else {
|
||||||
ShowMessage(
|
ShowMessage(
|
||||||
|
@ -1240,20 +1215,11 @@
|
||||||
|
|
||||||
function HandleResults(url) {
|
function HandleResults(url) {
|
||||||
getQuiz().then(res => {
|
getQuiz().then(res => {
|
||||||
console.log('\n\n\n')
|
|
||||||
res.forEach((r, i) => {
|
|
||||||
console.log('')
|
|
||||||
console.log(i + 1)
|
|
||||||
console.log(r.Q)
|
|
||||||
console.log(r.A)
|
|
||||||
console.log(r.data)
|
|
||||||
})
|
|
||||||
SaveQuiz(res, ShowSaveQuizDialog) // saves the quiz questions and answers
|
SaveQuiz(res, ShowSaveQuizDialog) // saves the quiz questions and answers
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function ShowSaveQuizDialog(sendResult, sentData, newQuestions) {
|
function ShowSaveQuizDialog(sendResult, sentData, newQuestions) {
|
||||||
// FIXME: normal string building with localisation :/
|
|
||||||
var msg = ''
|
var msg = ''
|
||||||
if (sendResult) {
|
if (sendResult) {
|
||||||
msg = 'Kérdések elküldve, katt az elküldött adatokért.'
|
msg = 'Kérdések elküldve, katt az elküldött adatokért.'
|
||||||
|
@ -1294,15 +1260,17 @@
|
||||||
throw new Error('quiz length is zero!')
|
throw new Error('quiz length is zero!')
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
sentData = {
|
||||||
|
version: info().script.version,
|
||||||
|
id: GetId(),
|
||||||
|
quiz: quiz,
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
sentData.subj = getCurrentSubjectName()
|
sentData.subj = getCurrentSubjectName()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
sentData.subj = 'NOSUBJ'
|
sentData.subj = 'NOSUBJ'
|
||||||
Log('unable to get subject name :c')
|
Log('unable to get subject name :c')
|
||||||
}
|
}
|
||||||
sentData.version = info().script.version
|
|
||||||
sentData.id = GetId()
|
|
||||||
sentData.quiz = quiz
|
|
||||||
console.log('SENT DATA', sentData)
|
console.log('SENT DATA', sentData)
|
||||||
SendXHRMessage('isAdding', sentData).then(res => {
|
SendXHRMessage('isAdding', sentData).then(res => {
|
||||||
next(res.success, sentData, res.newQuestions)
|
next(res.success, sentData, res.newQuestions)
|
||||||
|
@ -1319,26 +1287,6 @@
|
||||||
|
|
||||||
// : Helpers {{{
|
// : Helpers {{{
|
||||||
|
|
||||||
// adds image names to image nodes
|
|
||||||
function AddImageNamesToImages(imgs) {
|
|
||||||
// TODO
|
|
||||||
// for (var i = 0; i < imgs.length; i++) {
|
|
||||||
// if (!imgs[i].src.includes('brokenfile')) {
|
|
||||||
// // TODO: add this to shadowroot
|
|
||||||
// var filePart = imgs[i].src.split('/') // splits the link by "/"
|
|
||||||
// // console.log(imgs[i].src.split("base64,")[1])
|
|
||||||
// // TODO: base64
|
|
||||||
// filePart = filePart[filePart.length - 1] // the last one is the image name
|
|
||||||
// var appendTo = imgs[i].parentNode // it will be appended here
|
|
||||||
// var mainDiv = document.createElement('div')
|
|
||||||
// var fileName = SUtils.ShortenString(decodeURI(filePart), 15) // shortening name, couse it can be long as fuck
|
|
||||||
// var textNode = document.createTextNode('(' + fileName + ')')
|
|
||||||
// mainDiv.appendChild(textNode)
|
|
||||||
// appendBelowElement(appendTo, mainDiv)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
// this function adds basic hotkeys for video controll.
|
// this function adds basic hotkeys for video controll.
|
||||||
function AddVideoHotkeys(url) {
|
function AddVideoHotkeys(url) {
|
||||||
var seekTime = 20
|
var seekTime = 20
|
||||||
|
@ -1502,17 +1450,27 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
const xrow = document.createElement('div')
|
const xrow = document.createElement('div')
|
||||||
|
xrow.setAttribute('id', 'msgHeader')
|
||||||
SetStyle(xrow, {
|
SetStyle(xrow, {
|
||||||
height: '20px',
|
height: '20px',
|
||||||
display: 'flex',
|
userSelect: 'none',
|
||||||
justifyContent: 'flex-end',
|
|
||||||
})
|
})
|
||||||
mainDiv.appendChild(xrow)
|
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')
|
const xButton = CreateNodeWithText(xrow, '❌', 'div')
|
||||||
SetStyle(xButton, {
|
SetStyle(xButton, {
|
||||||
margin: '5px',
|
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
|
position: 'absolute',
|
||||||
|
right: '0px',
|
||||||
|
display: 'inline',
|
||||||
})
|
})
|
||||||
xButton.addEventListener('mousedown', e => {
|
xButton.addEventListener('mousedown', e => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
@ -1548,15 +1506,27 @@
|
||||||
var rowThree = table.insertRow() // next suggetsion button
|
var rowThree = table.insertRow() // next suggetsion button
|
||||||
// CELLS -----------------------------------------------------------------------------------------------------
|
// CELLS -----------------------------------------------------------------------------------------------------
|
||||||
// row one
|
// row one
|
||||||
|
const sideCellWidth = 30
|
||||||
var numberTextCell = rowOne.insertCell()
|
var numberTextCell = rowOne.insertCell()
|
||||||
|
SetStyle(numberTextCell, {
|
||||||
|
width: sideCellWidth + 'px',
|
||||||
|
})
|
||||||
var questionCell = rowOne.insertCell() // QUESTION CELL
|
var questionCell = rowOne.insertCell() // QUESTION CELL
|
||||||
questionCell.setAttribute('id', 'questionCell')
|
questionCell.setAttribute('id', 'questionCell')
|
||||||
questionCell.rowSpan = 3
|
questionCell.rowSpan = 3
|
||||||
questionCell.style.width = '90%'
|
|
||||||
var prevQuestionCell = rowOne.insertCell()
|
var prevQuestionCell = rowOne.insertCell()
|
||||||
|
SetStyle(prevQuestionCell, {
|
||||||
|
width: sideCellWidth + 'px',
|
||||||
|
})
|
||||||
// row two
|
// row two
|
||||||
var percentTextCell = rowTwo.insertCell()
|
var percentTextCell = rowTwo.insertCell()
|
||||||
|
SetStyle(percentTextCell, {
|
||||||
|
width: sideCellWidth + 'px',
|
||||||
|
})
|
||||||
var nextQuestionCell = rowTwo.insertCell()
|
var nextQuestionCell = rowTwo.insertCell()
|
||||||
|
SetStyle(nextQuestionCell, {
|
||||||
|
width: sideCellWidth + 'px',
|
||||||
|
})
|
||||||
// row three
|
// row three
|
||||||
var prevSuggestionCell = rowThree.insertCell()
|
var prevSuggestionCell = rowThree.insertCell()
|
||||||
var nextSuggestionCell = rowThree.insertCell()
|
var nextSuggestionCell = rowThree.insertCell()
|
||||||
|
@ -1565,6 +1535,7 @@
|
||||||
// PERCENT TEXT SETUP -----------------------------------------------------------------------------------------------------
|
// PERCENT TEXT SETUP -----------------------------------------------------------------------------------------------------
|
||||||
var percentTextBox = CreateNodeWithText(percentTextCell, '')
|
var percentTextBox = CreateNodeWithText(percentTextCell, '')
|
||||||
percentTextBox.setAttribute('id', 'percentTextBox')
|
percentTextBox.setAttribute('id', 'percentTextBox')
|
||||||
|
percentTextBox.title = 'Egyezés %'
|
||||||
|
|
||||||
if (matchPercent) {
|
if (matchPercent) {
|
||||||
// if match percent param is not null
|
// if match percent param is not null
|
||||||
|
@ -1573,6 +1544,7 @@
|
||||||
// NUMBER SETUP -----------------------------------------------------------------------------------------------------
|
// NUMBER SETUP -----------------------------------------------------------------------------------------------------
|
||||||
var numberTextBox = CreateNodeWithText(numberTextCell, '1.')
|
var numberTextBox = CreateNodeWithText(numberTextCell, '1.')
|
||||||
numberTextBox.setAttribute('id', 'numberTextBox')
|
numberTextBox.setAttribute('id', 'numberTextBox')
|
||||||
|
numberTextBox.title = 'Lehetséges válasz index'
|
||||||
|
|
||||||
// ANSWER NODE SETUP -------------------------------------------------------------------------------------------------------------
|
// ANSWER NODE SETUP -------------------------------------------------------------------------------------------------------------
|
||||||
var questionTextElement = CreateNodeWithText(
|
var questionTextElement = CreateNodeWithText(
|
||||||
|
@ -1621,10 +1593,10 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const SetQuestionText = () => {
|
const SetQuestionText = () => {
|
||||||
var relevantQuestion = GetRelevantQuestion()
|
const relevantQuestion = GetRelevantQuestion()
|
||||||
questionTextElement.innerText = removeUnnecesarySpaces(
|
questionTextElement.innerText = relevantQuestion.m
|
||||||
relevantQuestion.m
|
headerText.innerText = relevantQuestion.header
|
||||||
)
|
|
||||||
if (currItem === 0 && currRelevantQuestion === 0) {
|
if (currItem === 0 && currRelevantQuestion === 0) {
|
||||||
numberTextBox.innerText = currRelevantQuestion + 1 + '.'
|
numberTextBox.innerText = currRelevantQuestion + 1 + '.'
|
||||||
} else {
|
} else {
|
||||||
|
@ -1651,6 +1623,7 @@
|
||||||
'⬅️',
|
'⬅️',
|
||||||
'div'
|
'div'
|
||||||
)
|
)
|
||||||
|
prevSuggButton.title = 'Előző lehetséges válasz'
|
||||||
SetStyle(prevSuggButton, buttonStyle)
|
SetStyle(prevSuggButton, buttonStyle)
|
||||||
|
|
||||||
prevSuggButton.addEventListener('mousedown', function(e) {
|
prevSuggButton.addEventListener('mousedown', function(e) {
|
||||||
|
@ -1664,6 +1637,7 @@
|
||||||
'➡️',
|
'➡️',
|
||||||
'div'
|
'div'
|
||||||
)
|
)
|
||||||
|
nextSuggButton.title = 'Következő lehetséges válasz'
|
||||||
SetStyle(nextSuggButton, buttonStyle)
|
SetStyle(nextSuggButton, buttonStyle)
|
||||||
|
|
||||||
nextSuggButton.addEventListener('mousedown', function(e) {
|
nextSuggButton.addEventListener('mousedown', function(e) {
|
||||||
|
@ -1680,6 +1654,7 @@
|
||||||
// PREV QUESTION BUTTON ------------------------------------------------------------------------------------------------------------
|
// PREV QUESTION BUTTON ------------------------------------------------------------------------------------------------------------
|
||||||
var prevButton = CreateNodeWithText(prevQuestionCell, '⬆️', 'div')
|
var prevButton = CreateNodeWithText(prevQuestionCell, '⬆️', 'div')
|
||||||
SetStyle(prevButton, buttonStyle)
|
SetStyle(prevButton, buttonStyle)
|
||||||
|
prevButton.title = 'Előző kérdés'
|
||||||
|
|
||||||
// event listener
|
// event listener
|
||||||
prevButton.addEventListener('click', function() {
|
prevButton.addEventListener('click', function() {
|
||||||
|
@ -1689,6 +1664,7 @@
|
||||||
// NEXT QUESTION BUTTON ------------------------------------------------------------------------------------------------------------
|
// NEXT QUESTION BUTTON ------------------------------------------------------------------------------------------------------------
|
||||||
var nextButton = CreateNodeWithText(nextQuestionCell, '⬇️', 'div')
|
var nextButton = CreateNodeWithText(nextQuestionCell, '⬇️', 'div')
|
||||||
SetStyle(nextButton, buttonStyle)
|
SetStyle(nextButton, buttonStyle)
|
||||||
|
nextButton.title = 'Előző kérdés'
|
||||||
|
|
||||||
// event listener
|
// event listener
|
||||||
nextButton.addEventListener('click', function() {
|
nextButton.addEventListener('click', function() {
|
||||||
|
@ -1770,6 +1746,21 @@
|
||||||
color: '#ffffff',
|
color: '#ffffff',
|
||||||
cursor: 'pointer',
|
cursor: 'pointer',
|
||||||
}
|
}
|
||||||
|
// site link ----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
let siteLink = CreateNodeWithText(
|
||||||
|
buttonCell,
|
||||||
|
texts.websiteBugreport,
|
||||||
|
'button'
|
||||||
|
)
|
||||||
|
SetStyle(siteLink, buttonStyle)
|
||||||
|
|
||||||
|
siteLink.addEventListener('click', function() {
|
||||||
|
openInTab(serverAdress + 'menuClick', {
|
||||||
|
active: true,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
// help button ----------------------------------------------------------------------------------------------------------------
|
// help button ----------------------------------------------------------------------------------------------------------------
|
||||||
let helpButton = CreateNodeWithText(buttonCell, texts.help, 'button')
|
let helpButton = CreateNodeWithText(buttonCell, texts.help, 'button')
|
||||||
SetStyle(helpButton, buttonStyle)
|
SetStyle(helpButton, buttonStyle)
|
||||||
|
@ -1785,7 +1776,6 @@
|
||||||
texts.contribute,
|
texts.contribute,
|
||||||
'button'
|
'button'
|
||||||
)
|
)
|
||||||
contributeLink.title = texts.contributeTitle
|
|
||||||
SetStyle(contributeLink, buttonStyle)
|
SetStyle(contributeLink, buttonStyle)
|
||||||
|
|
||||||
contributeLink.addEventListener('click', function() {
|
contributeLink.addEventListener('click', function() {
|
||||||
|
@ -1801,22 +1791,17 @@
|
||||||
SetStyle(pwRequest, buttonStyle)
|
SetStyle(pwRequest, buttonStyle)
|
||||||
|
|
||||||
pwRequest.addEventListener('click', function() {
|
pwRequest.addEventListener('click', function() {
|
||||||
openInTab(serverAdress + 'pwRequest', {
|
openInTab(serverAdress + 'pwRequest?scriptMenu', {
|
||||||
active: true,
|
active: true,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
// IRC ----------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// site link ----------------------------------------------------------------------------------------------------------------
|
let ircButton2 = CreateNodeWithText(buttonCell, texts.ircButton, 'button')
|
||||||
|
ircButton2.title = texts.ircButtonTitle
|
||||||
let siteLink = CreateNodeWithText(
|
SetStyle(ircButton2, buttonStyle)
|
||||||
buttonCell,
|
ircButton2.addEventListener('click', function() {
|
||||||
texts.websiteBugreport,
|
openInTab(serverAdress + 'irc?scriptMenu', {
|
||||||
'button'
|
|
||||||
)
|
|
||||||
SetStyle(siteLink, buttonStyle)
|
|
||||||
|
|
||||||
siteLink.addEventListener('click', function() {
|
|
||||||
openInTab(serverAdress + 'menuClick', {
|
|
||||||
active: true,
|
active: true,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue