11/**
2- *
2+ *
33 * @copyright Copyright (c) 2018-2019 Gary Kim <[email protected] > 4- *
4+ *
55 * @author Gary Kim <[email protected] > 6- *
6+ *
77 * SAS Powerschool Enhancement Suite - A browser extension to improve the experience of SAS Powerschool.
88 *
99 * This program is free software: you can redistribute it and/or modify
10- * it under the terms of the GNU Affero General Public License as
10+ * it under the terms of the GNU Affero General Public License as
1111 * published by the Free Software Foundation, version 3.
1212 *
1313 * This program is distributed in the hope that it will be useful,
1717 *
1818 * You should have received a copy of the GNU Affero General Public License
1919 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20- *
20+ *
2121 */
2222
2323
@@ -42,7 +42,7 @@ browser.storage.local.get({percent_main_page: true}).then(
4242) ;
4343main ( ) ;
4444function main ( ) {
45-
45+
4646 // Button on options page
4747 let $topright = $ ( 'ul#tools' ) ;
4848 if ( $topright . length === 0 ) {
@@ -76,20 +76,36 @@ function main_page() {
7676 let student_name = document . querySelector ( '#userName' ) . querySelector ( 'span' ) . innerText ;
7777 let second_semester = false ;
7878 let courses = [ ] ;
79- let percents = [ ] ;
80- let $grade_rows = $ ( 'div#quickLookup table.grid' ) . find ( 'tr' ) ;
79+ let $grade_rows = $ ( '#quickLookup table.grid' ) . find ( 'tr' ) ;
80+ let s1col = 0 ;
81+ let s2col = 0 ;
82+
8183 if ( $grade_rows . eq ( 1 ) . html ( ) . match ( "S2" ) != null ) {
8284 second_semester = true ;
85+ let curr = 0 ;
86+ $grade_rows . eq ( 1 ) . find ( 'th' ) . get ( ) . forEach ( e => {
87+ switch ( e . innerText ) {
88+ case "S1" :
89+ s1col = curr ;
90+ break ;
91+ case "S2" :
92+ s2col = curr ;
93+ break ;
94+ default :
95+ break ;
96+ }
97+ curr += parseInt ( e . getAttribute ( 'colspan' ) ) || 1 ;
98+ } ) ;
8399 }
84100 for ( let i = 0 ; i < $grade_rows . length ; i ++ ) {
85101 let $course ;
86102 if ( second_semester ) {
87- // TODO: Currently not working after 2019 Powerschool update. Needs to be updated.
88- $course = $grade_rows . eq ( i ) . children ( 'td' ) . eq ( 3 ) . find ( " a[href^=' scores.html?']" ) ;
89- let first_grade = $grade_rows . eq ( i ) . children ( 'td' ) . eq ( 2 ) . find ( ` a[href^=' scores.html?']` ) ;
90- if ( first_grade . length === 1 ) {
91- if ( gradeToGPA ( first_grade . text ( ) ) !== - 1 ) {
92- fill_percent ( first_grade , `https://powerschool.sas.edu.sg/guardian/${ first_grade . attr ( 'href' ) } ` , [ 0 ] , 0 ) ;
103+ let $cells = $grade_rows . eq ( i ) . find ( 'td' ) ;
104+ $course = $cells . eq ( s2col ) . find ( ' a[href^=" scores.html"]' ) ;
105+ let $ first_grade = $cells . eq ( s1col ) . find ( ' a[href^=" scores.html"]' ) ;
106+ if ( $ first_grade. length === 1 ) {
107+ if ( gradeToGPA ( $ first_grade. text ( ) ) !== - 1 ) {
108+ fill_percent ( $ first_grade, `https://powerschool.sas.edu.sg/guardian/${ $ first_grade. attr ( 'href' ) } ` , [ 0 ] , 0 ) ;
93109 }
94110 }
95111 } else {
@@ -107,7 +123,7 @@ function main_page() {
107123 fill_percent ( $course , "https://powerschool.sas.edu.sg/guardian/" + $course . attr ( 'href' ) , courses [ courses . length - 1 ] , "fp" ) ;
108124 }
109125 }
110-
126+
111127 }
112128 $ ( "table[border='0'][cellpadding='3'][cellspacing='1'][width='100%']" ) . prepend ( `<tr><td align="center">Current Semester GPA (${ second_semester ?'S2' :'S1' } ): ${ calculate_gpa ( courses ) } </td></tr>` ) ;
113129
@@ -182,4 +198,4 @@ function html2nodelist(html_string) {
182198 let temp = document . createElement ( 'template' ) ;
183199 temp . innerHTML = html_string ;
184200 return temp . content . childNodes ;
185- }
201+ }
0 commit comments