Skip to content

Commit

Permalink
fixed linter errors
Browse files Browse the repository at this point in the history
Signed-off-by: Suhas Hariharan <hariharan774531@sas.edu.sg>
  • Loading branch information
Suhas Hariharan committed Nov 3, 2021
1 parent c992154 commit 0d30ba0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
54 changes: 28 additions & 26 deletions src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const grade_gpa = {
* @param {string} grade The grade to convert.
* @returns {number} The corresponding grade point average.
*/
function gradeToGPA(grade) {
function gradeToGPA (grade) {
if (grade in grade_gpa) {
return grade_gpa[grade];
}
Expand All @@ -72,7 +72,7 @@ const grade_fp = {
* @param {string} grade The grade to convert.
* @returns {number} The corresponding final percent.
*/
function gradeToFP(grade) {
function gradeToFP (grade) {
if (grade in grade_fp) {
return grade_fp[grade];
}
Expand All @@ -93,7 +93,7 @@ const fprange = {
'0-15': 'F',
};

function fpToGrade(finalPercent) {
function fpToGrade (finalPercent) {
return getKeyRange(fprange, parseFloat(parseFloat(finalPercent).toFixed(2)));
}

Expand All @@ -102,7 +102,7 @@ function fpToGrade(finalPercent) {
* @param {Course[]} courses The courses for which the overall grade point average should be calculated.
* @returns {string} The grade point average to the hundredth place.
*/
function calculate_gpa(courses) {
function calculate_gpa (courses) {
let courses_with_grades = 0;
let sum = 0;
for (var i = 0; i < courses.length; i++) {
Expand All @@ -117,7 +117,7 @@ function calculate_gpa(courses) {
}
return (sum / courses_with_grades).toFixed(2);

function course_boost(course_name, grade) {
function course_boost (course_name, grade) {
if (gradeToGPA(grade) < 1.8) {
return 0;
}
Expand All @@ -128,7 +128,7 @@ function calculate_gpa(courses) {
}
}

function calculate_credit_hours(course_name) {
function calculate_credit_hours (course_name) {
const double_effect_courses = [`English 10/American History`, `English 9/World History`];
if (double_effect_courses.includes(course_name)) {
return 2;
Expand All @@ -144,7 +144,7 @@ function calculate_credit_hours(course_name) {
* @param {String} html course page html
* @returns {Number|undefined} The final percent
*/
function extractFinalPercent(html) {
function extractFinalPercent (html) {
let number;
try {
let current_string = html.match(/(?=document\.write).*/g)[1];
Expand All @@ -166,7 +166,7 @@ function extractFinalPercent(html) {
* @param {String} semester string representing semester that the request is for
* @returns {Number|undefined} The final percent
*/
async function getFinalPercent(frn, semester) {
async function getFinalPercent (frn, semester) {
let number;
try {
await fetch(`https://powerschool.sas.edu.sg/guardian/scores_ms_guardian.html?frn=${frn}&fg=${semester}`, { credentials: "same-origin" }).then(response => response.text()).then(response => {
Expand All @@ -188,7 +188,7 @@ async function getFinalPercent(frn, semester) {
* @param {Node} table node representing table
* @returns {String[]} List of all categories
*/
function extractGradeCategories(table) {
function extractGradeCategories (table) {
const table_rows = table.getElementsByTagName("tr");
const category_set = new Set();
for (let i = 1; i < table_rows.length - 1; i++) {
Expand All @@ -201,7 +201,7 @@ function extractGradeCategories(table) {
* Extract all assignments from a class.
* @returns {ClassAssignment[]} List of all assignments
*/
function extractAssignmentList() {
function extractAssignmentList () {
const table = document.querySelector("table.zebra.grid > tbody");
const assignments = [];
[...table.querySelectorAll('tr')].slice(1, -1).forEach((e, i) => {
Expand All @@ -215,19 +215,19 @@ function extractAssignmentList() {
return assignments;
}
/**
* Return whether the given row contains an indicator of any kind(i.e missing, late)
* Return whether the given row contains an indicator of any kind(i.e missing, late)
* @param {Element} node Node representing individual row of each assignment
* @returns {boolean} boolean representing whether input has child nodes and are set to visible.
*/
function isIndicatorPresent(node) {
function isIndicatorPresent (node) {
return node.hasChildNodes() && node.querySelector("div.ps-icon");
}
/**
* Return Assignment instances for the given class page.
* @param {Element} node Root node element of the class page.
* @returns {Assignment[]} Assignments in this course
*/
function assignmentsFromNode(node) {
function assignmentsFromNode (node) {
const tr = [];
// Find assignments table, get it's rows, take out the header and legend rows.
[...node.querySelector('table.zebra.grid').querySelectorAll('tr')].slice(1, -1).forEach((e, i) => {
Expand All @@ -250,19 +250,21 @@ function assignmentsFromNode(node) {
* @param {String} end_date end date in YYYY-MM-DD format
* @returns {Assignment[]} Assignments in this course
*/
function assignmentsFromAPI(studentId, sectionId, startDate, endDate) {
function assignmentsFromAPI (studentId, sectionId, startDate, endDate) {
const assignmentList = [];
try {
fetch('https://powerschool.sas.edu.sg/ws/xte/assignment/lookup', {
method: "POST", headers: {
'Content-Type': 'application/json'
method: "POST",
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
"student_ids": [studentId],
"section_ids": [sectionId],
"start_date": startDate,
"end_date": endDate
}), credentials: "same-origin"
"end_date": endDate,
}),
credentials: "same-origin",
}).then(response => response.json()).then(response => {
for (let i = 0; i < response.length; i++) {
if (response[i]._assignmentsections?.length) {
Expand All @@ -285,15 +287,15 @@ function assignmentsFromAPI(studentId, sectionId, startDate, endDate) {
* Return course title of active class page
* @returns {String} Course title
*/
function extractCourseTitle() {
return document.querySelector("tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1)").innerText
function extractCourseTitle () {
return document.querySelector("tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1)").innerText;
}

/**
* Retrieve category weighting for class from local storage
* @returns {Map<String, Object>} Map of weighting assigned to each category for course
*/
async function getSavedCategoryWeighting() {
async function getSavedCategoryWeighting () {
const courseName = extractCourseTitle() + "-catmap";
const catmap = await browser.storage.local.get(courseName);
if (catmap === undefined || (Object.keys(catmap).length === 0 && catmap.constructor === Object) || catmap[courseName] === undefined) return false;
Expand All @@ -304,7 +306,7 @@ async function getSavedCategoryWeighting() {
* Save category weighting for class to local storage
* @param {Map<String, Object>} catmap Map of weighting assigned to each category for course
*/
async function saveCategoryWeighting(catmap) {
async function saveCategoryWeighting (catmap) {
const courseName = extractCourseTitle();
const data = {};
data[courseName + "-catmap"] = catmap;
Expand All @@ -317,7 +319,7 @@ async function saveCategoryWeighting(catmap) {
* @param {String} username users full name
* @returns {Promise<Course[]>} list of courses objects for that user
*/
async function getSavedGrades(username) {
async function getSavedGrades (username) {
const courses = [];
const user_data = (await browser.storage.local.get("user_data")).user_data;
if (user_data !== undefined) {
Expand Down Expand Up @@ -346,7 +348,7 @@ async function getSavedGrades(username) {
* @param {String} username users full name
* @param {Course[]} courses list of course objects to save
*/
async function saveGradesLocally(username, courses) {
async function saveGradesLocally (username, courses) {
const data = await getLocalConfig() || {};

if (data.opted_in === undefined) {
Expand Down Expand Up @@ -381,7 +383,7 @@ async function saveGradesLocally(username, courses) {
* @async
* @returns {Config} an object representing the user's config from the browser's local storage
*/
async function getLocalConfig() {
async function getLocalConfig () {
const data = await browser.storage.local.get(null);
return data;
}
Expand All @@ -390,7 +392,7 @@ async function getLocalConfig() {
* Retrieves the default extension config for new users.
* @returns {Config} an object representing the default config.
*/
function getDefaultConfig() {
function getDefaultConfig () {
const data = { opted_in: { changed: false, value: false }, percent_main_page: { changed: false, value: true } };
return data;
}
Expand Down
4 changes: 2 additions & 2 deletions src/js/saspowerschoolff.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ async function main_page () {

async function class_page () {
// Show final percent
await new Promise(r => setTimeout(r, 750)); // adds delay prior to running to ensure that class page JS is finished running.
await new Promise((resolve, reject) => setTimeout(resolve, 750)); // adds delay prior to running to ensure that class page JS is finished running.
const currentUrl = new URL(document.location.href);
const number = await getFinalPercent(currentUrl.searchParams.get("frn"), currentUrl.searchParams.get("fg")) || "";
if (!number) {
Expand Down Expand Up @@ -352,7 +352,7 @@ async function getCourses (second_semester, sem1_col, sem2_col) {
startDate = startDate.split("/")[2] + "-" + startDate.split("/")[0] + "-" + startDate.split("/")[1];
let endDate = currentUrl.searchParams.get("enddate");
endDate = endDate.split("/")[2] + "-" + endDate.split("/")[0] + "-" + endDate.split("/")[1];
const studentId = page.querySelector("div .xteContentWrapper").getAttribute("data-ng-init").split("\n")[0].split("= '")[1].replace("';","").substring(3);
const studentId = page.querySelector("div .xteContentWrapper").getAttribute("data-ng-init").split("\n")[0].split("= '")[1].replace("';", "").substring(3);
const assignment_list = assignmentsFromAPI(studentId, sectionId, startDate, endDate);
courses.push(new Course(temp.trim(), currentUrlString, $course.text(), finalPercent, assignment_list));
if (gradeToGPA($course.text()) !== -1) {
Expand Down

0 comments on commit 0d30ba0

Please sign in to comment.