mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
eslint format, site match order change
This commit is contained in:
parent
00ceb74ba7
commit
27211c7bc8
1 changed files with 119 additions and 118 deletions
237
stable.user.js
237
stable.user.js
|
@ -55,9 +55,8 @@
|
|||
// @match https://itc.semmelweis.hu/moodle/*
|
||||
// @match https://moodle.gtk.uni-pannon.hu/*
|
||||
// @match https://oktatas.mai.kvk.uni-obuda.hu/*
|
||||
// @match https://qmining.frylabs.net/*
|
||||
// @match http://qmining.frylabs.net/*
|
||||
// @noframes
|
||||
// @match https://qmining.frylabs.net/*
|
||||
// @run-at document-start
|
||||
// @grant GM_getResourceText
|
||||
// @grant GM_info
|
||||
|
@ -75,7 +74,7 @@
|
|||
// ==/UserScript==
|
||||
// : }}}
|
||||
|
||||
;(function() {
|
||||
;(function () {
|
||||
// : ESLINT bs {{{
|
||||
|
||||
// eslint-disable-line
|
||||
|
@ -250,7 +249,7 @@
|
|||
if (select.length > 0) {
|
||||
// test: 2c1d92a7-0ea2-4990-9451-7f19299bbbe4
|
||||
const question = []
|
||||
Array.from(elem.childNodes).forEach(cn => {
|
||||
Array.from(elem.childNodes).forEach((cn) => {
|
||||
if (cn.nodeValue) {
|
||||
question.push(cn.nodeValue)
|
||||
}
|
||||
|
@ -265,8 +264,8 @@
|
|||
|
||||
if (img.tagName === 'IMG') {
|
||||
promises.push(
|
||||
new Promise(resolve => {
|
||||
digestMessage(getBase64Image(img)).then(res => {
|
||||
new Promise((resolve) => {
|
||||
digestMessage(getBase64Image(img)).then((res) => {
|
||||
resolve({
|
||||
type: 'img',
|
||||
val: res,
|
||||
|
@ -312,7 +311,7 @@
|
|||
|
||||
function getLegacyImageID(imgArray) {
|
||||
try {
|
||||
return imgArray.map(img => {
|
||||
return imgArray.map((img) => {
|
||||
if (!img.src.includes('brokenfile')) {
|
||||
let filePart = img.src.split('/')
|
||||
filePart = filePart[filePart.length - 1]
|
||||
|
@ -350,7 +349,7 @@
|
|||
)
|
||||
|
||||
getQuizData()
|
||||
.then(readQuestions => {
|
||||
.then((readQuestions) => {
|
||||
if (readQuestions.length === 0) {
|
||||
warn('readQuestions length is zero, no questions found on page!')
|
||||
ShowMessage(
|
||||
|
@ -366,7 +365,7 @@
|
|||
return
|
||||
}
|
||||
|
||||
const questions = readQuestions.map(question => {
|
||||
const questions = readQuestions.map((question) => {
|
||||
return {
|
||||
Q: question.question,
|
||||
possibleAnswers: question.possibleAnswers,
|
||||
|
@ -385,7 +384,7 @@
|
|||
|
||||
log(sentData)
|
||||
|
||||
post('ask', sentData).then(results => {
|
||||
post('ask', sentData).then((results) => {
|
||||
removeLoadingMessage()
|
||||
ShowAnswers(
|
||||
results.map((res, i) => {
|
||||
|
@ -397,7 +396,7 @@
|
|||
)
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
warn(err)
|
||||
warn('Error in handleQuiz()')
|
||||
})
|
||||
|
@ -410,7 +409,7 @@
|
|||
document.getElementsByTagName('form')[0].childNodes[0].childNodes
|
||||
)
|
||||
// test: e2c01ff4-d97a-4ab9-8f7f-e28812541097
|
||||
const notOnlyTextNodes = questionNodes.every(node => {
|
||||
const notOnlyTextNodes = questionNodes.every((node) => {
|
||||
return node.tagName !== undefined
|
||||
})
|
||||
return notOnlyTextNodes && questionNodes.length > 0
|
||||
|
@ -439,7 +438,7 @@
|
|||
function getQuestionNodes() {
|
||||
try {
|
||||
let questionNodes
|
||||
Object.keys(questionNodeVariants).some(key => {
|
||||
Object.keys(questionNodeVariants).some((key) => {
|
||||
const variant = questionNodeVariants[key]
|
||||
if (variant.criteria()) {
|
||||
questionNodes = variant.getter()
|
||||
|
@ -460,7 +459,7 @@
|
|||
}
|
||||
|
||||
function getQuizData() {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
// TODO: dropdown in question
|
||||
// TODO: get possible answers too
|
||||
const promises = []
|
||||
|
@ -477,7 +476,7 @@
|
|||
}
|
||||
|
||||
Promise.all(promises)
|
||||
.then(result => {
|
||||
.then((result) => {
|
||||
const errorsRemoved = result.reduce((acc, res) => {
|
||||
if (res.success) {
|
||||
acc.push(res)
|
||||
|
@ -486,7 +485,7 @@
|
|||
}, [])
|
||||
resolve(errorsRemoved)
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
warn('Error in handleQuiz()')
|
||||
warn(err)
|
||||
})
|
||||
|
@ -515,7 +514,7 @@
|
|||
const select = node.getElementsByTagName('select')[0]
|
||||
if (select) {
|
||||
const options = []
|
||||
Array.from(select).forEach(opt => {
|
||||
Array.from(select).forEach((opt) => {
|
||||
if (!emptyOrWhiteSpace(opt.innerText)) {
|
||||
options.push([{ type: 'txt', val: opt.innerText }])
|
||||
}
|
||||
|
@ -526,7 +525,7 @@
|
|||
} else if (answerRoot.tagName === 'DIV') {
|
||||
const answers = Array.from(answerRoot.childNodes)
|
||||
|
||||
answers.forEach(answer => {
|
||||
answers.forEach((answer) => {
|
||||
if (answer.tagName) {
|
||||
promises.push(getTextPromisesFromNode(answer))
|
||||
}
|
||||
|
@ -537,7 +536,7 @@
|
|||
const answers = Array.from(answerRoot.childNodes[0].childNodes)
|
||||
// test: 002203ca-581b-445c-b45d-85374f212e8e NOT WORING
|
||||
|
||||
answers.forEach(answer => {
|
||||
answers.forEach((answer) => {
|
||||
if (answer.tagName) {
|
||||
// test: 817434df-a103-4edc-870e-c9ac953404dc
|
||||
promises.push(
|
||||
|
@ -559,7 +558,7 @@
|
|||
function getImgNodesFromArray(arr) {
|
||||
return arr.reduce((acc, x) => {
|
||||
if (Array.isArray(x)) {
|
||||
x.forEach(y => {
|
||||
x.forEach((y) => {
|
||||
if (y.type === 'img') {
|
||||
acc.push(y.node)
|
||||
}
|
||||
|
@ -575,34 +574,34 @@
|
|||
|
||||
const rootVariants = {
|
||||
qtext: {
|
||||
criteria: node => {
|
||||
criteria: (node) => {
|
||||
return node.getElementsByClassName('qtext').length > 0
|
||||
},
|
||||
getter: node => {
|
||||
getter: (node) => {
|
||||
return node.getElementsByClassName('qtext')[0]
|
||||
},
|
||||
},
|
||||
subquestion: {
|
||||
criteria: node => {
|
||||
criteria: (node) => {
|
||||
return node.getElementsByClassName('subquestion').length > 0
|
||||
},
|
||||
getter: node => {
|
||||
getter: (node) => {
|
||||
return node.getElementsByClassName('subquestion')[0].parentNode
|
||||
},
|
||||
},
|
||||
content: {
|
||||
// test: 002203ca-581b-445c-b45d-85374f212e8e
|
||||
criteria: node => {
|
||||
criteria: (node) => {
|
||||
return node.getElementsByClassName('content').length > 0
|
||||
},
|
||||
getter: node => {
|
||||
getter: (node) => {
|
||||
const content = node.getElementsByClassName('content')[0].childNodes[0]
|
||||
const pNodes = Array.from(content.childNodes).filter(node => {
|
||||
const pNodes = Array.from(content.childNodes).filter((node) => {
|
||||
return node.tagName === 'P'
|
||||
})
|
||||
|
||||
const parent = document.createElement('div')
|
||||
pNodes.forEach(node => {
|
||||
pNodes.forEach((node) => {
|
||||
parent.appendChild(node.cloneNode(true))
|
||||
})
|
||||
|
||||
|
@ -614,7 +613,7 @@
|
|||
function getQuestionRootNode(node) {
|
||||
try {
|
||||
let qtextNode
|
||||
Object.keys(rootVariants).some(key => {
|
||||
Object.keys(rootVariants).some((key) => {
|
||||
const variant = rootVariants[key]
|
||||
if (variant.criteria(node)) {
|
||||
qtextNode = variant.getter(node)
|
||||
|
@ -635,14 +634,14 @@
|
|||
}
|
||||
|
||||
function getQuestionPromiseForSingleQuestion(node) {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
try {
|
||||
const qtextNode = getQuestionRootNode(node)
|
||||
const questionPromises = getTextPromisesFromNode(qtextNode)
|
||||
const possibleAnswerPromises = getPossibleAnswersFromTest(node)
|
||||
|
||||
const unflattenedPossibleAnswerPromises = possibleAnswerPromises
|
||||
? possibleAnswerPromises.map(x => {
|
||||
? possibleAnswerPromises.map((x) => {
|
||||
return Promise.all(x)
|
||||
})
|
||||
: []
|
||||
|
@ -655,7 +654,7 @@
|
|||
const questionText = removeUnnecesarySpaces(
|
||||
question.reduce(makeTextFromElements, []).join(' ')
|
||||
)
|
||||
const possibleAnswers = possibleAnswerArray.map(x => {
|
||||
const possibleAnswers = possibleAnswerArray.map((x) => {
|
||||
return removeUnnecesarySpaces(
|
||||
x.reduce(makeTextFromElements, []).join(' ')
|
||||
)
|
||||
|
@ -684,7 +683,7 @@
|
|||
success: true,
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
warn('Error in getQuestionPromiseForSingleQuestion()')
|
||||
warn(err)
|
||||
resolve({ success: false })
|
||||
|
@ -701,7 +700,7 @@
|
|||
if (hashedImages.length > 0) {
|
||||
return {
|
||||
type: 'image',
|
||||
hashedImages: hashedImages.map(x => {
|
||||
hashedImages: hashedImages.map((x) => {
|
||||
return x.val
|
||||
}),
|
||||
images: legacyImages,
|
||||
|
@ -722,7 +721,7 @@
|
|||
function getResultNodes() {
|
||||
try {
|
||||
let resultNodes
|
||||
Object.keys(resultNodeVariants).some(key => {
|
||||
Object.keys(resultNodeVariants).some((key) => {
|
||||
const variant = resultNodeVariants[key]
|
||||
if (variant.criteria()) {
|
||||
resultNodes = variant.getter()
|
||||
|
@ -743,7 +742,7 @@
|
|||
}
|
||||
|
||||
function getQuiz() {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
const promises = []
|
||||
const questionNodes = getResultNodes()
|
||||
// let questionNodes = Array.from(
|
||||
|
@ -762,7 +761,7 @@
|
|||
}
|
||||
|
||||
Promise.all(promises)
|
||||
.then(result => {
|
||||
.then((result) => {
|
||||
const errorsRemoved = result.reduce((acc, res) => {
|
||||
if (res.success) {
|
||||
acc.push(res)
|
||||
|
@ -771,7 +770,7 @@
|
|||
}, [])
|
||||
resolve(errorsRemoved)
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
warn('Error in getQuiz()')
|
||||
warn(err)
|
||||
})
|
||||
|
@ -780,7 +779,7 @@
|
|||
|
||||
function getPromisesThatMeetsRequirements(getters, node) {
|
||||
let res
|
||||
Object.keys(getters).some(key => {
|
||||
Object.keys(getters).some((key) => {
|
||||
const getter = getters[key]
|
||||
if (getter.requirement(node)) {
|
||||
try {
|
||||
|
@ -798,7 +797,7 @@
|
|||
}
|
||||
|
||||
function getQuizFromNode(node) {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
try {
|
||||
const questionPromises = getPromisesThatMeetsRequirements(
|
||||
questionGetters,
|
||||
|
@ -835,7 +834,7 @@
|
|||
result.data.possibleAnswers = possibleAnswers
|
||||
resolve(result)
|
||||
})
|
||||
.catch(err => {
|
||||
.catch((err) => {
|
||||
warn('Error in getQuizFromNode()')
|
||||
warn(err)
|
||||
resolve({ success: false })
|
||||
|
@ -852,7 +851,7 @@
|
|||
if (images && images.length > 0) {
|
||||
return {
|
||||
type: 'image',
|
||||
hashedImages: images.map(x => {
|
||||
hashedImages: images.map((x) => {
|
||||
return x.val
|
||||
}),
|
||||
}
|
||||
|
@ -866,10 +865,10 @@
|
|||
const questionGetters = {
|
||||
getSimpleQuestion: {
|
||||
description: 'Basic question getter',
|
||||
requirement: node => {
|
||||
requirement: (node) => {
|
||||
return node.getElementsByClassName('qtext').length > 0
|
||||
},
|
||||
getterFunction: node => {
|
||||
getterFunction: (node) => {
|
||||
const question = node.getElementsByClassName('qtext')[0]
|
||||
return getTextPromisesFromNode(question)
|
||||
},
|
||||
|
@ -879,23 +878,23 @@
|
|||
const answerGetters = {
|
||||
getSimpleAnswer: {
|
||||
description: 'Basic answer getter',
|
||||
requirement: node => {
|
||||
requirement: (node) => {
|
||||
return node.getElementsByClassName('rightanswer').length > 0
|
||||
},
|
||||
getterFunction: node => {
|
||||
getterFunction: (node) => {
|
||||
const answer = node.getElementsByClassName('rightanswer')[0]
|
||||
return getTextPromisesFromNode(answer)
|
||||
},
|
||||
},
|
||||
noCorrect: {
|
||||
description: 'Gets correct answer, even if the correct is not shown',
|
||||
requirement: node => {
|
||||
requirement: (node) => {
|
||||
return (
|
||||
node.getElementsByClassName('rightanswer').length === 0 &&
|
||||
node.getElementsByClassName('answer').length > 0
|
||||
)
|
||||
},
|
||||
getterFunction: node => {
|
||||
getterFunction: (node) => {
|
||||
const possibleAnswers = getPossibleAnswers(node)
|
||||
|
||||
if (getIfSolutionIsCorrect(node)) {
|
||||
|
@ -903,7 +902,7 @@
|
|||
return [
|
||||
{
|
||||
type: 'txt',
|
||||
val: possibleAnswers.find(x => {
|
||||
val: possibleAnswers.find((x) => {
|
||||
return x.selectedByUser === false
|
||||
}).text,
|
||||
},
|
||||
|
@ -918,7 +917,7 @@
|
|||
return [
|
||||
{
|
||||
type: 'txt',
|
||||
val: possibleAnswers.find(x => {
|
||||
val: possibleAnswers.find((x) => {
|
||||
return x.selectedByUser === true
|
||||
}).text,
|
||||
},
|
||||
|
@ -928,30 +927,30 @@
|
|||
},
|
||||
getDropdownAnswer: {
|
||||
description: 'Dropdown answer getter',
|
||||
requirement: node => {
|
||||
requirement: (node) => {
|
||||
return false
|
||||
},
|
||||
getterFunction: node => {
|
||||
getterFunction: (node) => {
|
||||
// TODO dropdown kérdés.html
|
||||
return 'asd'
|
||||
},
|
||||
},
|
||||
getTextareaAnswer: {
|
||||
description: 'Get complex answer',
|
||||
requirement: node => {
|
||||
requirement: (node) => {
|
||||
return false
|
||||
},
|
||||
getterFunction: node => {
|
||||
getterFunction: (node) => {
|
||||
// TODO Ugrás... bug.html
|
||||
return 'asd'
|
||||
},
|
||||
},
|
||||
getDragBoxAnswer: {
|
||||
description: 'Get complex answer',
|
||||
requirement: node => {
|
||||
requirement: (node) => {
|
||||
return false
|
||||
},
|
||||
getterFunction: node => {
|
||||
getterFunction: (node) => {
|
||||
// TODO dragboxes
|
||||
return 'asd'
|
||||
},
|
||||
|
@ -991,7 +990,7 @@
|
|||
const select = node.getElementsByTagName('select')[0]
|
||||
if (select) {
|
||||
const options = []
|
||||
Array.from(select.childNodes).forEach(opt => {
|
||||
Array.from(select.childNodes).forEach((opt) => {
|
||||
if (!emptyOrWhiteSpace(opt.innerText)) {
|
||||
options.push(opt.innerText)
|
||||
}
|
||||
|
@ -1007,10 +1006,10 @@
|
|||
}
|
||||
|
||||
function digestMessage(message) {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
const encoder = new TextEncoder()
|
||||
const data = encoder.encode(message)
|
||||
crypto.subtle.digest('SHA-256', data).then(buf => {
|
||||
crypto.subtle.digest('SHA-256', data).then((buf) => {
|
||||
let res = String.fromCharCode.apply(null, new Uint8Array(buf))
|
||||
res = btoa(res)
|
||||
.replace(/=/g, '')
|
||||
|
@ -1098,7 +1097,7 @@
|
|||
})
|
||||
|
||||
const getHostHandler = {
|
||||
apply: function() {
|
||||
apply: function () {
|
||||
const result = apply(...arguments)
|
||||
return result === shadowRootNewHost ? shadowRootHost : result
|
||||
},
|
||||
|
@ -1274,7 +1273,7 @@
|
|||
if (!sideLinks) {
|
||||
return
|
||||
}
|
||||
Array.from(sideLinks.childNodes).forEach(link => {
|
||||
Array.from(sideLinks.childNodes).forEach((link) => {
|
||||
link.addEventListener('mousedown', () => {
|
||||
FillFeedbackCID(url, link)
|
||||
})
|
||||
|
@ -1316,13 +1315,13 @@
|
|||
}
|
||||
|
||||
try {
|
||||
addEventListener = (function() {
|
||||
addEventListener = (function () {
|
||||
if (document.addEventListener) {
|
||||
return function(element, event, handler) {
|
||||
return function (element, event, handler) {
|
||||
element.addEventListener(event, handler, false)
|
||||
}
|
||||
} else {
|
||||
return function(element, event, handler) {
|
||||
return function (element, event, handler) {
|
||||
element.attachEvent('on' + event, handler)
|
||||
}
|
||||
}
|
||||
|
@ -1338,13 +1337,13 @@
|
|||
}
|
||||
|
||||
function Auth(pw) {
|
||||
post('login', { pw: pw, script: true }).then(res => {
|
||||
post('login', { pw: pw, script: true }).then((res) => {
|
||||
if (res.result === 'success') {
|
||||
ConnectToServer(AfterLoad)
|
||||
clearAllMessages()
|
||||
resetMenu()
|
||||
} else {
|
||||
SafeGetElementById('infoMainDiv', elem => {
|
||||
SafeGetElementById('infoMainDiv', (elem) => {
|
||||
elem.innerText = texts.invalidPW + pw
|
||||
})
|
||||
}
|
||||
|
@ -1352,16 +1351,16 @@
|
|||
}
|
||||
|
||||
function resetMenu() {
|
||||
SafeGetElementById('scriptMenuDiv', elem => {
|
||||
SafeGetElementById('scriptMenuDiv', (elem) => {
|
||||
elem.style.backgroundColor = '#262626'
|
||||
})
|
||||
SafeGetElementById('retryContainer', elem => {
|
||||
SafeGetElementById('retryContainer', (elem) => {
|
||||
elem.style.display = 'none'
|
||||
})
|
||||
SafeGetElementById('loginDiv', elem => {
|
||||
SafeGetElementById('loginDiv', (elem) => {
|
||||
elem.style.display = 'none'
|
||||
})
|
||||
SafeGetElementById('infoMainDiv', elem => {
|
||||
SafeGetElementById('infoMainDiv', (elem) => {
|
||||
elem.innerText = texts.loading
|
||||
})
|
||||
}
|
||||
|
@ -1369,7 +1368,7 @@
|
|||
function ConnectToServer(cwith) {
|
||||
clearAllMessages()
|
||||
GetXHRInfos()
|
||||
.then(inf => {
|
||||
.then((inf) => {
|
||||
if (inf.result === 'nouser') {
|
||||
NoUserAction()
|
||||
return
|
||||
|
@ -1401,25 +1400,25 @@
|
|||
}
|
||||
|
||||
function NoUserAction() {
|
||||
SafeGetElementById('scriptMenuDiv', elem => {
|
||||
SafeGetElementById('scriptMenuDiv', (elem) => {
|
||||
elem.style.backgroundColor = '#44cc00'
|
||||
})
|
||||
SafeGetElementById('infoMainDiv', elem => {
|
||||
SafeGetElementById('infoMainDiv', (elem) => {
|
||||
elem.innerText = ''
|
||||
})
|
||||
SafeGetElementById('loginDiv', elem => {
|
||||
SafeGetElementById('loginDiv', (elem) => {
|
||||
elem.style.display = 'flex'
|
||||
})
|
||||
}
|
||||
|
||||
function NoServerAction() {
|
||||
SafeGetElementById('scriptMenuDiv', elem => {
|
||||
SafeGetElementById('scriptMenuDiv', (elem) => {
|
||||
elem.style.backgroundColor = 'red'
|
||||
})
|
||||
SafeGetElementById('infoMainDiv', elem => {
|
||||
SafeGetElementById('infoMainDiv', (elem) => {
|
||||
elem.innerText = texts.noServer
|
||||
})
|
||||
SafeGetElementById('retryContainer', elem => {
|
||||
SafeGetElementById('retryContainer', (elem) => {
|
||||
elem.style.display = 'flex'
|
||||
})
|
||||
log(texts.noServerConsoleMessage)
|
||||
|
@ -1501,7 +1500,7 @@
|
|||
function PrepareAnswers(result) {
|
||||
const { answers, question } = result
|
||||
if (answers.length > 0) {
|
||||
return answers.map(answer => {
|
||||
return answers.map((answer) => {
|
||||
const { Q, A, data } = answer.q
|
||||
let msg = Q + '\n' + A
|
||||
|
||||
|
@ -1564,7 +1563,7 @@
|
|||
texts.noResult,
|
||||
|
||||
undefined,
|
||||
function() {
|
||||
function () {
|
||||
OpenErrorPage({
|
||||
message: 'No result found',
|
||||
question: Array.isArray(answers[0])
|
||||
|
@ -1581,7 +1580,7 @@
|
|||
// : Quiz saving {{{
|
||||
|
||||
function HandleResults() {
|
||||
getQuiz().then(res => {
|
||||
getQuiz().then((res) => {
|
||||
SaveQuiz(res, ShowSaveQuizDialog) // saves the quiz questions and answers
|
||||
})
|
||||
}
|
||||
|
@ -1604,7 +1603,7 @@
|
|||
msg,
|
||||
|
||||
null,
|
||||
function() {
|
||||
function () {
|
||||
let towrite = ''
|
||||
try {
|
||||
towrite += '</p>Elküldött adatok:</p> ' + JSON.stringify(sentData)
|
||||
|
@ -1639,7 +1638,7 @@
|
|||
log('unable to get subject name :c')
|
||||
}
|
||||
log('SENT DATA', sentData)
|
||||
post('isAdding', sentData).then(res => {
|
||||
post('isAdding', sentData).then((res) => {
|
||||
next(res.success, sentData, res.totalNewQuestions)
|
||||
})
|
||||
} catch (e) {
|
||||
|
@ -1708,7 +1707,7 @@
|
|||
// this function adds basic hotkeys for video controll.
|
||||
function AddVideoHotkeys() {
|
||||
var seekTime = 20
|
||||
document.addEventListener('keydown', function(e) {
|
||||
document.addEventListener('keydown', function (e) {
|
||||
try {
|
||||
var video = getVideo()
|
||||
var keyCode = e.keyCode // getting keycode
|
||||
|
@ -1748,7 +1747,7 @@
|
|||
// : Show message, and script menu stuff {{{
|
||||
|
||||
function clearAllMessages() {
|
||||
overlay.querySelectorAll('#scriptMessage').forEach(x => x.remove())
|
||||
overlay.querySelectorAll('#scriptMessage').forEach((x) => x.remove())
|
||||
}
|
||||
|
||||
function getConvertedMessageNode(message) {
|
||||
|
@ -1756,7 +1755,7 @@
|
|||
const resultNode = document.createElement('p')
|
||||
messageNode.innerHTML = message.replace(/\n/g, '</br>')
|
||||
|
||||
Array.from(messageNode.childNodes).forEach(node => {
|
||||
Array.from(messageNode.childNodes).forEach((node) => {
|
||||
if (node.tagName === 'A') {
|
||||
const linkNode = document.createElement('span')
|
||||
SetStyle(linkNode, {
|
||||
|
@ -1765,7 +1764,7 @@
|
|||
cursor: 'pointer',
|
||||
})
|
||||
linkNode.innerText = node.innerText
|
||||
linkNode.addEventListener('mousedown', e => {
|
||||
linkNode.addEventListener('mousedown', (e) => {
|
||||
e.stopPropagation()
|
||||
openInTab(node.href, {
|
||||
active: true,
|
||||
|
@ -1787,7 +1786,7 @@
|
|||
}
|
||||
|
||||
let currOpacity = getVal(`${elem.id}_opacity`) || 1
|
||||
elem.addEventListener('wheel', e => {
|
||||
elem.addEventListener('wheel', (e) => {
|
||||
e.preventDefault()
|
||||
const isUp = e.deltaY < 0
|
||||
if (isUp) {
|
||||
|
@ -1871,7 +1870,7 @@
|
|||
let offset = [0, 0]
|
||||
let mousePosition
|
||||
if (movingEnabled) {
|
||||
mainDiv.addEventListener('mousedown', e => {
|
||||
mainDiv.addEventListener('mousedown', (e) => {
|
||||
isMouseDown = true
|
||||
offset = [
|
||||
mainDiv.offsetLeft - e.clientX,
|
||||
|
@ -1881,7 +1880,7 @@
|
|||
mainDiv.addEventListener('mouseup', () => {
|
||||
isMouseDown = false
|
||||
})
|
||||
mainDiv.addEventListener('mousemove', e => {
|
||||
mainDiv.addEventListener('mousemove', (e) => {
|
||||
if (isMouseDown) {
|
||||
mousePosition = {
|
||||
x: e.clientX,
|
||||
|
@ -1901,7 +1900,7 @@
|
|||
display: 'inline',
|
||||
margin: '3px',
|
||||
})
|
||||
xButton.addEventListener('mousedown', e => {
|
||||
xButton.addEventListener('mousedown', (e) => {
|
||||
e.stopPropagation()
|
||||
mainDiv.parentNode.removeChild(mainDiv)
|
||||
})
|
||||
|
@ -1916,7 +1915,7 @@
|
|||
const mesageNode = getConvertedMessageNode(simpleMessageText)
|
||||
|
||||
simpleMessageParagrapg.appendChild(mesageNode)
|
||||
mesageNode.addEventListener('mousedown', e => {
|
||||
mesageNode.addEventListener('mousedown', (e) => {
|
||||
e.stopPropagation()
|
||||
})
|
||||
SetStyle(mesageNode, {
|
||||
|
@ -1924,9 +1923,11 @@
|
|||
cursor: funct ? 'pointer' : 'auto',
|
||||
})
|
||||
|
||||
Array.from(mesageNode.getElementsByTagName('a')).forEach(anchorElem => {
|
||||
anchorElem.style.color = 'lightblue'
|
||||
})
|
||||
Array.from(mesageNode.getElementsByTagName('a')).forEach(
|
||||
(anchorElem) => {
|
||||
anchorElem.style.color = 'lightblue'
|
||||
}
|
||||
)
|
||||
|
||||
mainDiv.appendChild(simpleMessageParagrapg) // adding text box to main div
|
||||
} else {
|
||||
|
@ -2003,7 +2004,7 @@
|
|||
'ur question goes here, mister OwO'
|
||||
)
|
||||
|
||||
questionTextElement.addEventListener('mousedown', e => {
|
||||
questionTextElement.addEventListener('mousedown', (e) => {
|
||||
e.stopPropagation()
|
||||
})
|
||||
|
||||
|
@ -2022,7 +2023,7 @@
|
|||
return msgItem[currItem][currRelevantQuestion]
|
||||
}
|
||||
|
||||
const ChangeCurrItemIndex = to => {
|
||||
const ChangeCurrItemIndex = (to) => {
|
||||
currItem += to
|
||||
if (currItem < 0) {
|
||||
currItem = 0
|
||||
|
@ -2033,7 +2034,7 @@
|
|||
currRelevantQuestion = 0
|
||||
}
|
||||
|
||||
const ChangeCurrRelevantQuestionIndex = to => {
|
||||
const ChangeCurrRelevantQuestionIndex = (to) => {
|
||||
currRelevantQuestion += to
|
||||
if (currRelevantQuestion < 0) {
|
||||
currRelevantQuestion = 0
|
||||
|
@ -2080,7 +2081,7 @@
|
|||
prevSuggButton.title = 'Előző lehetséges válasz'
|
||||
SetStyle(prevSuggButton, buttonStyle)
|
||||
|
||||
prevSuggButton.addEventListener('mousedown', function(e) {
|
||||
prevSuggButton.addEventListener('mousedown', function (e) {
|
||||
e.stopPropagation()
|
||||
ChangeCurrRelevantQuestionIndex(-1)
|
||||
SetQuestionText()
|
||||
|
@ -2094,7 +2095,7 @@
|
|||
nextSuggButton.title = 'Következő lehetséges válasz'
|
||||
SetStyle(nextSuggButton, buttonStyle)
|
||||
|
||||
nextSuggButton.addEventListener('mousedown', function(e) {
|
||||
nextSuggButton.addEventListener('mousedown', function (e) {
|
||||
e.stopPropagation()
|
||||
ChangeCurrRelevantQuestionIndex(1)
|
||||
SetQuestionText()
|
||||
|
@ -2111,7 +2112,7 @@
|
|||
prevButton.title = 'Előző kérdés'
|
||||
|
||||
// event listener
|
||||
prevButton.addEventListener('click', function() {
|
||||
prevButton.addEventListener('click', function () {
|
||||
ChangeCurrItemIndex(-1)
|
||||
SetQuestionText()
|
||||
})
|
||||
|
@ -2121,7 +2122,7 @@
|
|||
nextButton.title = 'Előző kérdés'
|
||||
|
||||
// event listener
|
||||
nextButton.addEventListener('click', function() {
|
||||
nextButton.addEventListener('click', function () {
|
||||
ChangeCurrItemIndex(1)
|
||||
SetQuestionText()
|
||||
})
|
||||
|
@ -2134,18 +2135,18 @@
|
|||
// addEventListener(window, 'scroll', function () {
|
||||
// mainDiv.style.top = (pageYOffset + startFromTop) + 'px';
|
||||
// })
|
||||
addEventListener(window, 'resize', function() {
|
||||
addEventListener(window, 'resize', function () {
|
||||
mainDiv.style.left = (window.innerWidth - width) / 2 + 'px'
|
||||
})
|
||||
var timeOut
|
||||
if (timeout && timeout > 0) {
|
||||
// setting timeout if not zero or null
|
||||
timeOut = setTimeout(function() {
|
||||
timeOut = setTimeout(function () {
|
||||
mainDiv.parentNode.removeChild(mainDiv)
|
||||
}, timeout * 1000)
|
||||
}
|
||||
// middle click close event listener
|
||||
addEventListener(mainDiv, 'mousedown', function(e) {
|
||||
addEventListener(mainDiv, 'mousedown', function (e) {
|
||||
if (e.which === 2) {
|
||||
mainDiv.parentNode.removeChild(mainDiv)
|
||||
if (timeOut) {
|
||||
|
@ -2185,7 +2186,7 @@
|
|||
fontSize: '14px',
|
||||
})
|
||||
|
||||
addEventListener(scriptMenuDiv, 'mousedown', function(e) {
|
||||
addEventListener(scriptMenuDiv, 'mousedown', function (e) {
|
||||
if (e.which === 2) {
|
||||
scriptMenuDiv.parentNode.removeChild(scriptMenuDiv)
|
||||
}
|
||||
|
@ -2203,7 +2204,7 @@
|
|||
fontSize: '18px',
|
||||
})
|
||||
|
||||
xButton.addEventListener('mousedown', e => {
|
||||
xButton.addEventListener('mousedown', (e) => {
|
||||
e.stopPropagation()
|
||||
scriptMenuDiv.parentNode.removeChild(scriptMenuDiv)
|
||||
})
|
||||
|
@ -2220,7 +2221,7 @@
|
|||
fontSize: '30px',
|
||||
})
|
||||
|
||||
mailButton.addEventListener('mousedown', e => {
|
||||
mailButton.addEventListener('mousedown', (e) => {
|
||||
e.stopPropagation()
|
||||
if (userSpecificMotd && !userSpecificMotd.seen) {
|
||||
mailButton.innerText = '📭'
|
||||
|
@ -2258,7 +2259,7 @@
|
|||
cursor: 'pointer',
|
||||
}
|
||||
|
||||
Object.keys(menuButtons).forEach(key => {
|
||||
Object.keys(menuButtons).forEach((key) => {
|
||||
const buttonData = menuButtons[key]
|
||||
const button = CreateNodeWithText(
|
||||
buttonContainer,
|
||||
|
@ -2267,7 +2268,7 @@
|
|||
)
|
||||
SetStyle(button, buttonStyle)
|
||||
if (buttonData.onClick) {
|
||||
button.addEventListener('click', function() {
|
||||
button.addEventListener('click', function () {
|
||||
buttonData.onClick()
|
||||
})
|
||||
}
|
||||
|
@ -2308,7 +2309,7 @@
|
|||
loginContainer.appendChild(loginButton)
|
||||
loginButton.innerText = texts.login
|
||||
SetStyle(loginButton, buttonStyle)
|
||||
loginButton.addEventListener('click', function() {
|
||||
loginButton.addEventListener('click', function () {
|
||||
Auth(loginInput.value)
|
||||
})
|
||||
|
||||
|
@ -2333,7 +2334,7 @@
|
|||
color: '#ffffff',
|
||||
cursor: 'pointer',
|
||||
})
|
||||
retryButton.addEventListener('click', function() {
|
||||
retryButton.addEventListener('click', function () {
|
||||
scriptMenuDiv.style.background = '#262626'
|
||||
infoDiv.innerText = texts.loading
|
||||
retryContainer.style.display = 'none'
|
||||
|
@ -2390,7 +2391,7 @@
|
|||
|
||||
// : }}}
|
||||
|
||||
const assert = val => {
|
||||
const assert = (val) => {
|
||||
if (!val) {
|
||||
throw new Error('Assertion failed')
|
||||
}
|
||||
|
@ -2450,7 +2451,7 @@
|
|||
function SetStyle(target, style) {
|
||||
Object.keys(style)
|
||||
.sort()
|
||||
.forEach(key => {
|
||||
.forEach((key) => {
|
||||
target.style[key] = style[key]
|
||||
})
|
||||
}
|
||||
|
@ -2502,7 +2503,7 @@
|
|||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
onload: function(response) {
|
||||
onload: function (response) {
|
||||
try {
|
||||
setVal('lastInfoCheckTime', now)
|
||||
const res = JSON.parse(response.responseText)
|
||||
|
@ -2515,7 +2516,7 @@
|
|||
reject(e)
|
||||
}
|
||||
},
|
||||
onerror: e => {
|
||||
onerror: (e) => {
|
||||
log('Info get Error', e)
|
||||
reject(e)
|
||||
},
|
||||
|
@ -2549,11 +2550,11 @@
|
|||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
onerror: function(e) {
|
||||
onerror: function (e) {
|
||||
log('Data send error', e)
|
||||
reject(e)
|
||||
},
|
||||
onload: resp => {
|
||||
onload: (resp) => {
|
||||
try {
|
||||
const res = JSON.parse(resp.responseText)
|
||||
resolve(res)
|
||||
|
@ -2571,7 +2572,7 @@
|
|||
function OpenErrorPage(e) {
|
||||
const queries = []
|
||||
try {
|
||||
Object.keys(e).forEach(key => {
|
||||
Object.keys(e).forEach((key) => {
|
||||
if (e[key]) {
|
||||
queries.push(`${key}=${encodeURIComponent(e[key])}`)
|
||||
queries.push('db=all')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue