From a44c423d125060f9ea5d9d1a79740ae6e818fa95 Mon Sep 17 00:00:00 2001 From: Austin Jenchi Date: Wed, 6 Apr 2022 22:10:27 -0700 Subject: [PATCH] Fix calendar parsing for new MyUW Vue schedule cards --- js/insertButton.js | 20 +++++++++++--------- js/schedule.js | 7 +++---- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/js/insertButton.js b/js/insertButton.js index 5f7a734..b123f64 100644 --- a/js/insertButton.js +++ b/js/insertButton.js @@ -8,14 +8,16 @@ function addButton(schedule) { } function grabSchedule () { - console.log("Test"); - window.postMessage({ type: "schedule", schedule: JSON.stringify(WSData.course_data_for_term(VisualScheduleCard.term))}, "*"); - window.postMessage({ type: "newTab", newSchedule: JSON.stringify(WSData.course_data_for_term(VisualScheduleCard.term))}, "*"); + const schedule = document.getElementById('myuw-visual-schedule').__vue__.$store.state.visual_schedule.value.current; + schedule.sections = schedule.periods[0].sections; + window.postMessage({ type: "schedule", schedule: JSON.stringify(schedule)}, "*"); + window.postMessage({ type: "newTab", newSchedule: JSON.stringify(schedule)}, "*"); } -let oldHandler = VisualScheduleCard.render_handler; -VisualScheduleCard.render_handler = function() { - oldHandler(); - addButton(VisualScheduleCard.dom_target[0]) -} -VisualScheduleCard.render_init() +const buttonTimer = setInterval(() => { + const ele = document.getElementById('myuw-visual-schedule'); + if (ele) { + addButton(ele.children[0]); + clearInterval(buttonTimer); + } +}, 500); diff --git a/js/schedule.js b/js/schedule.js index ddcd5e8..3c904bb 100644 --- a/js/schedule.js +++ b/js/schedule.js @@ -34,8 +34,7 @@ function Schedule(newSchedule) { location = "Room TBD"; } - let dateSplit = response.term.first_day_quarter.split('-'); - let first_day = new Date(dateSplit[0], dateSplit[1] - 1, dateSplit[2]); + let first_day = new Date(response.term.first_day_quarter); if (days.length > 0) { while (!days.includes(this.WEEKDAYS[first_day.getDay()])) { first_day.setDate(first_day.getDate() + 1); @@ -65,8 +64,8 @@ function Schedule(newSchedule) { "title": section.curriculum_abbr + " " + section.course_number + " (" + type + ")", "description": section.curriculum_abbr + " " + section.course_number + " - " + section.course_title, "location": location, - "start_time": (section.meetings[j].start_time) ? (first_day.toISOString().substring(0, 10) + " " + section.meetings[j].start_time) : null, - "end_time": (section.meetings[j].start_time) ? (first_day.toISOString().substring(0, 10) + " " + section.meetings[j].end_time) : null, + "start_time": (section.meetings[j].start_time) ? (first_day.toISOString().substring(0, 10) + "T" + section.meetings[j].start_time.substring(11)) : null, + "end_time": (section.meetings[j].start_time) ? (first_day.toISOString().substring(0, 10) + "T" + section.meetings[j].end_time.substring(11)) : null, "freq": "WEEKLY", "until": end_date.toString(), "byday": days