Skip to content

Commit f1042cc

Browse files
committed
Add options and minor fixes
Signed-off-by: Anvay Mathur <[email protected]>
1 parent 8a75ff1 commit f1042cc

File tree

13 files changed

+305
-247
lines changed

13 files changed

+305
-247
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ lerna-debug.log*
99

1010
node_modules
1111
dist
12+
dist.zip
1213
dist-ssr
1314
*.local
1415

manifest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ export default defineManifest(async (env) => ({
3737
"js": ["src/content_script/guardianHome/index.ts"]
3838
}
3939
],
40+
"options_ui": {
41+
"page": "src/options/index.html",
42+
"open_in_tab": false
43+
},
44+
"icons": {
45+
"128": "public/icon.png"
46+
},
4047
"permissions": ["storage"],
4148
"web_accessible_resources": [
4249
{

src/content_script/guardianHome/GPA.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
55
export let classManager: ClassManager;
66
7-
console.log("RERENDERING");
8-
97
$: sem1GPA = classManager.calculateGPA(1);
108
$: sem2GPA = classManager.calculateGPA(2);
119
@@ -19,6 +17,7 @@
1917
</label>
2018

2119
{#if !hideGPA}
20+
<p class="tw-font-bold">Do not rely on any data from SAS PES!!</p>
2221
{#if sem1GPA && sem1GPA !== -1}
2322
<p>First Semester GPA: {classManager.calculateGPA(1).toFixed(2)}</p>
2423
{:else}

src/content_script/guardianHome/index.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,20 @@
2525
import { Class, ClassManager } from "../../models/classes";
2626
import GPA from "./GPA.svelte";
2727
import { listOfGrades, type Grade } from "../../models/grades";
28+
import { getFinalPercent } from "../scores/scoresUtilities";
2829

2930
const classManager = new ClassManager([]);
3031

3132
const rows = document.querySelectorAll(".linkDescList.grid > tbody > tr.center:not(.th2)");
3233

34+
35+
3336
for (const row of rows) {
3437
const nameEle = row.querySelector("td:nth-child(2)");
35-
const s1GradeEle = row.querySelector("td:nth-child(3)");
36-
const s2GradeEle = row.querySelector("td:nth-child(4)");
38+
const s1GradeEle = row.querySelector("td:nth-child(3) > a") as HTMLAnchorElement;
39+
const s2GradeEle = row.querySelector("td:nth-child(4) > a");
40+
41+
3742

3843
if (!nameEle || !s1GradeEle || !s2GradeEle) continue;
3944

@@ -49,6 +54,23 @@ for (const row of rows) {
4954
if (!listOfGrades.includes(s2Grade as Grade)) s2Grade = null;
5055

5156
if (!s1Grade && !s2Grade) continue;
57+
58+
if (s1Grade !== null && s1Grade !== "INC" && s1GradeEle.href !== null) {
59+
const url = new URL(s1GradeEle.href);
60+
let finalPercent = getFinalPercent(
61+
url.searchParams.get(
62+
"frn",
63+
)!,
64+
url.searchParams.get("fg")!
65+
);
66+
67+
finalPercent.then((f) => {
68+
console.log(f, "F");
69+
if (f !== null)
70+
s1GradeEle.innerHTML += ` (${f.toFixed(2)})`;
71+
})
72+
}
73+
5274
classManager.addClass(new Class(name, { s1: s1Grade as Grade | null, s2: s2Grade as Grade | null }))
5375
}
5476

src/content_script/home/Home.svelte

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,23 @@
5555
</h1>
5656
<!-- svelte-ignore missing-declaration -->
5757
<p class="tw-font-medium tw-text-lg">v{SAS_PES_VERSION}</p>
58+
<p>
59+
<a href="https://github.com/sas-fossdev/saspes">Website/Source Code</a> |
60+
<a href="https://github.com/sas-fossdev/saspes/issues">Issue Tracker</a>
61+
| <a href="https://forms.gle/aDtP57UyEBQU9gQx6">Feedback/Bug Report Form</a>
62+
|
63+
<!-- svelte-ignore missing-declaration -->
64+
<a
65+
href="#"
66+
on:click={() => {
67+
if (chrome.runtime.openOptionsPage) {
68+
chrome.runtime.openOptionsPage();
69+
} else {
70+
window.open(chrome.runtime.getURL("src/options/index.html"));
71+
}
72+
}}>Options</a
73+
>
74+
</p>
5875
<p><strong>Do not rely</strong> on the data provided by SAS PES.</p>
5976
{#if board}
6077
<!-- this is for a message board type of thing, where messages can be displayed without updating the extension everytime. This does NOT load javascript. -->
@@ -63,6 +80,9 @@
6380
</h3>
6481
<p class="tw-text-sm">{@html board.split("æ")[1]}</p>
6582
{/if}
83+
<p class="tw-mt-2">
84+
Copyright &copy; 2024 Anvay Mathur and the SAS PES Authors
85+
</p>
6686
</div>
6787

6888
<style>

src/content_script/scores/ScoreTools.svelte

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
>
1717
<div>
1818
<h1 class="tw-pb-2 tw-text-2xl">Tools</h1>
19-
<select bind:value={curTool}>
19+
<select
20+
bind:value={curTool}
21+
class="tw-rounded-md tw-border-[#CCCCCC] tw-border-solid tw-border tw-p-1"
22+
>
2023
<option value={Tools.CATEGORY_WEIGHTING}
2124
>Category Weighting and Advanced See All Possibilities</option
2225
>
@@ -27,6 +30,11 @@
2730
{#if curTool == Tools.CATEGORY_WEIGHTING}
2831
<SingleAssignment {finalPercent} {gradeManager} />
2932
{/if}
33+
<p>
34+
<span class="tw-font-bold">Do not rely on any data from SAS PES!!</span>
35+
Teachers can override your final grade, and calculations are not entirely
36+
accurate.
37+
</p>
3038
</div>
3139
{/if}
3240
{/await}

src/content_script/scores/index.ts

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import { Assignment, Category, GradeManager, listOfGrades, type Grade, gradeToPercent } from "../../models/grades";
2626
import FinalPercent from "./FinalPercent.svelte";
2727
import ScoreTools from "./ScoreTools.svelte";
28+
import { getFinalPercent } from "./scoresUtilities";
2829

2930
export enum Tools {
3031
CATEGORY_WEIGHTING = "CATEGORY_WEIGHTING",
@@ -51,31 +52,6 @@ function waitForElm(selector: string): Promise<Element | null> {
5152
});
5253
}
5354

54-
async function getFinalPercent(): Promise<number | null> {
55-
let finalGrade: number | null = null;
56-
const url = new URL(window.location.href);
57-
let text: string | null = null;
58-
try {
59-
text = await fetch(
60-
`https://powerschool.sas.edu.sg/guardian/scores_ms_guardian.html?frn=${url.searchParams.get(
61-
"frn",
62-
)}&fg=${url.searchParams.get("fg")}`,
63-
).then((res) => res.text());
64-
} catch (e) {
65-
console.error(e);
66-
return null;
67-
}
68-
console.log("Done fetching");
69-
70-
if (text) {
71-
let match = text.match(/\[decode;[^;]*;[^;]*;([^;]*);/);
72-
if (match?.[1] && !isNaN(parseFloat(match[1]))) {
73-
finalGrade = parseFloat(match[1]);
74-
return finalGrade;
75-
}
76-
}
77-
return null;
78-
}
7955

8056
let gradeManagerO = new GradeManager([], [], 100);
8157

@@ -160,7 +136,14 @@ document
160136
.querySelector(".box-round")!
161137
.insertBefore(target, document.querySelector(".box-round > p"));
162138

163-
let finalPercent = getFinalPercent();
139+
const url = new URL(window.location.href);
140+
141+
let finalPercent = getFinalPercent(
142+
url.searchParams.get(
143+
"frn",
144+
)!,
145+
url.searchParams.get("fg")!
146+
);
164147

165148
new FinalPercent({
166149
target: target as Element,

0 commit comments

Comments
 (0)