11/*
22 SAS Powerschool Enhancement Suite - A browser extension to improve the experience of SAS Powerschool.
33
4- Copyright (C) 2018-2019 Gary Kim ( gary@ydgkim.com)
4+ Copyright (C) 2018-2019 Gary Kim < gary@garykim.dev>
55
66 This program is free software: you can redistribute it and/or modify
77 it under the terms of the GNU General Public License as published by
2020
2121'use strict' ;
2222
23+ const fprange = {
24+ '0-15' : 'F' ,
25+ '15-25' : 'D' ,
26+ '25-35' : 'D+' ,
27+ '35-45' : 'C' ,
28+ '45-55' : 'C+' ,
29+ '55-65' : 'B' ,
30+ '65-75' : 'B+' ,
31+ '75-85' : 'A' ,
32+ '85-90' : 'A+'
33+ }
34+
2335let percent_main_page = true ;
2436browser . storage . local . get ( { percent_main_page : true } ) . then (
2537 function ( returned ) {
@@ -41,7 +53,7 @@ function main( jQuery ) {
4153 } ) ;
4254
4355
44- let page_url = window . location . href ;
56+ let page_url = window . location . href . split ( '#' ) [ 0 ] ;
4557 if ( page_url == "https://powerschool.sas.edu.sg/guardian/homeHS.html" ) {
4658 main_page ( ) ;
4759 analytics_message ( "Main Page" ) ;
@@ -188,6 +200,8 @@ function main_page() {
188200 */
189201}
190202function class_page ( ) {
203+
204+ // Show final percent
191205 let current_string = $ ( "table.linkDescList" ) . html ( ) ;
192206 current_string = current_string . match ( / (? = d o c u m e n t \. w r i t e ) .* / g) [ 1 ] ;
193207 current_string = / \[ .* \] / g. exec ( current_string ) [ 0 ] . slice ( 1 , - 1 ) ;
@@ -198,6 +212,42 @@ function class_page() {
198212 return ;
199213 }
200214 document . querySelector ( "table.linkDescList" ) . append ( html2node ( `<tr><td><strong>Final Percent: </strong></td><td>` + parseFloat ( number ) . toFixed ( 2 ) + ` <div class="tooltip saspe">ⓘ<span class="tooltiptext saspe">85: A+ | 75: A <br />65: B+ | 55: B <br />45: C+ | 35: C <br/>25: D+ | 15: D</span></div></td></tr>` ) ) ;
215+
216+
217+ // Hypo Assignment
218+ let $hypo_assignment = $ ( '<div></div>' ) . addClass ( 'saspes-section' ) ;
219+ let hypo_assignment_info = {
220+ weight : 0 ,
221+ grade : 'B'
222+ } ;
223+
224+ $hypo_assignment . html ( '<h3>Hypothetical Assignment</h3> <label for="saspes-assignment-effect" >Effect of new assignment (currently): </label>' ) ;
225+
226+
227+ $ ( '<input type="number" min="0" max="100" value="0" id="saspes-assignment-effect" />' ) . on ( 'input' , ( e ) => {
228+ hypo_assignment_info . weight = parseInt ( e . currentTarget . value ) ;
229+ showHypoGrade ( ) ;
230+ } ) . appendTo ( $hypo_assignment ) ;
231+ $hypo_assignment . append ( $ ( '<text>% </text>' ) )
232+ $hypo_assignment . append ( $ ( '<label for="hypo-grade-select">Grade of new assignment: </label>' ) ) ;
233+ $ ( '<select id="hypo-grade-select"><option value="A+">A+</option><option value="A">A</option><option value="B+">B+</option><option value="B" selected="">B</option><option value="C+">C+</option><option value="C">C</option><option value="D+">D+</option><option value="D">D</option><option value="F">F</option></select>' ) . on ( 'change' , ( e ) => {
234+ hypo_assignment_info . grade = e . currentTarget . value ;
235+ showHypoGrade ( ) ;
236+ } ) . appendTo ( $hypo_assignment ) ;
237+ $hypo_assignment . append ( `<br /><h4>Your grade with the selected assignment would be <text id="new-hypo-grade"></text> with a final percent of <text id="new-hypo-fp"></text>.</h4>` ) ;
238+
239+ $hypo_assignment . insertAfter ( 'div.box-round' ) ;
240+
241+ showHypoGrade ( ) ;
242+ function showHypoGrade ( ) {
243+ let new_fp = hypo_assignment_info . weight * 0.01 * grade_fp ( hypo_assignment_info . grade ) + ( ( 100 - ( hypo_assignment_info . weight ) ) * 0.01 * parseFloat ( number ) ) ;
244+ console . log ( new_fp ) ;
245+ console . log ( getKeyRange ( fprange , new_fp ) )
246+ document . querySelector ( 'div.saspes-section text#new-hypo-grade' ) . innerText = getKeyRange ( fprange , new_fp ) ;
247+ document . querySelector ( 'div.saspes-section text#new-hypo-fp' ) . innerText = new_fp . toFixed ( 2 ) ;
248+ }
249+
250+
201251}
202252function login_page ( ) {
203253 /*
@@ -222,6 +272,16 @@ function login_page() {
222272 let insert_location = document.querySelector('#content');
223273 insert_location.parentNode.insertBefore(document.createElement('a'), insert_location);
224274 */
275+ $ ( '<div id="saspes-info"></div>' ) . insertAfter ( 'div#content' ) ;
276+ $ ( '#saspes-info' ) . html ( `<h3> <img src="${ browser . runtime . getURL ( 'icons/128.png' ) } " class="saspes-logo">SAS Powerschool Enhancement Suite</h3> <div class="saspes-content"><p style="font-size: 1.5em;">Version: ${ browser . runtime . getManifest ( ) . version } </p><p><a class="saspes-link" href="https://gschool.ydgkim.com/saspowerschool/" target="_blank" >Project Website<a> | <a href="https://github.com/gary-kim/saspes/blob/master/CHANGELOG.md" class="saspes-link" target="_blank" >Changelog</a> | <a class="saspes-link" href="https://github.com/gary-kim/saspes" target="_blank" >Source Code</a> | <a id="login-extension-settings" href="#" >Extension Options</a></div></p>` ) ;
277+ $ ( '#login-extension-settings' ) . on ( 'click' , ( ) => {
278+ browser . runtime . sendMessage ( { action : "open_settings" } ) ;
279+ } ) ;
280+ $ ( '.saspes-link' ) . on ( 'click' , ( e ) => {
281+ let href = e . currentTarget . href ;
282+ browser . runtime . sendMessage ( { action : "analytics_send" , args : { url : href , extra : { link : href } } } ) ;
283+ } ) ;
284+
225285}
226286function fill_percent ( $fill_location , url_link , percents , pos_in_arr ) {
227287 if ( ! percent_main_page ) {
@@ -318,6 +378,40 @@ function grade_gpa(grade) {
318378 break ;
319379 }
320380}
381+ function grade_fp ( grade ) {
382+ switch ( grade ) {
383+ case "A+" :
384+ return 90 ;
385+ break ;
386+ case "A" :
387+ return 80 ;
388+ break ;
389+ case "B+" :
390+ return 70 ;
391+ break ;
392+ case "B" :
393+ return 60 ;
394+ break ;
395+ case "C+" :
396+ return 50 ;
397+ break ;
398+ case "C" :
399+ return 40 ;
400+ break ;
401+ case "D+" :
402+ return 30 ;
403+ break ;
404+ case "D" :
405+ return 20 ;
406+ break ;
407+ case "F" :
408+ return 10 ;
409+ break ;
410+ default :
411+ return - 1 ;
412+ break ;
413+ }
414+ }
321415function html2node ( html_string ) {
322416 return html2nodelist ( html_string ) [ 0 ] ;
323417}
0 commit comments