From 82b1bd075cebe6a16dbaab7f57d949fdeb73f438 Mon Sep 17 00:00:00 2001 From: mrfry Date: Sat, 19 Dec 2020 15:00:24 +0100 Subject: [PATCH] Script header changes, show help query, other minor changes --- stable.user.js | 69 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 10 deletions(-) diff --git a/stable.user.js b/stable.user.js index 737b2dd..88d841c 100755 --- a/stable.user.js +++ b/stable.user.js @@ -2,7 +2,6 @@ /* ---------------------------------------------------------------------------- Online Moodle/Elearning/KMOOC test help - Greasyfork: GitLab: This program is free software: you can redistribute it and/or modify @@ -19,6 +18,30 @@ along with this program. If not, see . ------------------------------------------------------------------------- */ +// : 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 {{{ // ==UserScript== @@ -30,6 +53,7 @@ // @match https://elearning.uni-obuda.hu/kmooc/* // @match https://mooc.unideb.hu/* // @match https://itc.semmelweis.hu/moodle/* +// @match https://oktatas.mai.kvk.uni-obuda.hu/* // @match https://qmining.frylabs.net/* // @match http://qmining.frylabs.net/* // @noframes @@ -88,7 +112,7 @@ // forcing pages for testing. unless you test, do not set these to true! setVal('ISDEVEL', true) // only one of these should be true for testing - const forceTestPage = false + const forceTestPage = true const forceResultPage = 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 => { removeLoadingMessage() ShowAnswers(results) @@ -476,7 +519,7 @@ ]) const data = getDataFromTest( images, - possibleAnswerArray, + possibleAnswers, getLegacyImageID(imageNodes) ) @@ -1077,7 +1120,7 @@ } function Auth(pw) { - SendXHRMessage('login', { pw: pw, script: true }).then(res => { + post('login', { pw: pw, script: true }).then(res => { if (res.result === 'success') { ConnectToServer(AfterLoad) ClearAllMessages() @@ -1380,7 +1423,7 @@ log('unable to get subject name :c') } console.log('SENT DATA', sentData) - SendXHRMessage('isAdding', sentData).then(res => { + post('isAdding', sentData).then(res => { next(res.success, sentData, res.newQuestions) }) } catch (e) { @@ -1410,7 +1453,8 @@ var firstRun = getVal('firstRun') // if the current run is the frst if (firstRun === undefined || firstRun === true) { 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.close() @@ -1505,6 +1549,7 @@ let currOpacity = getVal(`${elem.id}_opacity`) elem.addEventListener('mousewheel', e => { + e.preventDefault() const isUp = e.deltaY < 0 if (isUp) { if (currOpacity + messageOpacityDelta <= 1) { @@ -2359,7 +2404,7 @@ }) } - function SendXHRMessage(path, message) { + function post(path, message) { if (typeof message === 'object') { message = JSON.stringify(message) } @@ -2383,7 +2428,7 @@ const res = JSON.parse(resp.responseText) resolve(res) } catch (e) { - log('Error paring JSON in SendXHRMessage') + log('Error paring JSON in post') log(resp.responseText) log(e) reject(e) @@ -2417,8 +2462,12 @@ // : Help {{{ // shows some neat help - function ShowHelp() { - openInTab(serverAdress + 'manual?scriptMenu', { + function ShowHelp(query) { + let q = 'scriptMenu' + if (query) { + q = query + } + openInTab(serverAdress + `manual?${q}`, { active: true, }) }