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
|
||||
/* eslint-disable */
|
||||
const location = location
|
||||
const a = Main
|
||||
function getVal (name) { return GM_getValue(name) }
|
||||
function setVal (name, val) { return GM_setValue(name, val) }
|
||||
|
@ -210,6 +209,19 @@ class Subject {
|
|||
|
||||
this.Name = n
|
||||
this.Questions = []
|
||||
this.active = false
|
||||
}
|
||||
|
||||
active () {
|
||||
this.active = true
|
||||
}
|
||||
|
||||
set index (i) {
|
||||
this.index = i
|
||||
}
|
||||
|
||||
get index () {
|
||||
return this.index
|
||||
}
|
||||
|
||||
get length () {
|
||||
|
@ -732,7 +744,7 @@ function Main () {
|
|||
console.time('main')
|
||||
|
||||
Init(function (count, subjCount) {
|
||||
var url = location.href
|
||||
var url = location.href // eslint-disable-line
|
||||
|
||||
let skipLoad = getVal('skipLoad')
|
||||
if (count === -2 && subjCount === -2 && skipLoad) {
|
||||
|
@ -791,7 +803,7 @@ function Init (cwith) {
|
|||
setVal('showQuestions', 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.
|
||||
// --------------------------------------------------------------------------------------
|
||||
// event listener fuckery
|
||||
|
@ -1075,6 +1087,8 @@ function NLoad (resource, cwith) {
|
|||
for (let i = 0; i < d.Subjects.length; i++) {
|
||||
let s = new Subject(d.Subjects[i].Name)
|
||||
if (getVal('Is' + i + 'Active')) {
|
||||
s.active()
|
||||
s.index = i
|
||||
var j = 0
|
||||
for (j = 0; j < d.Subjects[i].Questions.length; j++) {
|
||||
var currQ = d.Subjects[i].Questions[j]
|
||||
|
@ -1895,15 +1909,20 @@ function ShowMenuList () {
|
|||
var headerSubjInfoParagraph2 = CreateNodeWithText(header2, 'Aktív')
|
||||
headerSubjInfoParagraph2.style.margin = fiveMargin // fancy margin
|
||||
|
||||
// TODO: group here
|
||||
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()
|
||||
subjRow.style.border = '1px solid #131319'
|
||||
|
||||
var td = subjRow.insertCell()
|
||||
var text = data.Subjects[i].Name
|
||||
if (data.Subjects[i].length !== 0) { text += ' [ ' + data.Subjects[i].length + 'db ]' }
|
||||
var text = subj.Name
|
||||
if (subj.length !== 0) { text += ' [ ' + subj.length + 'db ]' }
|
||||
|
||||
var textBox = CreateNodeWithText(td, text)
|
||||
|
||||
|
@ -1916,16 +1935,13 @@ function ShowMenuList () {
|
|||
checkbox.style.margin = '5px 5px 5px 5px' // fancy margin
|
||||
td.appendChild(checkbox) // adding text box to main td
|
||||
|
||||
var active = data.GetIfActive(i)
|
||||
checkbox.checked = active
|
||||
|
||||
checkbox.checked = subj.active
|
||||
checkbox.setAttribute('id', 'HelperTextNode' + i)
|
||||
|
||||
checkbox.addEventListener('click', function () {
|
||||
var checked = document.getElementById('HelperTextNode' + i).checked
|
||||
data.ChangeActive(i, checked)
|
||||
}) // adding click
|
||||
}
|
||||
})
|
||||
|
||||
var scrollDiv = document.createElement('div')
|
||||
scrollDiv.style.width = '100%'
|
||||
|
@ -1940,6 +1956,7 @@ function ShowMenuList () {
|
|||
} else { // if no data
|
||||
var noDataRow = tbl.insertRow()
|
||||
var noDataRowCell = noDataRow.insertCell()
|
||||
let textBox
|
||||
|
||||
if (getVal('skipLoad')) {
|
||||
textBox = CreateNodeWithText(noDataRowCell,
|
||||
|
@ -2072,7 +2089,7 @@ function ShowMenuList () {
|
|||
siteLink.innerText = 'Weboldal'
|
||||
|
||||
siteLink.addEventListener('click', function () {
|
||||
location.href = serverAdress + 'menuClick'
|
||||
location.href = serverAdress + 'menuClick' // eslint-disable-line
|
||||
})
|
||||
|
||||
// addEventListener(window, 'scroll', function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue