Removed passive mode, added new pw button

This commit is contained in:
MrFry 2020-04-13 19:14:53 +02:00
parent 089f6d3732
commit f8d4bf2a41

View file

@ -21,7 +21,7 @@
// ==UserScript== // ==UserScript==
// @name Moodle/Elearning/KMOOC test help // @name Moodle/Elearning/KMOOC test help
// @version 2.0.1.5 // @version 2.0.1.6
// @description Online Moodle/Elearning/KMOOC test help // @description Online Moodle/Elearning/KMOOC test help
// @author MrFry // @author MrFry
// @match https://elearning.uni-obuda.hu/main/* // @match https://elearning.uni-obuda.hu/main/*
@ -61,9 +61,7 @@
var addEventListener // add event listener function var addEventListener // add event listener function
let serverAdress = 'https://qmining.frylabs.net/' let serverAdress = 'https://qmining.frylabs.net/'
// const serverAdress = 'http://localhost:8080/'
let 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' const ircAddress = 'https://kiwiirc.com/nextclient/irc.sub.fm/#qmining'
// 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!
@ -101,20 +99,18 @@
websiteBugreport: 'Weboldal / Bug report', websiteBugreport: 'Weboldal / Bug report',
contribute: 'Contribute', contribute: 'Contribute',
donate: 'Donate', 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', retry: 'Újrapróbálás',
ircButton: 'IRC', ircButton: 'IRC',
invalidPW: 'Hibás jelszó: ', invalidPW: 'Hibás jelszó: ',
search: 'Keresés ...', search: 'Keresés ...',
loading: 'Betöltés ...', loading: 'Betöltés ...',
login: 'Belépé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!', noServer: 'Nem elérhető a szerver!',
noUser: 'Nem vagy bejelentkezve!', 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` 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,10 +743,8 @@
} }
VersionActions() VersionActions()
if (!url.includes('.pdf')) { ShowMenu() } if (!url.includes('.pdf')) { ShowMenu() }
if (!getVal('skipLoad')) {
ConnectToServer(AfterLoad) ConnectToServer(AfterLoad)
} }
}
function Auth (pw) { function Auth (pw) {
SendXHRMessage('login', { pw: pw, script: true }) SendXHRMessage('login', { pw: pw, script: true })
@ -758,7 +752,7 @@
if (res.result === 'success') { if (res.result === 'success') {
ConnectToServer(AfterLoad) ConnectToServer(AfterLoad)
ClearAllMessages() ClearAllMessages()
setPassiveButtonState(false) resetMenu()
} else { } else {
SafeGetElementById('infoMainDiv', (elem) => { SafeGetElementById('infoMainDiv', (elem) => {
elem.innerText = texts.invalidPW + pw 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) { function ConnectToServer (cwith) {
ClearAllMessages() ClearAllMessages()
GetXHRInfos().then((inf) => { GetXHRInfos().then((inf) => {
@ -791,6 +803,9 @@
}) })
SafeGetElementById('infoMainDiv', (elem) => { SafeGetElementById('infoMainDiv', (elem) => {
elem.innerText = texts.noUser elem.innerText = texts.noUser
if (getVal('clientId')) {
elem.innerText += ` (${getVal('clientId')})`
}
}) })
SafeGetElementById('loginDiv', (elem) => { SafeGetElementById('loginDiv', (elem) => {
elem.style.display = '' elem.style.display = ''
@ -1521,6 +1536,7 @@
// site link ---------------------------------------------------------------------------------------------------------------- // site link ----------------------------------------------------------------------------------------------------------------
let contributeLink = CreateNodeWithText(buttonCell, texts.contribute, 'button') let contributeLink = CreateNodeWithText(buttonCell, texts.contribute, 'button')
contributeLink.title = texts.contributeTitle
SetStyle(contributeLink, buttonStyle) SetStyle(contributeLink, buttonStyle)
contributeLink.addEventListener('click', function () { 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 ---------------------------------------------------------------------------------------------------------------- // site link ----------------------------------------------------------------------------------------------------------------
let siteLink = CreateNodeWithText(buttonCell, texts.websiteBugreport, 'button') let siteLink = CreateNodeWithText(buttonCell, texts.websiteBugreport, 'button')
@ -1587,7 +1615,7 @@
const clientId = getVal('clientId') const clientId = getVal('clientId')
if (clientId && clientId.toString()[0] !== '0') { if (clientId && clientId.toString()[0] !== '0') {
loginInput.value = clientId || '' loginInput.value = clientId || ''
loginButton.innerText = texts.requestPW loginButton.innerText = texts.requestPWInsteadOfLogin
} }
loginDiv.appendChild(loginInput) loginDiv.appendChild(loginInput)
loginDiv.appendChild(loginButton) loginDiv.appendChild(loginButton)
@ -1637,60 +1665,13 @@
menuButtonDiv.style.top = (window.innerHeight - 70) + 'px' 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 // APPEND EVERYTHING
appedtTo.appendChild(menuButtonDiv) 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) { } catch (e) {
Exception(e, 'script error at showing menu:') 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 {{{ // : Generic utils {{{