Removed some unnecesary stuff, script gui nicening

This commit is contained in:
mrfry 2020-11-20 10:55:38 +01:00
parent 566321eed8
commit 57274ad8d4

View file

@ -130,17 +130,17 @@
showGreetingOnEveryPage: 'Üdvözlő üzenet mutatása minden oldalon',
close: 'Bezárás',
help: 'Help',
websiteBugreport: 'Weboldal / Bug report',
contribute: 'Contribute',
websiteBugreport: 'Weboldal',
contribute: 'Bug report / Szavazás következő feature-re',
donate: 'Donate',
retry: 'Újrapróbálás',
ircButton: 'IRC',
ircButtonTitle: 'IRC chat',
invalidPW: 'Hibás jelszó: ',
search: 'Keresés ...',
loading: 'Betöltés ...',
login: 'Belépé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',
pwRequest: 'Új jelszó',
noServer: 'Nem elérhető a szerver!',
@ -250,6 +250,7 @@
function getQuizData() {
return new Promise(resolve => {
// TODO: dropdown in question
// TODO: get possible answers too
const promises = []
const questionNodes = Array.from(
document.getElementsByTagName('form')[0].childNodes[0].childNodes
@ -612,7 +613,10 @@
// ----------------------------------------------------------------------------------------------
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, '')
while (toremove.includes(' ')) {
@ -808,13 +812,6 @@
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
}
// if (false) {
// // eslint-disable-line
// setVal("version16", undefined);
// setVal("version15", undefined);
// setVal("firstRun", undefined);
// setVal("showQuestions", undefined);
// setVal("showSplash", undefined);
// }
// --------------------------------------------------------------------------------------
// event listener fuckery
// --------------------------------------------------------------------------------------
try {
// adding addeventlistener stuff, for the ability to add more event listeners for the same event
addEventListener = (function() {
if (document.addEventListener) {
return function(element, event, handler) {
@ -1077,12 +1062,6 @@
}
function VersionActions() {
// FOR TESTING ONLY
// setVal("version15", true);
// setVal("firstRun", true);
// setVal("version16", true);
// throw "asd";
FreshStart()
}
@ -1181,7 +1160,6 @@
// : Answering stuffs {{{
// TODO
function PrepareAnswers(result) {
assert(result)
@ -1198,22 +1176,19 @@
res.q.data.images.join(', ') // if it has image part, adding that too
}
msg += '\n(Tárgy: ' + res.detailedMatch.matchedSubjName + ')'
return {
m: msg,
p: res.match,
header: res.detailedMatch.matchedSubjName,
}
})
}
}
// TODO
function ShowAnswers(answers, question) {
assert(answers)
if (answers.length > 0) {
// if there are more than 0 answer
ShowMessage(answers)
} else {
ShowMessage(
@ -1240,20 +1215,11 @@
function HandleResults(url) {
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
})
}
function ShowSaveQuizDialog(sendResult, sentData, newQuestions) {
// FIXME: normal string building with localisation :/
var msg = ''
if (sendResult) {
msg = 'Kérdések elküldve, katt az elküldött adatokért.'
@ -1294,15 +1260,17 @@
throw new Error('quiz length is zero!')
}
try {
sentData = {
version: info().script.version,
id: GetId(),
quiz: quiz,
}
try {
sentData.subj = getCurrentSubjectName()
} catch (e) {
sentData.subj = 'NOSUBJ'
Log('unable to get subject name :c')
}
sentData.version = info().script.version
sentData.id = GetId()
sentData.quiz = quiz
console.log('SENT DATA', sentData)
SendXHRMessage('isAdding', sentData).then(res => {
next(res.success, sentData, res.newQuestions)
@ -1319,26 +1287,6 @@
// : 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.
function AddVideoHotkeys(url) {
var seekTime = 20
@ -1502,17 +1450,27 @@
})
const xrow = document.createElement('div')
xrow.setAttribute('id', 'msgHeader')
SetStyle(xrow, {
height: '20px',
display: 'flex',
justifyContent: 'flex-end',
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, {
margin: '5px',
cursor: 'pointer',
position: 'absolute',
right: '0px',
display: 'inline',
})
xButton.addEventListener('mousedown', e => {
e.stopPropagation()
@ -1548,15 +1506,27 @@
var rowThree = table.insertRow() // next suggetsion button
// CELLS -----------------------------------------------------------------------------------------------------
// row one
const sideCellWidth = 30
var numberTextCell = rowOne.insertCell()
SetStyle(numberTextCell, {
width: sideCellWidth + 'px',
})
var questionCell = rowOne.insertCell() // QUESTION CELL
questionCell.setAttribute('id', 'questionCell')
questionCell.rowSpan = 3
questionCell.style.width = '90%'
var prevQuestionCell = rowOne.insertCell()
SetStyle(prevQuestionCell, {
width: sideCellWidth + 'px',
})
// row two
var percentTextCell = rowTwo.insertCell()
SetStyle(percentTextCell, {
width: sideCellWidth + 'px',
})
var nextQuestionCell = rowTwo.insertCell()
SetStyle(nextQuestionCell, {
width: sideCellWidth + 'px',
})
// row three
var prevSuggestionCell = rowThree.insertCell()
var nextSuggestionCell = rowThree.insertCell()
@ -1565,6 +1535,7 @@
// PERCENT TEXT SETUP -----------------------------------------------------------------------------------------------------
var percentTextBox = CreateNodeWithText(percentTextCell, '')
percentTextBox.setAttribute('id', 'percentTextBox')
percentTextBox.title = 'Egyezés %'
if (matchPercent) {
// if match percent param is not null
@ -1573,6 +1544,7 @@
// NUMBER SETUP -----------------------------------------------------------------------------------------------------
var numberTextBox = CreateNodeWithText(numberTextCell, '1.')
numberTextBox.setAttribute('id', 'numberTextBox')
numberTextBox.title = 'Lehetséges válasz index'
// ANSWER NODE SETUP -------------------------------------------------------------------------------------------------------------
var questionTextElement = CreateNodeWithText(
@ -1621,10 +1593,10 @@
}
const SetQuestionText = () => {
var relevantQuestion = GetRelevantQuestion()
questionTextElement.innerText = removeUnnecesarySpaces(
relevantQuestion.m
)
const relevantQuestion = GetRelevantQuestion()
questionTextElement.innerText = relevantQuestion.m
headerText.innerText = relevantQuestion.header
if (currItem === 0 && currRelevantQuestion === 0) {
numberTextBox.innerText = currRelevantQuestion + 1 + '.'
} else {
@ -1651,6 +1623,7 @@
'⬅️',
'div'
)
prevSuggButton.title = 'Előző lehetséges válasz'
SetStyle(prevSuggButton, buttonStyle)
prevSuggButton.addEventListener('mousedown', function(e) {
@ -1664,6 +1637,7 @@
'➡️',
'div'
)
nextSuggButton.title = 'Következő lehetséges válasz'
SetStyle(nextSuggButton, buttonStyle)
nextSuggButton.addEventListener('mousedown', function(e) {
@ -1680,6 +1654,7 @@
// PREV QUESTION BUTTON ------------------------------------------------------------------------------------------------------------
var prevButton = CreateNodeWithText(prevQuestionCell, '⬆️', 'div')
SetStyle(prevButton, buttonStyle)
prevButton.title = 'Előző kérdés'
// event listener
prevButton.addEventListener('click', function() {
@ -1689,6 +1664,7 @@
// NEXT QUESTION BUTTON ------------------------------------------------------------------------------------------------------------
var nextButton = CreateNodeWithText(nextQuestionCell, '⬇️', 'div')
SetStyle(nextButton, buttonStyle)
nextButton.title = 'Előző kérdés'
// event listener
nextButton.addEventListener('click', function() {
@ -1770,6 +1746,21 @@
color: '#ffffff',
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 ----------------------------------------------------------------------------------------------------------------
let helpButton = CreateNodeWithText(buttonCell, texts.help, 'button')
SetStyle(helpButton, buttonStyle)
@ -1785,7 +1776,6 @@
texts.contribute,
'button'
)
contributeLink.title = texts.contributeTitle
SetStyle(contributeLink, buttonStyle)
contributeLink.addEventListener('click', function() {
@ -1801,22 +1791,17 @@
SetStyle(pwRequest, buttonStyle)
pwRequest.addEventListener('click', function() {
openInTab(serverAdress + 'pwRequest', {
openInTab(serverAdress + 'pwRequest?scriptMenu', {
active: true,
})
})
// IRC ----------------------------------------------------------------------------------------------------------------
// site link ----------------------------------------------------------------------------------------------------------------
let siteLink = CreateNodeWithText(
buttonCell,
texts.websiteBugreport,
'button'
)
SetStyle(siteLink, buttonStyle)
siteLink.addEventListener('click', function() {
openInTab(serverAdress + 'menuClick', {
let ircButton2 = CreateNodeWithText(buttonCell, texts.ircButton, 'button')
ircButton2.title = texts.ircButtonTitle
SetStyle(ircButton2, buttonStyle)
ircButton2.addEventListener('click', function() {
openInTab(serverAdress + 'irc?scriptMenu', {
active: true,
})
})