From daeb08341b700dee93523a4c08e4b35505e6c515 Mon Sep 17 00:00:00 2001 From: MrFry Date: Fri, 3 Apr 2020 17:14:34 +0200 Subject: [PATCH 01/18] Added basic auth --- stable.user.js | 124 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 103 insertions(+), 21 deletions(-) diff --git a/stable.user.js b/stable.user.js index 7248d80..9459c8e 100755 --- a/stable.user.js +++ b/stable.user.js @@ -61,8 +61,8 @@ var addEventListener // add event listener function const serverAdress = 'https://qmining.frylabs.net/' // const serverAdress = 'http://localhost:8080/' - const apiAdress = 'https://api.frylabs.net/' - // const apiAdress = 'http://localhost:8080/' + // const apiAdress = 'https://api.frylabs.net/' + const apiAdress = 'http://localhost:8080/' const ircAddress = 'https://kiwiirc.com/nextclient/irc.sub.fm/#qmining' // forcing pages for testing. unless you test, do not set these to true! @@ -74,7 +74,8 @@ const log = true const motdShowCount = 3 /* Ammount of times to show motd */ - const infoExpireTime = 60 // Every n seconds basic info should be loaded from server + // TODO: set to 60 + const infoExpireTime = 1 // Every n seconds basic info should be loaded from server var motd = '' var lastestVersion = '' var subjInfo @@ -96,9 +97,11 @@ passiveTooltip: 'Ha erre kattintasz akkor a script átálítja a neptunban a hallgatói státuszod passzívra', retry: 'Újrapróbálás', ircButton: 'IRC', + invalidPW: 'Hibás jelszó: ', search: 'Keresés ...', loading: 'Betöltés ...', noServer: 'Nem elérhető a szerver!', + noUser: 'Nem vagy bejelentkezve!', passiveModeActivated: 'Passzív mód bekapcsolva, nem lesz mostantól a szerver piszkálva', passiveModeDeactivated: 'Passzív mód kikapcsolva, frissíts az érvénybe lépéshez!', passiveMode: 'Passzív mód', @@ -728,9 +731,30 @@ } } + function Auth (pw) { + SendXHRMessage('login', { pw: pw, script: true }) + .then((res) => { + if (res.result === 'success') { + setVal('sessionID', res.sessionID) + ConnectToServer(AfterLoad) + ClearAllMessages() + setPassiveButtonState(false) + } else { + SafeGetElementById('infoMainDiv', (elem) => { + elem.innerText = texts.invalidPW + pw + }) + } + }) + } + function ConnectToServer (cwith) { + setVal('sessionID', 'gfdgkldf') ClearAllMessages() GetXHRInfos().then((inf) => { + if (inf.result === 'nouser') { + NoUserAction() + return + } lastestVersion = inf.version motd = inf.motd subjInfo = inf.subjinfo @@ -742,6 +766,18 @@ }) } + function NoUserAction () { + SafeGetElementById('menuButtonDiv', (elem) => { + elem.style.backgroundColor = 'red' + }) + SafeGetElementById('infoMainDiv', (elem) => { + elem.innerText = texts.noUser + }) + SafeGetElementById('loginDiv', (elem) => { + elem.style.display = '' + }) + } + function NoServerAction () { SafeGetElementById('menuButtonDiv', (elem) => { elem.style.backgroundColor = 'red' @@ -1019,7 +1055,7 @@ sentData.id = GetId() sentData.quiz = quiz console.log('SENT DATA', sentData) - SendXHRMessage(JSON.stringify(sentData)).then((res) => { + SendXHRMessage('isAdding', sentData).then((res) => { next(res.success, sentData, res.newQuestions) }) } catch (e) { @@ -1427,7 +1463,7 @@ SetStyle(menuButtonDiv, { // width: buttonWidth + 'px', // height: buttonHeight + 'px', - top: (window.innerHeight - 90) + 'px', + top: (window.innerHeight - 120) + 'px', left: '10px', zIndex: 999999, position: 'fixed', @@ -1506,6 +1542,26 @@ margin: '5px' }) + // login div ---------------------------------------------------------------------------------------------------------------- + const loginDiv = document.createElement('div') + loginDiv.style.display = 'none' + loginDiv.setAttribute('id', 'loginDiv') + const loginButton = document.createElement('button') + loginButton.innerText = 'Login' + const loginInput = document.createElement('input') + loginInput.type = 'text' + + loginDiv.appendChild(loginInput) + loginDiv.appendChild(loginButton) + + SetStyle(loginButton, buttonStyle) + + loginButton.addEventListener('click', function () { + Auth(loginInput.value) + }) + + ibuttonCell.appendChild(loginDiv) + // irc button ---------------------------------------------------------------------------------------------------------------- let ircButton = CreateNodeWithText(ibuttonCell, texts.ircButton, 'button') SetStyle(ircButton, buttonStyle) @@ -1542,16 +1598,9 @@ passiveButton.title = texts.passiveTooltip SetStyle(passiveButton, buttonStyle) - let setPassiveButtonState = (isPassive) => { - menuButtonDiv.style.background = '#262626' - retryButton.style.display = 'none' - ircButton.style.display = 'none' - if (!isPassive) { - infoDiv.innerText = texts.loading - } else { - infoDiv.innerText = texts.passiveModeMenuBoxText - } - } + // APPEND EVERYTHING + appedtTo.appendChild(menuButtonDiv) + setPassiveButtonState(getVal('skipLoad')) passiveButton.addEventListener('click', function () { @@ -1569,13 +1618,35 @@ ConnectToServer(AfterLoad) } }) - - appedtTo.appendChild(menuButtonDiv) } catch (e) { Exception(e, 'script error at showing menu:') } } + function setPassiveButtonState (isPassive) { + SafeGetElementById('menuButtonDiv', (elem) => { + elem.style.backgroundColor = '#262626' + }) + SafeGetElementById('ircButton', (elem) => { + elem.style.display = 'none' + }) + SafeGetElementById('retryButton', (elem) => { + elem.style.display = 'none' + }) + SafeGetElementById('loginDiv', (elem) => { + elem.style.display = 'none' + }) + if (!isPassive) { + SafeGetElementById('infoMainDiv', (elem) => { + elem.innerText = texts.loading + }) + } else { + SafeGetElementById('infoMainDiv', (elem) => { + elem.innerText = texts.passiveModeMenuBoxText + }) + } + } + // : }}} // : Generic utils {{{ @@ -1628,9 +1699,14 @@ info().script.version + '&cid=' + GetId() + console.log(getVal('sessionID')) xmlhttpRequest({ method: 'GET', url: url, + headers: { + 'Cookie': `sessionID=${getVal('sessionID')}`, + 'Content-Type': 'application/json' + }, onload: function (response) { try { setVal('lastInfoCheckTime', now) @@ -1710,15 +1786,21 @@ }) } - function SendXHRMessage (message) { - message = SUtils.RemoveSpecialChars(message) - var url = apiAdress + 'isAdding' + function SendXHRMessage (path, message) { + // message = SUtils.RemoveSpecialChars(message) // TODO: check this + if (typeof message === 'object') { + message = JSON.stringify(message) + } + const url = apiAdress + path return new Promise((resolve, reject) => { + console.log(getVal('sessionID')) xmlhttpRequest({ method: 'POST', url: url, + xhrFields: { withCredentials: true }, data: message, headers: { + 'Cookie': `sessionID=${getVal('sessionID')}`, 'Content-Type': 'application/json' }, onerror: function (e) { @@ -1730,7 +1812,7 @@ const res = JSON.parse(resp.responseText) resolve(res) } catch (e) { - Log('Errro paring JSON in SendXHRMessage') + Log('Error paring JSON in SendXHRMessage') Log(e) reject(e) } From d9f9a16b4980fdf57bdfd4ff426fff7e0a6ed963 Mon Sep 17 00:00:00 2001 From: MrFry Date: Fri, 3 Apr 2020 17:21:48 +0200 Subject: [PATCH 02/18] removed unnecesarry cookie stuff --- stable.user.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/stable.user.js b/stable.user.js index 9459c8e..f58061a 100755 --- a/stable.user.js +++ b/stable.user.js @@ -735,7 +735,6 @@ SendXHRMessage('login', { pw: pw, script: true }) .then((res) => { if (res.result === 'success') { - setVal('sessionID', res.sessionID) ConnectToServer(AfterLoad) ClearAllMessages() setPassiveButtonState(false) @@ -748,7 +747,6 @@ } function ConnectToServer (cwith) { - setVal('sessionID', 'gfdgkldf') ClearAllMessages() GetXHRInfos().then((inf) => { if (inf.result === 'nouser') { @@ -1699,12 +1697,10 @@ info().script.version + '&cid=' + GetId() - console.log(getVal('sessionID')) xmlhttpRequest({ method: 'GET', url: url, headers: { - 'Cookie': `sessionID=${getVal('sessionID')}`, 'Content-Type': 'application/json' }, onload: function (response) { @@ -1793,14 +1789,12 @@ } const url = apiAdress + path return new Promise((resolve, reject) => { - console.log(getVal('sessionID')) xmlhttpRequest({ method: 'POST', url: url, xhrFields: { withCredentials: true }, data: message, headers: { - 'Cookie': `sessionID=${getVal('sessionID')}`, 'Content-Type': 'application/json' }, onerror: function (e) { From 6016b134033723a2fbe6920911c848eebed6a480 Mon Sep 17 00:00:00 2001 From: MrFry Date: Mon, 6 Apr 2020 14:32:26 +0200 Subject: [PATCH 03/18] Added noframes to header --- stable.user.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stable.user.js b/stable.user.js index f58061a..5d03909 100755 --- a/stable.user.js +++ b/stable.user.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 2.0.0.6 +// @version 2.0.0.7 // @description Online Moodle/Elearning/KMOOC test help // @author MrFry // @match https://elearning.uni-obuda.hu/main/* @@ -29,6 +29,7 @@ // @match https://mooc.unideb.hu/* // @match https://qmining.frylabs.net/* // @match http://qmining.frylabs.net/* +// @noframes // @grant GM_getResourceText // @grant GM_info // @grant GM_getValue @@ -1792,7 +1793,7 @@ xmlhttpRequest({ method: 'POST', url: url, - xhrFields: { withCredentials: true }, + // xhrFields: { withCredentials: true }, data: message, headers: { 'Content-Type': 'application/json' From edbafe3d8a028a71e0d261ed24134a3f467388c2 Mon Sep 17 00:00:00 2001 From: MrFry Date: Wed, 8 Apr 2020 13:37:00 +0200 Subject: [PATCH 04/18] Changed not logged in bg color to yellow --- stable.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stable.user.js b/stable.user.js index 5d03909..780b8dc 100755 --- a/stable.user.js +++ b/stable.user.js @@ -767,7 +767,7 @@ function NoUserAction () { SafeGetElementById('menuButtonDiv', (elem) => { - elem.style.backgroundColor = 'red' + elem.style.backgroundColor = '#44cc00' }) SafeGetElementById('infoMainDiv', (elem) => { elem.innerText = texts.noUser From 5ffcdcaf85da04b5d0850f221375c3ab3d99950f Mon Sep 17 00:00:00 2001 From: MrFry Date: Wed, 8 Apr 2020 17:46:33 +0200 Subject: [PATCH 05/18] Redirect to get veteran client id if user has client ID --- stable.user.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/stable.user.js b/stable.user.js index 780b8dc..4dbe908 100755 --- a/stable.user.js +++ b/stable.user.js @@ -63,7 +63,7 @@ const serverAdress = 'https://qmining.frylabs.net/' // const serverAdress = 'http://localhost:8080/' // const apiAdress = 'https://api.frylabs.net/' - const apiAdress = 'http://localhost:8080/' + const apiAdress = 'http://localhost:80/' const ircAddress = 'https://kiwiirc.com/nextclient/irc.sub.fm/#qmining' // forcing pages for testing. unless you test, do not set these to true! @@ -661,7 +661,11 @@ // : Loading {{{ function HandleQminingSite (url) { try { - Array.from(document.getElementById('sideBarLinks').childNodes).forEach((link) => { + const sideLinks = document.getElementById('sideBarLinks') + if (!sideLinks) { + return + } + Array.from(sideLinks.childNodes).forEach((link) => { link.addEventListener('mousedown', () => { FillFeedbackCID(url, link) }) @@ -1549,6 +1553,8 @@ loginButton.innerText = 'Login' const loginInput = document.createElement('input') loginInput.type = 'text' + loginInput.style.textAlign = 'center' + loginInput.value = getVal('clientId') || '' loginDiv.appendChild(loginInput) loginDiv.appendChild(loginButton) @@ -1556,7 +1562,14 @@ SetStyle(loginButton, buttonStyle) loginButton.addEventListener('click', function () { - Auth(loginInput.value) + if (loginInput.value === getVal('clientId').toString()) { + console.log('opening veteran pw page ...') + openInTab(serverAdress + 'getVeteranPw?cid=' + getVal('clientId'), { + active: true + }) + } else { + Auth(loginInput.value) + } }) ibuttonCell.appendChild(loginDiv) From 7bccf3c7ee8fe874df413464f64e8fa73f7b2577 Mon Sep 17 00:00:00 2001 From: MrFry Date: Thu, 9 Apr 2020 09:20:07 +0200 Subject: [PATCH 06/18] New client id gen, only filling pw field if user has old client ID --- stable.user.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/stable.user.js b/stable.user.js index 4dbe908..d6b64e9 100755 --- a/stable.user.js +++ b/stable.user.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 2.0.0.7 +// @version 2.0.1.0 // @description Online Moodle/Elearning/KMOOC test help // @author MrFry // @match https://elearning.uni-obuda.hu/main/* @@ -1552,10 +1552,12 @@ const loginButton = document.createElement('button') loginButton.innerText = 'Login' const loginInput = document.createElement('input') - loginInput.type = 'text' + loginInput.type = 'password' loginInput.style.textAlign = 'center' - loginInput.value = getVal('clientId') || '' - + if (getVal('clientId') && getVal('clientId')[0] !== 0) { + loginInput.value = getVal('clientId') || '' + loginInput.type = 'text' + } loginDiv.appendChild(loginInput) loginDiv.appendChild(loginButton) @@ -1668,8 +1670,11 @@ return currId } else { currId = new Date() - currId = currId.getTime() + Math.floor(Math.random() * 10000000) - setVal('clientId', currId.toString()) + currId = currId.getTime() + Math.floor(Math.random() * 1000000000000) + currId = currId.toString().split('') + currId.shift() + currId = '0' + currId.join('') + setVal('clientId', currId) return currId } } From 6504ec2b0be27002d324bb0f65df9fa25a2ef114 Mon Sep 17 00:00:00 2001 From: MrFry Date: Thu, 9 Apr 2020 12:51:16 +0200 Subject: [PATCH 07/18] Reset some testing variables --- stable.user.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/stable.user.js b/stable.user.js index d6b64e9..ccf0aa5 100755 --- a/stable.user.js +++ b/stable.user.js @@ -62,8 +62,8 @@ var addEventListener // add event listener function const serverAdress = 'https://qmining.frylabs.net/' // const serverAdress = 'http://localhost:8080/' - // const apiAdress = 'https://api.frylabs.net/' - const apiAdress = 'http://localhost:80/' + const apiAdress = 'https://api.frylabs.net/' + // const apiAdress = 'http://localhost:80/' const ircAddress = 'https://kiwiirc.com/nextclient/irc.sub.fm/#qmining' // forcing pages for testing. unless you test, do not set these to true! @@ -75,8 +75,7 @@ const log = true const motdShowCount = 3 /* Ammount of times to show motd */ - // TODO: set to 60 - const infoExpireTime = 1 // Every n seconds basic info should be loaded from server + const infoExpireTime = 60 // Every n seconds basic info should be loaded from server var motd = '' var lastestVersion = '' var subjInfo @@ -1553,6 +1552,7 @@ loginButton.innerText = 'Login' const loginInput = document.createElement('input') loginInput.type = 'password' + loginInput.style.width = '400px' loginInput.style.textAlign = 'center' if (getVal('clientId') && getVal('clientId')[0] !== 0) { loginInput.value = getVal('clientId') || '' @@ -1565,7 +1565,6 @@ loginButton.addEventListener('click', function () { if (loginInput.value === getVal('clientId').toString()) { - console.log('opening veteran pw page ...') openInTab(serverAdress + 'getVeteranPw?cid=' + getVal('clientId'), { active: true }) @@ -1719,6 +1718,8 @@ xmlhttpRequest({ method: 'GET', url: url, + crossDomain: true, + xhrFields: { withCredentials: true }, headers: { 'Content-Type': 'application/json' }, @@ -1811,7 +1812,8 @@ xmlhttpRequest({ method: 'POST', url: url, - // xhrFields: { withCredentials: true }, + crossDomain: true, + xhrFields: { withCredentials: true }, data: message, headers: { 'Content-Type': 'application/json' From 22275e394369c365a57e170210eea80f85c3724e Mon Sep 17 00:00:00 2001 From: MrFry Date: Thu, 9 Apr 2020 17:14:35 +0200 Subject: [PATCH 08/18] Always requesting data from server if last message status was not success --- stable.user.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stable.user.js b/stable.user.js index ccf0aa5..db602b0 100755 --- a/stable.user.js +++ b/stable.user.js @@ -1708,7 +1708,8 @@ setVal('lastInfoCheckTime', now) } - if (now > lastCheck + (infoExpireTime * 1000)) { + const lastInfo = JSON.parse(getVal('lastInfo')) + if (lastInfo.result !== 'success' || now > lastCheck + (infoExpireTime * 1000)) { return new Promise((resolve, reject) => { const url = apiAdress + 'infos?version=true&motd=true&subjinfo=true&cversion=' + @@ -1744,7 +1745,7 @@ } else { return new Promise((resolve, reject) => { try { - resolve(JSON.parse(getVal('lastInfo'))) + resolve(lastInfo) } catch (e) { Log('Errro paring JSON in GetXHRInfos, when using old data!') Log(e) From a8e47bc73dbaf662b2ae4be248c2d89270c1ec37 Mon Sep 17 00:00:00 2001 From: MrFry Date: Thu, 9 Apr 2020 17:41:36 +0200 Subject: [PATCH 09/18] removed changelog --- stable.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stable.user.js b/stable.user.js index db602b0..031b255 100755 --- a/stable.user.js +++ b/stable.user.js @@ -81,7 +81,7 @@ var subjInfo const huTexts = { - lastChangeLog: '- "Húzza a megfelelő helyre ..." kérdés lekezelése\n- Kód refactor\n- Ha valami elszállt: feedback pls', + lastChangeLog: '', fatalError: 'Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!', consoleErrorInfo: 'Itteni hibák 100% a moodle hiba. Kivéve, ha oda van írva hogy script error ;) Ha ilyesmi szerepel itt, akkor olvasd el a segítség szekciót!', freshStartWarning: '

Moodle teszt userscript:

1.5.0 verzió: a script mostantól XMLHTTP kéréseket küld szerver fele! Erre a userscript futtató kiegészítőd is figyelmeztetni fog! Ha ez történik, a script rendes működése érdekében engedélyezd (Always allow domain)! Ha nem akarod, hogy ez történjen, akkor ne engedélyezd, vagy a menüben válaszd ki a "helyi fájl használata" opciót!

Elküldött adatok: minden teszt után a kérdés-válasz páros. Fogadott adatok: Az összes eddig ismert kérdés. Érdemes help-et elolvasni!!!

Ez az ablak frissités után eltűnik. Ha nem, akkor a visza gombbal próbálkozz.
', From 7dc12dbfa0343138237518435224f5ae34b3cff6 Mon Sep 17 00:00:00 2001 From: MrFry Date: Thu, 9 Apr 2020 20:45:03 +0200 Subject: [PATCH 10/18] Adding cid to login page --- stable.user.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/stable.user.js b/stable.user.js index 031b255..f7c348d 100755 --- a/stable.user.js +++ b/stable.user.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 2.0.1.0 +// @version 2.0.1.1 // @description Online Moodle/Elearning/KMOOC test help // @author MrFry // @match https://elearning.uni-obuda.hu/main/* @@ -659,6 +659,14 @@ // : Loading {{{ function HandleQminingSite (url) { + try { + const idInput = document.getElementById('cid') + if (idInput) { + idInput.value = getVal('clientId') + } + } catch (e) { + console.info('Error filling client ID input', e) + } try { const sideLinks = document.getElementById('sideBarLinks') if (!sideLinks) { From 6a638e0f789809e23a31ece7b8a10aa85592624a Mon Sep 17 00:00:00 2001 From: MrFry Date: Thu, 9 Apr 2020 22:24:08 +0200 Subject: [PATCH 11/18] Last info JSON parsing error handling --- stable.user.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/stable.user.js b/stable.user.js index f7c348d..08fe24c 100755 --- a/stable.user.js +++ b/stable.user.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 2.0.1.1 +// @version 2.0.1.2 // @description Online Moodle/Elearning/KMOOC test help // @author MrFry // @match https://elearning.uni-obuda.hu/main/* @@ -1716,7 +1716,11 @@ setVal('lastInfoCheckTime', now) } - const lastInfo = JSON.parse(getVal('lastInfo')) + let lastInfo = { result: 'noLastInfo' } + try { + lastInfo = JSON.parse(getVal('lastInfo')) + } catch (e) { + } if (lastInfo.result !== 'success' || now > lastCheck + (infoExpireTime * 1000)) { return new Promise((resolve, reject) => { const url = apiAdress + From a25e64189e050bcde8408bef0628d792e10b8b67 Mon Sep 17 00:00:00 2001 From: MrFry Date: Fri, 10 Apr 2020 13:11:31 +0200 Subject: [PATCH 12/18] Set pw input type to text, to prevent autofills --- stable.user.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/stable.user.js b/stable.user.js index 08fe24c..b2cf9a6 100755 --- a/stable.user.js +++ b/stable.user.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 2.0.1.2 +// @version 2.0.1.3 // @description Online Moodle/Elearning/KMOOC test help // @author MrFry // @match https://elearning.uni-obuda.hu/main/* @@ -1559,12 +1559,11 @@ const loginButton = document.createElement('button') loginButton.innerText = 'Login' const loginInput = document.createElement('input') - loginInput.type = 'password' + loginInput.type = 'text' loginInput.style.width = '400px' loginInput.style.textAlign = 'center' if (getVal('clientId') && getVal('clientId')[0] !== 0) { loginInput.value = getVal('clientId') || '' - loginInput.type = 'text' } loginDiv.appendChild(loginInput) loginDiv.appendChild(loginButton) From 0baf5df7d4ca77321c41b8e64d0bc44bed4b0bd9 Mon Sep 17 00:00:00 2001 From: MrFry Date: Fri, 10 Apr 2020 15:58:16 +0200 Subject: [PATCH 13/18] Added contribute button --- stable.user.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/stable.user.js b/stable.user.js index b2cf9a6..44a2308 100755 --- a/stable.user.js +++ b/stable.user.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 2.0.1.3 +// @version 2.0.1.4 // @description Online Moodle/Elearning/KMOOC test help // @author MrFry // @match https://elearning.uni-obuda.hu/main/* @@ -93,6 +93,7 @@ close: 'Bezárás', help: 'Help', websiteBugreport: 'Weboldal / Bug report', + contribute: 'Contribute', donate: 'Donate', passiveTooltip: 'Ha erre kattintasz akkor a script átálítja a neptunban a hallgatói státuszod passzívra', retry: 'Újrapróbálás', @@ -1471,7 +1472,7 @@ var menuButtonDiv = document.createElement('div') menuButtonDiv.setAttribute('id', 'menuButtonDiv') SetStyle(menuButtonDiv, { - // width: buttonWidth + 'px', + width: '600px', // height: buttonHeight + 'px', top: (window.innerHeight - 120) + 'px', left: '10px', @@ -1511,11 +1512,24 @@ // site link ---------------------------------------------------------------------------------------------------------------- + let contributeLink = CreateNodeWithText(buttonCell, texts.contribute, 'button') + SetStyle(contributeLink, buttonStyle) + + contributeLink.addEventListener('click', function () { + openInTab(serverAdress + 'contribute?scriptMenu', { + active: true + }) + }) + + // site link ---------------------------------------------------------------------------------------------------------------- + let siteLink = CreateNodeWithText(buttonCell, texts.websiteBugreport, 'button') SetStyle(siteLink, buttonStyle) siteLink.addEventListener('click', function () { - location.href = serverAdress + 'menuClick' // eslint-disable-line + openInTab(serverAdress + 'menuClick', { + active: true + }) }) // donate link ---------------------------------------------------------------------------------------------------------------- From eacd72f2ba6a2a5435258bde148e9bca710a0d1c Mon Sep 17 00:00:00 2001 From: MrFry Date: Fri, 10 Apr 2020 17:01:53 +0200 Subject: [PATCH 14/18] Fixed types when comparing client id-s first character --- stable.user.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/stable.user.js b/stable.user.js index 44a2308..b5f1584 100755 --- a/stable.user.js +++ b/stable.user.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 2.0.1.4 +// @version 2.0.1.5 // @description Online Moodle/Elearning/KMOOC test help // @author MrFry // @match https://elearning.uni-obuda.hu/main/* @@ -1576,8 +1576,9 @@ loginInput.type = 'text' loginInput.style.width = '400px' loginInput.style.textAlign = 'center' - if (getVal('clientId') && getVal('clientId')[0] !== 0) { - loginInput.value = getVal('clientId') || '' + const clientId = getVal('clientId') + if (clientId && clientId.toString()[0] !== '0') { + loginInput.value = clientId || '' } loginDiv.appendChild(loginInput) loginDiv.appendChild(loginButton) @@ -1585,8 +1586,8 @@ SetStyle(loginButton, buttonStyle) loginButton.addEventListener('click', function () { - if (loginInput.value === getVal('clientId').toString()) { - openInTab(serverAdress + 'getVeteranPw?cid=' + getVal('clientId'), { + if (loginInput.value === clientId.toString()) { + openInTab(serverAdress + 'getVeteranPw?cid=' + clientId, { active: true }) } else { From 089f6d3732c624eb767b5818239111a643706280 Mon Sep 17 00:00:00 2001 From: MrFry Date: Mon, 13 Apr 2020 13:14:18 +0200 Subject: [PATCH 15/18] Added devel mode, changed login texts --- stable.user.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/stable.user.js b/stable.user.js index b5f1584..8bf3310 100755 --- a/stable.user.js +++ b/stable.user.js @@ -60,9 +60,9 @@ /* eslint-enable */ var addEventListener // add event listener function - const serverAdress = 'https://qmining.frylabs.net/' + let serverAdress = 'https://qmining.frylabs.net/' // const serverAdress = 'http://localhost:8080/' - const apiAdress = 'https://api.frylabs.net/' + let apiAdress = 'https://api.frylabs.net/' // const apiAdress = 'http://localhost:80/' const ircAddress = 'https://kiwiirc.com/nextclient/irc.sub.fm/#qmining' @@ -75,11 +75,17 @@ const log = true const motdShowCount = 3 /* Ammount of times to show motd */ - const infoExpireTime = 60 // Every n seconds basic info should be loaded from server + let infoExpireTime = 60 // Every n seconds basic info should be loaded from server var motd = '' var lastestVersion = '' var subjInfo + if (getVal('ISDEVEL')) { + infoExpireTime = 1 + serverAdress = 'http://localhost:8080/' + apiAdress = 'http://localhost:80/' + } + const huTexts = { lastChangeLog: '', fatalError: 'Fatál error. Check console (f12). Kattints az üzenetre az összes kérdés/válaszért manuális kereséshez!', @@ -101,6 +107,8 @@ invalidPW: 'Hibás jelszó: ', search: 'Keresés ...', loading: 'Betöltés ...', + login: 'Belépés', + requestPW: 'Jelszó kérése', noServer: 'Nem elérhető a szerver!', noUser: 'Nem vagy bejelentkezve!', passiveModeActivated: 'Passzív mód bekapcsolva, nem lesz mostantól a szerver piszkálva', @@ -1571,7 +1579,7 @@ loginDiv.style.display = 'none' loginDiv.setAttribute('id', 'loginDiv') const loginButton = document.createElement('button') - loginButton.innerText = 'Login' + loginButton.innerText = texts.login const loginInput = document.createElement('input') loginInput.type = 'text' loginInput.style.width = '400px' @@ -1579,6 +1587,7 @@ const clientId = getVal('clientId') if (clientId && clientId.toString()[0] !== '0') { loginInput.value = clientId || '' + loginButton.innerText = texts.requestPW } loginDiv.appendChild(loginInput) loginDiv.appendChild(loginButton) From f8d4bf2a414d2973582c08bfa8b8b8f19389b2e9 Mon Sep 17 00:00:00 2001 From: MrFry Date: Mon, 13 Apr 2020 19:14:53 +0200 Subject: [PATCH 16/18] Removed passive mode, added new pw button --- stable.user.js | 103 ++++++++++++++++++++----------------------------- 1 file changed, 42 insertions(+), 61 deletions(-) diff --git a/stable.user.js b/stable.user.js index 8bf3310..28046ef 100755 --- a/stable.user.js +++ b/stable.user.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 2.0.1.5 +// @version 2.0.1.6 // @description Online Moodle/Elearning/KMOOC test help // @author MrFry // @match https://elearning.uni-obuda.hu/main/* @@ -61,9 +61,7 @@ var addEventListener // add event listener function let serverAdress = 'https://qmining.frylabs.net/' - // const serverAdress = 'http://localhost:8080/' let apiAdress = 'https://api.frylabs.net/' - // const apiAdress = 'http://localhost:80/' const ircAddress = 'https://kiwiirc.com/nextclient/irc.sub.fm/#qmining' // forcing pages for testing. unless you test, do not set these to true! @@ -101,20 +99,18 @@ websiteBugreport: 'Weboldal / Bug report', contribute: 'Contribute', donate: 'Donate', - passiveTooltip: 'Ha erre kattintasz akkor a script átálítja a neptunban a hallgatói státuszod passzívra', retry: 'Újrapróbálás', ircButton: 'IRC', invalidPW: 'Hibás jelszó: ', search: 'Keresés ...', loading: 'Betöltés ...', login: 'Belépés', - requestPW: 'Jelszó kérése', + 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!', noUser: 'Nem vagy bejelentkezve!', - passiveModeActivated: 'Passzív mód bekapcsolva, nem lesz mostantól a szerver piszkálva', - passiveModeDeactivated: 'Passzív mód kikapcsolva, frissíts az érvénybe lépéshez!', - passiveMode: 'Passzív mód', - passiveModeMenuBoxText: 'Passzív mód aktív', noServerConsoleMessage: `Nem elérhető a szerver, vagy kis eséllyel kezeletlen hiba történt! Ha elérhető a weboldal, akkor ott meg bírod nézni a kérdéseket itt: ${serverAdress}legacy` } @@ -747,9 +743,7 @@ } VersionActions() if (!url.includes('.pdf')) { ShowMenu() } - if (!getVal('skipLoad')) { - ConnectToServer(AfterLoad) - } + ConnectToServer(AfterLoad) } function Auth (pw) { @@ -758,7 +752,7 @@ if (res.result === 'success') { ConnectToServer(AfterLoad) ClearAllMessages() - setPassiveButtonState(false) + resetMenu() } else { SafeGetElementById('infoMainDiv', (elem) => { elem.innerText = texts.invalidPW + pw @@ -767,6 +761,24 @@ }) } + function resetMenu () { + SafeGetElementById('menuButtonDiv', (elem) => { + elem.style.backgroundColor = '#262626' + }) + SafeGetElementById('ircButton', (elem) => { + elem.style.display = 'none' + }) + SafeGetElementById('retryButton', (elem) => { + elem.style.display = 'none' + }) + SafeGetElementById('loginDiv', (elem) => { + elem.style.display = 'none' + }) + SafeGetElementById('infoMainDiv', (elem) => { + elem.innerText = texts.loading + }) + } + function ConnectToServer (cwith) { ClearAllMessages() GetXHRInfos().then((inf) => { @@ -791,6 +803,9 @@ }) SafeGetElementById('infoMainDiv', (elem) => { elem.innerText = texts.noUser + if (getVal('clientId')) { + elem.innerText += ` (${getVal('clientId')})` + } }) SafeGetElementById('loginDiv', (elem) => { elem.style.display = '' @@ -1521,6 +1536,7 @@ // site link ---------------------------------------------------------------------------------------------------------------- let contributeLink = CreateNodeWithText(buttonCell, texts.contribute, 'button') + contributeLink.title = texts.contributeTitle SetStyle(contributeLink, buttonStyle) contributeLink.addEventListener('click', function () { @@ -1529,6 +1545,18 @@ }) }) + // pw request ---------------------------------------------------------------------------------------------------------------- + + let pwRequest = CreateNodeWithText(buttonCell, texts.pwRequest, 'button') + pwRequest.title = texts.newPWTitle + SetStyle(pwRequest, buttonStyle) + + pwRequest.addEventListener('click', function () { + openInTab(serverAdress + 'pwRequest', { + active: true + }) + }) + // site link ---------------------------------------------------------------------------------------------------------------- let siteLink = CreateNodeWithText(buttonCell, texts.websiteBugreport, 'button') @@ -1587,7 +1615,7 @@ const clientId = getVal('clientId') if (clientId && clientId.toString()[0] !== '0') { loginInput.value = clientId || '' - loginButton.innerText = texts.requestPW + loginButton.innerText = texts.requestPWInsteadOfLogin } loginDiv.appendChild(loginInput) loginDiv.appendChild(loginButton) @@ -1637,60 +1665,13 @@ menuButtonDiv.style.top = (window.innerHeight - 70) + 'px' }) - // passive button ---------------------------------------------------------------------------------------------------------------- - let passiveButton = CreateNodeWithText(buttonCell, texts.passiveMode, 'button') - passiveButton.title = texts.passiveTooltip - SetStyle(passiveButton, buttonStyle) - // APPEND EVERYTHING appedtTo.appendChild(menuButtonDiv) - - setPassiveButtonState(getVal('skipLoad')) - - passiveButton.addEventListener('click', function () { - ClearAllMessages() - let sl = !getVal('skipLoad') - setVal('skipLoad', sl) - setPassiveButtonState(sl, true) - - if (sl) { - ShowMessage({ - m: texts.passiveModeActivated, - isSimple: true - }, 6) - } else { - ConnectToServer(AfterLoad) - } - }) } catch (e) { Exception(e, 'script error at showing menu:') } } - function setPassiveButtonState (isPassive) { - SafeGetElementById('menuButtonDiv', (elem) => { - elem.style.backgroundColor = '#262626' - }) - SafeGetElementById('ircButton', (elem) => { - elem.style.display = 'none' - }) - SafeGetElementById('retryButton', (elem) => { - elem.style.display = 'none' - }) - SafeGetElementById('loginDiv', (elem) => { - elem.style.display = 'none' - }) - if (!isPassive) { - SafeGetElementById('infoMainDiv', (elem) => { - elem.innerText = texts.loading - }) - } else { - SafeGetElementById('infoMainDiv', (elem) => { - elem.innerText = texts.passiveModeMenuBoxText - }) - } - } - // : }}} // : Generic utils {{{ From 3d358ccd4e8004092b30b41d7ea2a583f42746c3 Mon Sep 17 00:00:00 2001 From: MrFry Date: Mon, 13 Apr 2020 20:35:23 +0200 Subject: [PATCH 17/18] Login button text change based on value --- stable.user.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/stable.user.js b/stable.user.js index 28046ef..832357c 100755 --- a/stable.user.js +++ b/stable.user.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 2.0.1.6 +// @version 2.0.1.7 // @description Online Moodle/Elearning/KMOOC test help // @author MrFry // @match https://elearning.uni-obuda.hu/main/* @@ -1622,6 +1622,15 @@ SetStyle(loginButton, buttonStyle) + loginInput.addEventListener('keyup', (e) => { + console.log(e.target.value) + if (e.target.value === clientId) { + loginButton.innerText = texts.requestPWInsteadOfLogin + } else if (e.target.value !== '') { + loginButton.innerText = texts.login + } + }) + loginButton.addEventListener('click', function () { if (loginInput.value === clientId.toString()) { openInTab(serverAdress + 'getVeteranPw?cid=' + clientId, { From 2c815c8d20b6c25a4214d6118760d993f2287f36 Mon Sep 17 00:00:00 2001 From: MrFry Date: Tue, 14 Apr 2020 14:37:13 +0200 Subject: [PATCH 18/18] Showing user id on menu --- stable.user.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stable.user.js b/stable.user.js index 832357c..e36e8b8 100755 --- a/stable.user.js +++ b/stable.user.js @@ -21,7 +21,7 @@ // ==UserScript== // @name Moodle/Elearning/KMOOC test help -// @version 2.0.1.7 +// @version 2.0.1.8 // @description Online Moodle/Elearning/KMOOC test help // @author MrFry // @match https://elearning.uni-obuda.hu/main/* @@ -789,7 +789,7 @@ lastestVersion = inf.version motd = inf.motd subjInfo = inf.subjinfo - document.getElementById('infoMainDiv').innerText = `${subjInfo.subjects} tárgy, ${subjInfo.questions} kérdés` + document.getElementById('infoMainDiv').innerText = `${subjInfo.subjects} tárgy, ${subjInfo.questions} kérdés. Felh #${inf.uid}` // FIXME: if cwith() throws an unhandled error it sais server is not avaible cwith() }).catch(() => {