From 993326da95979838c7aee9fa27c6a13114fd7722 Mon Sep 17 00:00:00 2001 From: QkeleQ10 Date: Thu, 20 Jun 2024 21:50:22 +0200 Subject: [PATCH] 3.11.6 --- _locales/nl/strings.json | 1 + manifest-firefox.json | 2 +- manifest.json | 2 +- src/magister/scripts/api.js | 59 ++++---- src/magister/scripts/gamification.js | 24 ++-- src/magister/scripts/main.js | 2 + src/magister/scripts/style.js | 59 +++++++- src/magister/scripts/today.js | 199 +++++++-------------------- src/magister/styles/today.css | 12 +- 9 files changed, 161 insertions(+), 199 deletions(-) diff --git a/_locales/nl/strings.json b/_locales/nl/strings.json index e48d25d..01cf164 100644 --- a/_locales/nl/strings.json +++ b/_locales/nl/strings.json @@ -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...", diff --git a/manifest-firefox.json b/manifest-firefox.json index ea67790..cabf1ca 100644 --- a/manifest-firefox.json +++ b/manifest-firefox.json @@ -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", diff --git a/manifest.json b/manifest.json index 7c3a6a4..2fc8390 100644 --- a/manifest.json +++ b/manifest.json @@ -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", diff --git a/src/magister/scripts/api.js b/src/magister/scripts/api.js index 26fd402..978eed6 100644 --- a/src/magister/scripts/api.js +++ b/src/magister/scripts/api.js @@ -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 () => { @@ -80,7 +53,6 @@ const MagisterApi = { ) }) }, - exams: { list: async (year) => { return new Promise(async (resolve, reject) => { @@ -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: "

Dit is een onvoltooid huiswerkitem.

", 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: "

In deze les heb je een schriftelijke overhoring. Neem je oortjes mee.

", 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: "

Dit item heb je al wel voltooid. Good job.

", 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( @@ -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( @@ -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( @@ -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( @@ -187,6 +174,9 @@ const MagisterApi = { }) }, activities: async () => { + if (MagisterApi.useSampleData) { + return [null] + } return new Promise(async (resolve, reject) => { magisterApiCache.activities ??= fetchWrapper( @@ -198,6 +188,9 @@ const MagisterApi = { }) }, logs: async () => { + if (MagisterApi.useSampleData) { + return [null] + } return new Promise(async (resolve, reject) => { magisterApiCache.logs ??= fetchWrapper( diff --git a/src/magister/scripts/gamification.js b/src/magister/scripts/gamification.js index f263b30..508ca4a 100644 --- a/src/magister/scripts/gamification.js +++ b/src/magister/scripts/gamification.js @@ -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 @@ -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 }) } @@ -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')` }) @@ -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) { @@ -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 }) + } + } } }) } diff --git a/src/magister/scripts/main.js b/src/magister/scripts/main.js index 58270e9..5ecd71f 100644 --- a/src/magister/scripts/main.js +++ b/src/magister/scripts/main.js @@ -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'), diff --git a/src/magister/scripts/style.js b/src/magister/scripts/style.js index 1ab88aa..f484515 100644 --- a/src/magister/scripts/style.js +++ b/src/magister/scripts/style.js @@ -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 { @@ -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') } diff --git a/src/magister/scripts/today.js b/src/magister/scripts/today.js index b7a2289..752068b 100644 --- a/src/magister/scripts/today.js +++ b/src/magister/scripts/today.js @@ -519,7 +519,7 @@ async function today() { style: `--relative-start: ${new Date(item.Start).getHoursWithDecimals()}; --duration: ${new Date(item.Einde).getHoursWithDecimals() - new Date(item.Start).getHoursWithDecimals()}; --cols: ${item.cols.length}; --cols-before: ${item.colsBefore.length};`, title: [ item.Omschrijving || 'Geen omschrijving', - item.Lokatie || item.Lokalen.map(e => e.Naam).join(', ') || 'Geen locatie', + item.Lokatie || item.Lokalen?.map(e => e.Naam).join(', ') || 'Geen locatie', item.DuurtHeleDag ? 'Hele dag' : new Date(item.Start).getFormattedTime() + '–' + new Date(item.Einde).getFormattedTime() ].join('\n') }) @@ -598,8 +598,17 @@ async function today() { // Display 'no events' if necessary if (day.events?.length < 1 && !listViewEnabled && agendaView === 'day') { let seed = cyrb128(String(day.date.getTime())) - element('i', `st-start-col-${i}-fa`, column, { class: `st-start-icon fa-duotone ${['fa-island-tropical', 'fa-snooze', 'fa-alarm-snooze', 'fa-house-day', 'fa-umbrella-beach', 'fa-bed', 'fa-face-smile-wink', 'fa-house-person-return', 'fa-house-chimney-user', 'fa-house-user', 'fa-house-heart', 'fa-calendar-heart', 'fa-skull', 'fa-rocket-launch', 'fa-bath', 'fa-bowling-ball-pin', 'fa-poo-storm', 'fa-block-question', 'fa-crab'].random(seed)}` }) - element('span', `st-start-col-${i}-disclaimer`, column, { class: 'st-start-disclaimer', innerText: day.today ? i18n('noEventsToday') : i18n('noEvents') }) + element('i', `st-start-col-${i}-fa`, column, { + class: `st-start-icon fa-duotone ${['fa-island-tropical', 'fa-snooze', 'fa-alarm-snooze', 'fa-house-day', 'fa-umbrella-beach', 'fa-bed', 'fa-face-smile-wink', 'fa-house-person-return', 'fa-house-chimney-user', 'fa-house-user', 'fa-house-heart', 'fa-calendar-heart', 'fa-skull', 'fa-rocket-launch', 'fa-bath', 'fa-bowling-ball-pin', 'fa-poo-storm', 'fa-block-question', 'fa-crab'].random(seed)}` + }) + element('span', `st-start-col-${i}-disclaimer`, column, { + class: 'st-start-disclaimer', + innerText: events.length === 0 + ? i18n('noEventsUntilDate', { date: gatherEnd.toLocaleDateString(locale, { day: 'numeric', month: 'long' }), dateShort: gatherEnd.toLocaleDateString(locale, { day: 'numeric', month: 'short' }) }) + : day.today + ? i18n('noEventsToday') + : i18n('noEvents') + }) } // Ensure a nice scrolling position if the date shown is not today @@ -675,14 +684,12 @@ async function today() { types: ['Tegel', 'Lijst'], render: async (type, placeholder) => { return new Promise(async resolve => { - let logs + if (placeholder) MagisterApi.useSampleData = true - if (placeholder) { - logs = [null] - } else { - logs = await MagisterApi.logs() - .catch(() => { return reject() }) - } + let logs = await MagisterApi.logs() + .catch(() => { return reject() }) + + if (placeholder) MagisterApi.useSampleData = false if (logs.length < 1) return resolve() let widgetElement = element('div', 'st-start-widget-logs', null, { class: 'st-tile st-widget' }) @@ -702,14 +709,12 @@ async function today() { types: ['Tegel', 'Lijst'], render: async (type, placeholder) => { return new Promise(async resolve => { - let activities + if (placeholder) MagisterApi.useSampleData = true - if (placeholder) { - activities = [null] - } else { - activities = await MagisterApi.activities() - .catch(() => { return reject() }) - } + let activities = await MagisterApi.activities() + .catch(() => { return reject() }) + + if (placeholder) MagisterApi.useSampleData = false if (activities.length < 1) return resolve() let widgetElement = element('div', 'st-start-widget-activities', null, { class: 'st-tile st-widget' }) @@ -768,50 +773,16 @@ async function today() { let viewResult = await getFromStorage('start-widget-cf-result', 'local') || 'always' let autoRotate = await getFromStorage('start-widget-cf-rotate', 'local') || 'true' - let grades, assignments, hiddenItems - if (placeholder) { - grades = [ - { - 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 - } - ] - assignments = [] - hiddenItems = new Set() - } else { - grades = await MagisterApi.grades.recent() - .catch(() => { return reject() }) - assignments = await MagisterApi.assignments.top() - .catch(() => { return reject() }) + if (placeholder) MagisterApi.useSampleData = true - hiddenItems = new Set((await getFromStorage('hiddenGrades', 'local') || [])) - } + let grades = await MagisterApi.grades.recent() + .catch(() => { return reject() }) + let assignments = await MagisterApi.assignments.top() + .catch(() => { return reject() }) + + if (placeholder) MagisterApi.useSampleData = false + + let hiddenItems = new Set((await getFromStorage('hiddenGrades', 'local') || [])) const relevantAssignments = assignments.filter(item => item.Beoordeling?.length > 0).map(item => ( { @@ -960,31 +931,12 @@ async function today() { types: ['Tegel', 'Lijst'], render: async (type, placeholder) => { return new Promise(async resolve => { - let unreadMessages + if (placeholder) MagisterApi.useSampleData = true - if (placeholder) { - unreadMessages = [ - { - 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) - } - ] - } else { - unreadMessages = await MagisterApi.messages() - .catch(() => { return reject() }) - } + let unreadMessages = await MagisterApi.messages() + .catch(() => { return reject() }) + + if (placeholder) MagisterApi.useSampleData = false if (unreadMessages.length < 1) return resolve() let widgetElement = element('div', 'st-start-widget-messages', null, { class: 'st-tile st-widget' }) @@ -1046,53 +998,13 @@ async function today() { return new Promise(async resolve => { const filterOption = await getFromStorage('start-widget-hw-filter', 'local') || 'incomplete' - let events - if (placeholder) { - events = [ - { - Start: new Date(new Date().setHours(0, 0, 0, 0) + 122400000), - Einde: new Date(new Date().setHours(0, 0, 0, 0) + 125100000), - Inhoud: "

Dit is een onvoltooid huiswerkitem.

", - Opmerking: null, - InfoType: 1, - Afgerond: false, - 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: "

In deze les heb je een schriftelijke overhoring. Neem je oortjes mee.

", - Opmerking: null, - InfoType: 2, - Afgerond: false, - 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: "

Dit item heb je al wel voltooid. Good job.

", - Opmerking: null, - InfoType: 1, - Afgerond: true, - Vakken: [ - { - Naam: "Jouw favoriete vak" - } - ] - } - ] - } else { - events = await MagisterApi.events() - .catch(() => { return reject() }) - } + if (placeholder) MagisterApi.useSampleData = true + + let events = await MagisterApi.events() + .catch(() => { return reject() }) + + if (placeholder) MagisterApi.useSampleData = false + const homeworkEvents = events.filter(item => { if (filterOption === 'incomplete') return (item.Inhoud?.length > 0 && new Date(item.Einde) > new Date() && !item.Afgerond) @@ -1145,25 +1057,12 @@ async function today() { types: ['Tegel', 'Lijst'], render: async (type, placeholder) => { return new Promise(async (resolve) => { - let assignments - if (placeholder) { - assignments = [ - { - 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) - } - ] - } else { - assignments = await MagisterApi.assignments.top() - .catch(() => { return reject() }) - } + if (placeholder) MagisterApi.useSampleData = true + + let assignments = await MagisterApi.assignments.top() + .catch(() => { return reject() }) + + if (placeholder) MagisterApi.useSampleData = false const relevantAssignments = assignments.filter(item => !item.Afgesloten && !item.IngeleverdOp) diff --git a/src/magister/styles/today.css b/src/magister/styles/today.css index 15dffd6..bd7f466 100644 --- a/src/magister/styles/today.css +++ b/src/magister/styles/today.css @@ -49,21 +49,25 @@ width: 100%; height: 84px; box-sizing: border-box; - display: flex; + display: grid; + grid-template: + 'text buttons' 32px + / 1fr auto; + align-items: center; padding: 32px 32px 20px; transition: background-color 200ms, padding-right 200ms, opacity 200ms; } #st-start-header-text-wrapper { flex: 1; - display: flex; + display: grid; + grid-template-columns: 100% 100%; overflow: hidden; } #st-start-header-text, #st-start-header-greeting { - flex: 100% 0 0; - width: 100%; + flex: 1; margin-bottom: 0; text-wrap: nowrap; overflow: hidden;