Skip to content

Commit

Permalink
3.11.6
Browse files Browse the repository at this point in the history
  • Loading branch information
QkeleQ10 committed Jun 20, 2024
1 parent 2ac7d13 commit 993326d
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 199 deletions.
1 change: 1 addition & 0 deletions _locales/nl/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
"Ouder": "Ouder",
"noEvents": "Geen afspraken deze dag",
"noEventsToday": "Geen afspraken vandaag",
"noEventsUntilDate": "Geen afspraken\n(tot in elk geval {date})",
"error": "Er is iets misgegaan",
"loading": "Laden...",
"loadingWidgets": "Widgets laden...",
Expand Down
2 changes: 1 addition & 1 deletion manifest-firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"manifest_version": 3,
"name": "__MSG_appName__",
"description": "__MSG_appDesc__",
"version": "3.11.5",
"version": "3.11.6",
"default_locale": "nl",
"icons": {
"16": "icons/icon@16px.png",
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"manifest_version": 3,
"name": "__MSG_appName__",
"description": "__MSG_appDesc__",
"version": "3.11.5",
"version": "3.11.6",
"default_locale": "nl",
"icons": {
"16": "icons/icon@16px.png",
Expand Down
59 changes: 26 additions & 33 deletions src/magister/scripts/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,44 +18,17 @@ const gatherEnd = new Date()
gatherEnd.setDate(now.getDate() + 42)
gatherEnd.setHours(0, 0, 0, 0)


const MagisterApi = {
accountInfo: async (parse = false) => {
useSampleData: false,
accountInfo: async () => {
return new Promise(async (resolve, reject) => {
magisterApiCache.accountInfo ??=
fetchWrapper(
`https://${magisterApiSchoolName}.magister.net/api/account?noCache=0`, null, 'accountInfo'
)
if (parse) {
const obj = await magisterApiCache.accountInfo
resolve({
id: obj.Persoon.Id,
externalId: obj.Persoon.ExterneId,
uuid: obj.Persoon.UuId,
name: {
official: {
firstnames: obj.Persoon.OfficieleVoornamen || obj.Persoon.Roepnaam,
affixes: obj.Persoon.OfficieleTussenvoegsels || obj.Persoon.GeboortenaamTussenvoegsel || obj.Persoon.Tussenvoegsel,
lastname: obj.Persoon.OfficieleAchternaam || obj.Persoon.GeboorteAchternaam || obj.Persoon.Achternaam
},
birth: {
isPreferred: obj.Persoon.GebruikGeboortenaam === true,
affix: obj.Persoon.GeboortenaamTussenvoegsel || obj.Persoon.OfficieleTussenvoegsels || obj.Persoon.Tussenvoegsel,
lastname: obj.Persoon.GeboorteAchternaam || obj.Persoon.OfficieleAchternaam || obj.Persoon.Achternaam
},
initials: obj.Persoon.Voorletters,
firstname: obj.Persoon.Roepnaam || obj.Persoon.OfficieleVoornamen,
affix: obj.Persoon.Tussenvoegsel || obj.Persoon.OfficieleTussenvoegsels || obj.Persoon.GeboortenaamTussenvoegsel,
lastname: obj.Persoon.Achternaam || obj.Persoon.GeboorteAchternaam || obj.Persoon.OfficieleAchternaam
},
dateOfBirth: new Date(obj.Persoon.Geboortedatum),
permissions: obj.Groep[0].Privileges
})
} else {
resolve(
(await magisterApiCache.accountInfo)
)
}
resolve(
(await magisterApiCache.accountInfo)
)
})
},
years: async () => {
Expand All @@ -80,7 +53,6 @@ const MagisterApi = {
)
})
},

exams: {
list: async (year) => {
return new Promise(async (resolve, reject) => {
Expand All @@ -106,6 +78,9 @@ const MagisterApi = {
}
},
events: async (start = gatherStart, end = gatherEnd) => {
if (MagisterApi.useSampleData) {
return [{ "Docenten": [{ "Naam": "O. Baguette", "Docentcode": "OBA" }], "Start": now.toISOString().split('T')[0] + " 09:00", "Einde": now.toISOString().split('T')[0] + " 10:00", "Id": 1, "InfoType": 0, "Inhoud": null, "LesuurTotMet": 2, "LesuurVan": 2, "Lokalen": [{ "Naam": "11s" }], "Omschrijving": "fatl - oba", "Lokatie": "11s", "Status": 5, "Vakken": [{ "Naam": "Franse taal" }] }, { "Docenten": [{ "Naam": "G. Gifje", "Docentcode": "GIF" }], "Start": now.toISOString().split('T')[0] + " 10:00", "Einde": now.toISOString().split('T')[0] + " 11:00", "Id": 2, "InfoType": 0, "Inhoud": null, "LesuurTotMet": 3, "LesuurVan": 3, "Lokalen": [{ "Naam": "11s" }], "Omschrijving": "mem - gif", "Lokatie": "11s", "Vakken": [{ "Naam": "memekunde" }] }, { "Docenten": [{ "Naam": "M. Millenial", "Docentcode": "MMI" }], "Start": now.toISOString().split('T')[0] + " 11:30", "Einde": now.toISOString().split('T')[0] + " 12:30", "Id": 3, "InfoType": 0, "Inhoud": null, "LesuurTotMet": 4, "LesuurVan": 4, "Lokalen": [{ "Naam": "11l" }], "Omschrijving": "stk - mmi", "Lokatie": "11l", "Vakken": [{ "Naam": "straattaalkunde" }] }, { "Docenten": [{ "Id": 0, "Naam": "E. Musk", "Docentcode": "EMU" }], "Start": now.toISOString().split('T')[0] + " 12:30", "Einde": now.toISOString().split('T')[0] + " 13:30", "Id": 4, "InfoType": 0, "Inhoud": null, "LesuurTotMet": 5, "LesuurVan": 5, "Lokalen": [{ "Naam": "binas6" }], "Omschrijving": "na - emu", "Lokatie": "binas6", "Vakken": [{ "Naam": "natuurkunde" }] }, { "Docenten": [{ "Id": 0, "Naam": "B. Baan", "Docentcode": "BBA" }], "Start": now.toISOString().split('T')[0] + " 14:00", "Einde": now.toISOString().split('T')[0] + " 15:00", "Id": 5, "InfoType": 0, "Inhoud": null, "LesuurTotMet": 6, "LesuurVan": 6, "Lokalen": [{ "Naam": "at1_ondersteboven" }], "Omschrijving": "ka - bba", "Lokatie": "at1_ondersteboven", "Type": 7, "Vakken": [{ "Naam": "kinderarbeid" }] }, { Start: new Date(new Date().setHours(0, 0, 0, 0) + 122400000), Einde: new Date(new Date().setHours(0, 0, 0, 0) + 125100000), Inhoud: "<p>Dit is een onvoltooid huiswerkitem.</p>", Opmerking: null, InfoType: 1, Afgerond: false, "Docenten": [{ "Naam": "O. Baguette", "Docentcode": "OBA" }], Vakken: [{ Naam: "Niet-bestaand vak" }] }, { Start: new Date(new Date().setHours(0, 0, 0, 0) + 297900000), Einde: new Date(new Date().setHours(0, 0, 0, 0) + 300600000), Inhoud: "<p>In deze les heb je een schriftelijke overhoring. Neem je oortjes mee.</p>", Opmerking: null, InfoType: 2, Afgerond: false, "Docenten": [{ "Naam": "O. Baguette", "Docentcode": "OBA" }], Vakken: [{ Naam: "Lichamelijke opvoeding" }] }, { Start: new Date(new Date().setHours(0, 0, 0, 0) + 297900000), Einde: new Date(new Date().setHours(0, 0, 0, 0) + 300600000), Inhoud: "<p>Dit item heb je al wel voltooid. Good job.</p>", Opmerking: null, InfoType: 1, Afgerond: true, "Docenten": [{ "Naam": "O. Baguette", "Docentcode": "OBA" }], Vakken: [{ Naam: "Jouw favoriete vak" }] }]
}
return new Promise(async (resolve, reject) => {
magisterApiCache['events' + start.toISOString().substring(0, 10) + end.toISOString().substring(0, 10)] ??=
fetchWrapper(
Expand All @@ -118,6 +93,11 @@ const MagisterApi = {
},
grades: {
recent: async () => {

if (MagisterApi.useSampleData) {
return [{ omschrijving: "Voorbeeld", ingevoerdOp: new Date(now - 172800000), vak: { code: "netl", omschrijving: "Nederlandse taal" }, waarde: "6,9", weegfactor: 0 }, { omschrijving: "Baguette", ingevoerdOp: new Date(now - 691200000), vak: { code: "fatl", omschrijving: "Franse taal" }, waarde: "U", weegfactor: 0 }, { omschrijving: "Grade mockery", ingevoerdOp: new Date(now - 6891200000), vak: { code: "entl", omschrijving: "Engelse taal" }, waarde: "5,4", weegfactor: 0 }
]
}
return new Promise(async (resolve, reject) => {
magisterApiCache.gradesRecent ??=
fetchWrapper(
Expand Down Expand Up @@ -153,6 +133,9 @@ const MagisterApi = {
},
assignments: {
top: async () => {
if (MagisterApi.useSampleData) {
return [{ Titel: "Praktische opdracht", Vak: "sk", InleverenVoor: new Date(new Date().setHours(0, 0, 0, 0) + 300600000), Omschrijving: "Zorg ervoor dat je toestemming hebt van de TOA voordat je begint met je experiment." }, { Titel: "Boekverslag", Vak: "netl", InleverenVoor: new Date(new Date().setHours(0, 0, 0, 0) + 400500000) }]
}
return new Promise(async (resolve, reject) => {
magisterApiCache.assignments ??=
fetchWrapper(
Expand All @@ -176,6 +159,10 @@ const MagisterApi = {
}
},
messages: async () => {
if (MagisterApi.useSampleData) {
return [{ onderwerp: "🔥😂💚🍀😔🐜😝🙏👍🪢💀☠️", afzender: { naam: "Quinten Althues (V6E)" }, heeftBijlagen: true, verzondenOp: new Date(now - 3032000000) }, { onderwerp: "Wie gebruikt Berichten in vredesnaam?", afzender: { naam: "Quinten Althues (V6E)" }, heeftPrioriteit: true, verzondenOp: new Date(now - 1000000) }
]
}
return new Promise(async (resolve, reject) => {
magisterApiCache.messages ??=
fetchWrapper(
Expand All @@ -187,6 +174,9 @@ const MagisterApi = {
})
},
activities: async () => {
if (MagisterApi.useSampleData) {
return [null]
}
return new Promise(async (resolve, reject) => {
magisterApiCache.activities ??=
fetchWrapper(
Expand All @@ -198,6 +188,9 @@ const MagisterApi = {
})
},
logs: async () => {
if (MagisterApi.useSampleData) {
return [null]
}
return new Promise(async (resolve, reject) => {
magisterApiCache.logs ??=
fetchWrapper(
Expand Down
24 changes: 16 additions & 8 deletions src/magister/scripts/gamification.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ window.checkWrapped = checkWrapped()
async function checkWrapped() {
if ((now >= range1.start && now <= range1.end) || (await getFromStorage('forceWrappedExamEdition', 'session')) === 'true') {

user = await MagisterApi.accountInfo(true)
user = await MagisterApi.accountInfo()

years = (await MagisterApi.years())
.filter(year => Number(year.einde.split('-')[0]) <= now.getFullYear()) // Filter years to not include the upcoming school year
Expand Down Expand Up @@ -110,14 +110,14 @@ async function constructWrapped(lastYearOnly) {
previousButton.addEventListener('click', () => {
wrappedPage = Math.max(wrappedPage - 1, 0)
document.querySelector(`.st-wrapped-year:nth-child(${wrappedPage + 1})`).scrollIntoView({ inline: 'start', behavior: 'smooth' })
nextButton.disabled = wrappedPage === years.length
nextButton.disabled = wrappedPage === years.length - 1
previousButton.disabled = wrappedPage === 0
})
const nextButton = element('button', 'st-wrapped-next', dialog, { class: 'st-button icon', 'data-icon': '' })
nextButton.addEventListener('click', () => {
wrappedPage = Math.min(wrappedPage + 1, years.length)
document.querySelector(`.st-wrapped-year:nth-child(${wrappedPage + 1})`).scrollIntoView({ inline: 'start', behavior: 'smooth' })
nextButton.disabled = wrappedPage === years.length
nextButton.disabled = wrappedPage === years.length - 1
previousButton.disabled = wrappedPage === 0
})
}
Expand Down Expand Up @@ -147,7 +147,7 @@ async function constructWrapped(lastYearOnly) {
return new Promise(async (resolveYear) => {
let year = JSON.parse(JSON.stringify((i === years.length ? {} : years[i]) || {}))

let seed = cyrb128((year.groep?.code + year.lesperiode?.code) || (user.name?.firstname + i))
let seed = cyrb128((year.groep?.code + year.lesperiode?.code) || (user.Persoon.Roepnaam + i))
let rand = sfc32(seed[0], seed[1], seed[2], seed[3])

const yearElement = element('div', null, null, { class: 'st-wrapped-year', style: `--gradient: ${gradients.random(seed)} ; --pattern: url('https://raw.githubusercontent.com/QkeleQ10/http-resources/main/study-tools/decorations/wrapped/${i === years.length ? 'a' : year.studie.code.replace(/\D/gi, '')}.svg')` })
Expand Down Expand Up @@ -431,7 +431,7 @@ async function themeContest() {

event.preventDefault()

if ((await getFromStorage('themeContestJurorMode', 'session')) === 'true' || syncedStorage['themeContestJurorMode']) {
if (!((await getFromStorage('themeContestJurorMode', 'session')) === 'true') != !(syncedStorage['themeContestJurorMode'])) {
const textarea = element('textarea', 'null', document.body, { style: 'position: absolute; z-index: 99999999; top: 50%; left: 50%; translate: -50% -50%; width: 300px; height: 200px; transition: all 200ms;', resize: 'both', innerText: 'alt+klik om te verplaatsen, ctrl+klik om te verbergen' })
document.body.addEventListener('click', (event) => {
if (event.altKey) {
Expand Down Expand Up @@ -459,9 +459,17 @@ async function themeContest() {
})

} else {
user = await MagisterApi.accountInfo(true)
navigator.clipboard.writeText(btoa(JSON.stringify({ title: 'Magister Theme Contest', name: `${user.name.firstname} ${user.name.lastname}`, school: window.location.hostname.split('.')[0], options: pick(syncedStorage, 'ptheme', 'pagecolor', 'wallpaper', 'sidecolor', 'decoration', 'decoration-size', 'appbarcolor', 'shape', 'custom-css') })))
notify('dialog', "Je inzending is nu gekopieerd naar je klembord. Typ '/winactie' in Discord en volg de aanwijzingen.")
user = await MagisterApi.accountInfo()
const copyText = (btoa(JSON.stringify({ title: 'Magister Theme Contest', name: `${user.Persoon.Roepnaam} ${user.Persoon.Achternaam}`, school: window.location.hostname.split('.')[0], options: pick(syncedStorage, 'ptheme', 'pagecolor', 'wallpaper', 'sidecolor', 'decoration', 'decoration-size', 'appbarcolor', 'shape', 'custom-css') }))).match(new RegExp(`.{1,4000}`, 'g')) || []
if (copyText.length === 1) {
navigator.clipboard.writeText(copyText[0])
notify('dialog', "Je inzending is nu gekopieerd naar je klembord. Typ '/winactie' in Discord en volg de aanwijzingen.")
} else if (copyText.length > 1) {
for (let i = 0; i < copyText.length; i++) {
navigator.clipboard.writeText(copyText[i])
await notify('dialog', `Je inzending is erg lang. Daarom moet hij worden opgesplitst in ${copyText.length} delen. \nDeel ${i + 1} is nu gekopieerd naar je klembord.` + i === 0 ? " Typ '/winactie' in Discord en volg de aanwijzingen.\nKlik pas daarna verder." : '', null, null, { index: i + 1, length: copyText.length })
}
}
}
})
}
Expand Down
2 changes: 2 additions & 0 deletions src/magister/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ chrome.runtime.sendMessage({ action: 'popstateDetected' }) // Revive the service
// Run when the extension and page are loaded
main()
async function main() {
if((await getFromStorage('sampleApiData', 'session')) === 'true') MagisterApi.useSampleData = true

const todayDate = new Date(new Date().setHours(0, 0, 0, 0))

let appbar = await awaitElement('.appbar'),
Expand Down
59 changes: 57 additions & 2 deletions src/magister/scripts/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,37 @@ aside .tabs li a {
transform: scaleX(-1);
}
.menu-host .logo a .logo-expanded {
margin-left: 0;
.menu-host {
display: flex !important;
flex-direction: column;
}
.menu-host .logo {
position: static !important;
margin-left: 16px;
margin-top: 32px;
margin-bottom: 12px;
}
.menu-host .logo a .logo-collapsed {
margin-left: -12px;
}
.menu-host .menu {
position: static !important;
padding-bottom: 0 !important;
flex: 1;
display: flex;
flex-direction: column;
justify-content: space-between;
}
.menu-host .menu .menu-container {
height: max-content !important;
}
.menu-host .menu-footer {
position: static !important;
}
dna-card-title.disabled {
Expand Down Expand Up @@ -1528,6 +1557,32 @@ ${insufArray.map(x => `.grade.grade.grade.grade[title^="${x.toLocaleString('nl-N

if (syncedStorage['custom-css']) {
createStyle(syncedStorage['custom-css'], 'study-tools-custom-css')
const cssVarReferenceMatches = extractVariables(syncedStorage['custom-css'])

function extractVariables(inputString) {
const regex = /var\(--st-reference-(\w+)-([^\s)]+)\)/g
let matches
let result = []

while ((matches = regex.exec(inputString)) !== null) {
const property = matches[1]
const selector = matches[2]?.replace(/\\+/gi, '')
const variable = `--st-reference-${property}-${selector}`
result.push({ variable, property, selector })
}

return result
}

cssVarReferenceMatches.forEach(({ variable, property, selector }) => {
let interval = setInterval(update, 50)
setTimeout(() => clearInterval(interval), 3000)
window.addEventListener('resize', update)
document.querySelector(selector.replace(/\_/gi, ' ')).addEventListener('click', update)
function update() {
document.querySelector(':root').style.setProperty(variable, document.querySelector(selector.replace(/\_/gi, ' '))[property === 'width' ? 'offsetWidth' : 'offsetHeight'] + 'px')
}
})
} else {
createStyle('', 'study-tools-custom-css')
}
Expand Down
Loading

0 comments on commit 993326d

Please sign in to comment.