Script header changes, show help query, other minor changes

This commit is contained in:
mrfry 2020-12-19 15:00:24 +01:00
parent dea0b115b7
commit 82b1bd075c

View file

@ -2,7 +2,6 @@
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
Online Moodle/Elearning/KMOOC test help Online Moodle/Elearning/KMOOC test help
Greasyfork: <https://greasyfork.org/en/scripts/38999-moodle-elearning-kmooc-test-help>
GitLab: <https://gitlab.com/MrFry/moodle-test-userscript> GitLab: <https://gitlab.com/MrFry/moodle-test-userscript>
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
@ -19,6 +18,30 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
------------------------------------------------------------------------- */ ------------------------------------------------------------------------- */
// : Install info {{{
// ===============================================================================
// ===============================================================================
//
// HA EZT LÁTOD, ÉS TELEPÍTENI AKARTAD A SCRIPTET, AKKOR
// NINCS USERSCRIPT KEZELŐ BŐVÍTMÉNYED.
//
// Telepíts egy userscript kezelőt, például a Tampermonkey-t:
// https://www.tampermonkey.net/
//
// ===============================================================================
//
// IF YOU ARE SEEING THIS MESSAGE, AND YOU WANTED TO
// INSTALL THIS SCRIPT, THEN YOU DON'T HAVE ANY USERSCRIPT
// MANAGER INSTALLED.
//
// Install a userscript manager, for example Tampermonkey:
// https://www.tampermonkey.net/
//
// ===============================================================================
// ===============================================================================
// : }}}
// : Script header {{{ // : Script header {{{
// ==UserScript== // ==UserScript==
@ -30,6 +53,7 @@
// @match https://elearning.uni-obuda.hu/kmooc/* // @match https://elearning.uni-obuda.hu/kmooc/*
// @match https://mooc.unideb.hu/* // @match https://mooc.unideb.hu/*
// @match https://itc.semmelweis.hu/moodle/* // @match https://itc.semmelweis.hu/moodle/*
// @match https://oktatas.mai.kvk.uni-obuda.hu/*
// @match https://qmining.frylabs.net/* // @match https://qmining.frylabs.net/*
// @match http://qmining.frylabs.net/* // @match http://qmining.frylabs.net/*
// @noframes // @noframes
@ -88,7 +112,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 = false const forceTestPage = true
const forceResultPage = false const forceResultPage = false
const forceDefaultPage = false const forceDefaultPage = false
@ -327,6 +351,25 @@
) )
}) })
// const questions = res.map(question => {
// return {
// q: question.question,
// data: question.data,
// subj: getCurrentSubjectName(),
// }
// })
// console.log(questions)
// post('ask', {
// questions: questions,
// location: location.href,
// version: info().script.version,
// cid: cid,
// uid: uid,
// }).then(results => {
// console.log('RES')
// console.log(results)
Promise.all(promises).then(results => { Promise.all(promises).then(results => {
removeLoadingMessage() removeLoadingMessage()
ShowAnswers(results) ShowAnswers(results)
@ -476,7 +519,7 @@
]) ])
const data = getDataFromTest( const data = getDataFromTest(
images, images,
possibleAnswerArray, possibleAnswers,
getLegacyImageID(imageNodes) getLegacyImageID(imageNodes)
) )
@ -1077,7 +1120,7 @@
} }
function Auth(pw) { function Auth(pw) {
SendXHRMessage('login', { pw: pw, script: true }).then(res => { post('login', { pw: pw, script: true }).then(res => {
if (res.result === 'success') { if (res.result === 'success') {
ConnectToServer(AfterLoad) ConnectToServer(AfterLoad)
ClearAllMessages() ClearAllMessages()
@ -1380,7 +1423,7 @@
log('unable to get subject name :c') log('unable to get subject name :c')
} }
console.log('SENT DATA', sentData) console.log('SENT DATA', sentData)
SendXHRMessage('isAdding', sentData).then(res => { post('isAdding', sentData).then(res => {
next(res.success, sentData, res.newQuestions) next(res.success, sentData, res.newQuestions)
}) })
} catch (e) { } catch (e) {
@ -1410,7 +1453,8 @@
var firstRun = getVal('firstRun') // if the current run is the frst var firstRun = getVal('firstRun') // if the current run is the frst
if (firstRun === undefined || firstRun === true) { if (firstRun === undefined || firstRun === true) {
setVal('firstRun', false) setVal('firstRun', false)
ShowHelp() // showing help // TODO: add install source to query. Maybe even a new api endpoint to register installion
ShowHelp('firstRun') // showing help
document.write(texts.freshStartWarning) document.write(texts.freshStartWarning)
document.close() document.close()
@ -1505,6 +1549,7 @@
let currOpacity = getVal(`${elem.id}_opacity`) let currOpacity = getVal(`${elem.id}_opacity`)
elem.addEventListener('mousewheel', e => { elem.addEventListener('mousewheel', e => {
e.preventDefault()
const isUp = e.deltaY < 0 const isUp = e.deltaY < 0
if (isUp) { if (isUp) {
if (currOpacity + messageOpacityDelta <= 1) { if (currOpacity + messageOpacityDelta <= 1) {
@ -2359,7 +2404,7 @@
}) })
} }
function SendXHRMessage(path, message) { function post(path, message) {
if (typeof message === 'object') { if (typeof message === 'object') {
message = JSON.stringify(message) message = JSON.stringify(message)
} }
@ -2383,7 +2428,7 @@
const res = JSON.parse(resp.responseText) const res = JSON.parse(resp.responseText)
resolve(res) resolve(res)
} catch (e) { } catch (e) {
log('Error paring JSON in SendXHRMessage') log('Error paring JSON in post')
log(resp.responseText) log(resp.responseText)
log(e) log(e)
reject(e) reject(e)
@ -2417,8 +2462,12 @@
// : Help {{{ // : Help {{{
// shows some neat help // shows some neat help
function ShowHelp() { function ShowHelp(query) {
openInTab(serverAdress + 'manual?scriptMenu', { let q = 'scriptMenu'
if (query) {
q = query
}
openInTab(serverAdress + `manual?${q}`, {
active: true, active: true,
}) })
} }