@@ -192,7 +192,7 @@ function extractGradeCategories (table) {
192192 const table_rows = table . getElementsByTagName ( "tr" ) ;
193193 const category_set = new Set ( ) ;
194194 for ( let i = 1 ; i < table_rows . length - 1 ; i ++ ) {
195- category_set . add ( table_rows [ i ] . getElementsByTagName ( "td" ) [ 1 ] . getElementsByTagName ( "a " ) [ 0 ] . innerText ) ;
195+ category_set . add ( table_rows [ i ] . getElementsByTagName ( "td" ) [ 1 ] . getElementsByTagName ( "span " ) [ 1 ] . innerText ) ;
196196 }
197197 return Array . from ( category_set ) ;
198198}
@@ -202,11 +202,15 @@ function extractGradeCategories (table) {
202202 * @returns {ClassAssignment[] } List of all assignments
203203 */
204204function extractAssignmentList ( ) {
205- const table = document . querySelector ( "#content-main > div.box-round > table:nth-child(4) > tbody" ) ;
205+ const table = document . querySelector ( "table.zebra.grid > tbody" ) ;
206206 const assignments = [ ] ;
207207 [ ...table . querySelectorAll ( 'tr' ) ] . slice ( 1 , - 1 ) . forEach ( ( e , i ) => {
208208 const curr = e . querySelectorAll ( 'td' ) ;
209- assignments . push ( new ClassAssignment ( i , curr [ 0 ] . innerHTML , curr [ 1 ] . innerText , curr [ 2 ] . innerHTML , isIndicatorPresent ( curr [ 3 ] ) , isIndicatorPresent ( curr [ 4 ] ) , isIndicatorPresent ( curr [ 5 ] ) , isIndicatorPresent ( curr [ 6 ] ) , isIndicatorPresent ( curr [ 7 ] ) , curr [ 9 ] . innerHTML , curr [ 11 ] . innerHTML ) ) ;
209+ let offset = 0 ;
210+ if ( curr . length === 14 ) {
211+ offset = 1 ;
212+ }
213+ assignments . push ( new ClassAssignment ( i , curr [ 0 ] . innerHTML , curr [ 1 ] . innerText , curr [ 2 ] . innerHTML , isIndicatorPresent ( curr [ 3 + offset ] ) , isIndicatorPresent ( curr [ 4 + offset ] ) , isIndicatorPresent ( curr [ 5 + offset ] ) , isIndicatorPresent ( curr [ 6 + offset ] ) , isIndicatorPresent ( curr [ 7 + offset ] ) , isIndicatorPresent ( curr [ 8 + offset ] ) , isIndicatorPresent ( curr [ 9 + offset ] ) , curr [ 10 + offset ] . innerText , curr [ 11 + offset ] . innerText . trim ( ) ) ) ;
210214 } ) ;
211215 return assignments ;
212216}
@@ -216,17 +220,17 @@ function extractAssignmentList () {
216220 * @returns {boolean } boolean representing whether input has child nodes and are set to visible.
217221 */
218222function isIndicatorPresent ( node ) {
219- return node . hasChildNodes ( ) && node . childNodes [ 0 ] . style . display !== 'none' ;
223+ return node . childNodes ?. length === 7 || false ;
220224}
221225/**
222226 * Return Assignment instances for the given class page.
223227 * @param {Element } node Root node element of the class page.
224228 * @returns {Assignment[] } Assignments in this course
225229 */
226- function assignments ( node ) {
230+ function assignmentsFromNode ( node ) {
227231 const tr = [ ] ;
228232 // Find assignments table, get it's rows, take out the header and legend rows.
229- [ ...node . querySelector ( 'table[align=center ' ) . querySelectorAll ( 'tr' ) ] . slice ( 1 , - 1 ) . forEach ( ( e , i ) => {
233+ [ ...node . querySelector ( 'table.zebra.grid ' ) . querySelectorAll ( 'tr' ) ] . slice ( 1 , - 1 ) . forEach ( ( e , i ) => {
230234 const curr = e . querySelectorAll ( 'td' ) ;
231235 const assignment = new Assignment ( curr [ 2 ] ?. innerText || "" , curr [ curr . length - 1 ] ?. innerText || "" , i ) ;
232236 const missingIcon = e . querySelector ( 'img[src="/images/icon_missing.gif"]' ) ;
@@ -238,12 +242,53 @@ function assignments (node) {
238242 return tr ;
239243}
240244
245+ /**
246+ * Return Assignment instances for the given class page.
247+ * @param {String } student_id student id for the current user
248+ * @param {String } sectino_id section id for the course being requested
249+ * @param {String } start_date start date in YYYY-MM-DD format
250+ * @param {String } end_date end date in YYYY-MM-DD format
251+ * @returns {Assignment[] } Assignments in this course
252+ */
253+ function assignmentsFromAPI ( studentId , sectionId , startDate , endDate ) {
254+ const assignmentList = [ ] ;
255+ try {
256+ fetch ( 'https://powerschool.sas.edu.sg/ws/xte/assignment/lookup' , {
257+ method : "POST" ,
258+ headers : {
259+ 'Content-Type' : 'application/json' ,
260+ } ,
261+ body : JSON . stringify ( {
262+ "student_ids" : [ studentId ] ,
263+ "section_ids" : [ sectionId ] ,
264+ "start_date" : startDate ,
265+ "end_date" : endDate ,
266+ } ) ,
267+ credentials : "same-origin" ,
268+ } ) . then ( response => response . json ( ) ) . then ( response => {
269+ for ( let i = 0 ; i < response . length ; i ++ ) {
270+ if ( response [ i ] . _assignmentsections ?. length ) {
271+ const assignmentData = response [ i ] . _assignmentsections [ 0 ] ;
272+ const assignment = new Assignment ( assignmentData . name , assignmentData . _assignmentscores [ 0 ] ?. actualscoreentered || "" , i ) ;
273+ if ( assignmentData . _assignmentscores [ 0 ] ?. ismissing || null ) {
274+ assignment . addStatus ( Assignment . statuses . MISSING ) ;
275+ }
276+ assignmentList . push ( assignment ) ;
277+ }
278+ }
279+ } ) ;
280+ } catch ( e ) {
281+ return [ ] ;
282+ }
283+ return assignmentList ;
284+ }
285+
241286/**
242287 * Return course title of active class page
243288 * @returns {String } Course title
244289 */
245290function extractCourseTitle ( ) {
246- return document . getElementsByTagName ( 'h2' ) [ 0 ] . innerHTML ;
291+ return document . querySelector ( "tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1)" ) . innerText ;
247292}
248293
249294/**
@@ -366,7 +411,8 @@ export {
366411 getFinalPercent ,
367412 extractGradeCategories ,
368413 extractAssignmentList ,
369- assignments ,
414+ assignmentsFromNode ,
415+ assignmentsFromAPI ,
370416 calculate_credit_hours ,
371417 getSavedGrades ,
372418 saveGradesLocally ,
0 commit comments