mirror of
https://gitlab.com/MrFry/moodle-test-userscript
synced 2025-04-01 20:22:48 +02:00
Added index and active to subject. group by year on ui prepare
This commit is contained in:
parent
bd031525d0
commit
0c374906ca
1 changed files with 30 additions and 13 deletions
43
main.js
43
main.js
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
// GM functions, only to disable ESLINT errors
|
// GM functions, only to disable ESLINT errors
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
const location = location
|
|
||||||
const a = Main
|
const a = Main
|
||||||
function getVal (name) { return GM_getValue(name) }
|
function getVal (name) { return GM_getValue(name) }
|
||||||
function setVal (name, val) { return GM_setValue(name, val) }
|
function setVal (name, val) { return GM_setValue(name, val) }
|
||||||
|
@ -210,6 +209,19 @@ class Subject {
|
||||||
|
|
||||||
this.Name = n
|
this.Name = n
|
||||||
this.Questions = []
|
this.Questions = []
|
||||||
|
this.active = false
|
||||||
|
}
|
||||||
|
|
||||||
|
active () {
|
||||||
|
this.active = true
|
||||||
|
}
|
||||||
|
|
||||||
|
set index (i) {
|
||||||
|
this.index = i
|
||||||
|
}
|
||||||
|
|
||||||
|
get index () {
|
||||||
|
return this.index
|
||||||
}
|
}
|
||||||
|
|
||||||
get length () {
|
get length () {
|
||||||
|
@ -732,7 +744,7 @@ function Main () {
|
||||||
console.time('main')
|
console.time('main')
|
||||||
|
|
||||||
Init(function (count, subjCount) {
|
Init(function (count, subjCount) {
|
||||||
var url = location.href
|
var url = location.href // eslint-disable-line
|
||||||
|
|
||||||
let skipLoad = getVal('skipLoad')
|
let skipLoad = getVal('skipLoad')
|
||||||
if (count === -2 && subjCount === -2 && skipLoad) {
|
if (count === -2 && subjCount === -2 && skipLoad) {
|
||||||
|
@ -791,7 +803,7 @@ function Init (cwith) {
|
||||||
setVal('showQuestions', undefined)
|
setVal('showQuestions', undefined)
|
||||||
setVal('showSplash', undefined)
|
setVal('showSplash', undefined)
|
||||||
}
|
}
|
||||||
var url = location.href // window location
|
var url = location.href // eslint-disable-line
|
||||||
var count = -1 // loaded question count. stays -1 if the load failed.
|
var count = -1 // loaded question count. stays -1 if the load failed.
|
||||||
// --------------------------------------------------------------------------------------
|
// --------------------------------------------------------------------------------------
|
||||||
// event listener fuckery
|
// event listener fuckery
|
||||||
|
@ -1075,6 +1087,8 @@ function NLoad (resource, cwith) {
|
||||||
for (let i = 0; i < d.Subjects.length; i++) {
|
for (let i = 0; i < d.Subjects.length; i++) {
|
||||||
let s = new Subject(d.Subjects[i].Name)
|
let s = new Subject(d.Subjects[i].Name)
|
||||||
if (getVal('Is' + i + 'Active')) {
|
if (getVal('Is' + i + 'Active')) {
|
||||||
|
s.active()
|
||||||
|
s.index = i
|
||||||
var j = 0
|
var j = 0
|
||||||
for (j = 0; j < d.Subjects[i].Questions.length; j++) {
|
for (j = 0; j < d.Subjects[i].Questions.length; j++) {
|
||||||
var currQ = d.Subjects[i].Questions[j]
|
var currQ = d.Subjects[i].Questions[j]
|
||||||
|
@ -1895,15 +1909,20 @@ function ShowMenuList () {
|
||||||
var headerSubjInfoParagraph2 = CreateNodeWithText(header2, 'Aktív')
|
var headerSubjInfoParagraph2 = CreateNodeWithText(header2, 'Aktív')
|
||||||
headerSubjInfoParagraph2.style.margin = fiveMargin // fancy margin
|
headerSubjInfoParagraph2.style.margin = fiveMargin // fancy margin
|
||||||
|
|
||||||
// TODO: group here
|
|
||||||
if (data && data.length > 0) {
|
if (data && data.length > 0) {
|
||||||
for (let i = 0; i < data.length; i++) {
|
// TODO: group here
|
||||||
|
// let sorted = data.Subjects.sort((x) => {
|
||||||
|
|
||||||
|
// })
|
||||||
|
let sorted = data.Subjects
|
||||||
|
|
||||||
|
sorted.forEach((subj, i) => {
|
||||||
var subjRow = subjTable.insertRow()
|
var subjRow = subjTable.insertRow()
|
||||||
subjRow.style.border = '1px solid #131319'
|
subjRow.style.border = '1px solid #131319'
|
||||||
|
|
||||||
var td = subjRow.insertCell()
|
var td = subjRow.insertCell()
|
||||||
var text = data.Subjects[i].Name
|
var text = subj.Name
|
||||||
if (data.Subjects[i].length !== 0) { text += ' [ ' + data.Subjects[i].length + 'db ]' }
|
if (subj.length !== 0) { text += ' [ ' + subj.length + 'db ]' }
|
||||||
|
|
||||||
var textBox = CreateNodeWithText(td, text)
|
var textBox = CreateNodeWithText(td, text)
|
||||||
|
|
||||||
|
@ -1916,16 +1935,13 @@ function ShowMenuList () {
|
||||||
checkbox.style.margin = '5px 5px 5px 5px' // fancy margin
|
checkbox.style.margin = '5px 5px 5px 5px' // fancy margin
|
||||||
td.appendChild(checkbox) // adding text box to main td
|
td.appendChild(checkbox) // adding text box to main td
|
||||||
|
|
||||||
var active = data.GetIfActive(i)
|
checkbox.checked = subj.active
|
||||||
checkbox.checked = active
|
|
||||||
|
|
||||||
checkbox.setAttribute('id', 'HelperTextNode' + i)
|
checkbox.setAttribute('id', 'HelperTextNode' + i)
|
||||||
|
|
||||||
checkbox.addEventListener('click', function () {
|
checkbox.addEventListener('click', function () {
|
||||||
var checked = document.getElementById('HelperTextNode' + i).checked
|
var checked = document.getElementById('HelperTextNode' + i).checked
|
||||||
data.ChangeActive(i, checked)
|
data.ChangeActive(i, checked)
|
||||||
}) // adding click
|
}) // adding click
|
||||||
}
|
})
|
||||||
|
|
||||||
var scrollDiv = document.createElement('div')
|
var scrollDiv = document.createElement('div')
|
||||||
scrollDiv.style.width = '100%'
|
scrollDiv.style.width = '100%'
|
||||||
|
@ -1940,6 +1956,7 @@ function ShowMenuList () {
|
||||||
} else { // if no data
|
} else { // if no data
|
||||||
var noDataRow = tbl.insertRow()
|
var noDataRow = tbl.insertRow()
|
||||||
var noDataRowCell = noDataRow.insertCell()
|
var noDataRowCell = noDataRow.insertCell()
|
||||||
|
let textBox
|
||||||
|
|
||||||
if (getVal('skipLoad')) {
|
if (getVal('skipLoad')) {
|
||||||
textBox = CreateNodeWithText(noDataRowCell,
|
textBox = CreateNodeWithText(noDataRowCell,
|
||||||
|
@ -2072,7 +2089,7 @@ function ShowMenuList () {
|
||||||
siteLink.innerText = 'Weboldal'
|
siteLink.innerText = 'Weboldal'
|
||||||
|
|
||||||
siteLink.addEventListener('click', function () {
|
siteLink.addEventListener('click', function () {
|
||||||
location.href = serverAdress + 'menuClick'
|
location.href = serverAdress + 'menuClick' // eslint-disable-line
|
||||||
})
|
})
|
||||||
|
|
||||||
// addEventListener(window, 'scroll', function () {
|
// addEventListener(window, 'scroll', function () {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue