Skip to content

Commit d4d9f92

Browse files
committed
fix: add function to get current term
Again, aiming for clarity in the main_page function. Wrapping the if statement's very long jQuery parse into a function name that's in English makes the code easier on the eyes. Signed-off-by: Lucas Sta Maria <[email protected]>
1 parent 728790f commit d4d9f92

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

src/js/saspowerschoolff.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ function main_page () {
8181
let second_semester = isSecondSemester();
8282
const courses = [];
8383
const $grade_rows = $('#quickLookup table.grid').find('tr');
84-
let current_term = "";
85-
let attendance_href = "";
8684

8785
for (let i = 0; i < $grade_rows.length; i++) {
8886
let $course;
@@ -115,9 +113,7 @@ function main_page () {
115113
}
116114
}
117115
}
118-
if ((attendance_href = $grade_rows.eq($grade_rows.length - 1)?.find('a[href*="attendancedates"]')?.[0]?.href)) { // Check that attendance_href exists and if it does, run the next line.
119-
current_term = new URL(attendance_href).searchParams.get("term");
120-
}
116+
let current_term = getCurrentTerm();
121117
showCurrentGPA(second_semester, courses);
122118

123119
if (second_semester) {
@@ -243,6 +239,21 @@ function showCurrentGPA (second_semester, courses) {
243239
$("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>`);
244240
}
245241

242+
/**
243+
* Returns the current semester by parsing HTML.
244+
* @return {string} representing the current semester
245+
*/
246+
function getCurrentTerm () {
247+
const $grade_rows = $('#quickLookup table.grid').find('tr');
248+
let attendance_href = "";
249+
let current_term = "";
250+
if ((attendance_href = $grade_rows.eq($grade_rows.length - 1)?.find('a[href*="attendancedates"]')?.[0]?.href)) { // Check that attendance_href exists and if it does, run the next line.
251+
current_term = new URL(attendance_href).searchParams.get("term");
252+
}
253+
254+
return current_term;
255+
}
256+
246257
/**
247258
* Show the first semester GPA.
248259
*/

0 commit comments

Comments
 (0)