OnCampusTweaks

Change the way any myschoolappp based student website behaves.

当前为 2021-03-04 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name OnCampusTweaks
  3. // @namespace https://*.myschoolapp.com
  4. // @version 0.9.5
  5. // @description Change the way any myschoolappp based student website behaves.
  6. // @author Zack Sargent & N3
  7. // @match https://*.myschoolapp.com/app/*
  8. // @grant none
  9. // ==/UserScript==
  10. // THIS CODE IS RELEASED UNDER THE MIT LICENSE
  11. // Find it on github: https://github.com/zsarge/OnCampusTweaks
  12.  
  13. /* START SETTINGS */
  14.  
  15. // This controls whether grades should be shown
  16. // automatically when the progress page is opened.
  17. // Can be true or false.
  18. const shouldAlwaysShowGrades = true;
  19.  
  20. // This controls whether the assignment center should
  21. // change to week view when it loads.
  22. // Can be true or false.
  23. const shouldChangeToWeekView = true;
  24.  
  25. /* END SETTINGS */
  26.  
  27. // Set task index based on hostname.
  28. const index = window.location.hostname === "elderhs.myschoolapp.com" ? 3 : 4;
  29.  
  30. // Runs when page is fully loaded
  31. // The website is set up in a way that window.onload triggers before the page is fully loaded.
  32. // Thus, we must check independently to see if the full page has loaded.
  33. var checkExist = setInterval(function () {
  34. // if the string "assignment-center" is in the url
  35. if (window.location.href.indexOf("assignment-center") > -1) {
  36. if (
  37. document.readyState === "ready" ||
  38. document.readyState === "complete"
  39. ) {
  40. if (shouldChangeToWeekView) {
  41. changeToWeekView();
  42. }
  43. hideCompletedTasks();
  44. clearInterval(checkExist);
  45. // Run only one time. not needed to run again as the website saves your preferences for that session
  46. }
  47. }
  48. }, 100); //100 ms
  49.  
  50. function changeToWeekView() {
  51. // if the string "assignment-center" is in the url
  52. if (window.location.href.indexOf("assignment-center") > -1) {
  53. document.getElementById("week-view").click();
  54. console.log("OnCampusTweaks: Changed to week view");
  55. }
  56. }
  57.  
  58. // Hides completed tasks automatically in the assignment center.
  59. // Unfortunately, upon marking a assignment as completed, it will not
  60. // disappear. However I am not going to mess with this as its most likely
  61. // by design of the website and some people could prefer to still see it.
  62. function hideCompletedTasks() {
  63. if (window.location.href.indexOf("assignment-center") > -1) {
  64. document.getElementById("filter-status").click();
  65.  
  66. // Create a list of all of the button elements that appear when you filter by status
  67. var buttonElements = document.getElementsByClassName(
  68. "pull-left btn btn-xs btn-approve status-button active"
  69. );
  70. buttonElements[index].click(); // Hides Completed tasks
  71.  
  72. // We have to get the buttons again because clicking on them changes the class structure
  73. buttonElements = document.getElementsByClassName(
  74. "pull-left btn btn-xs btn-approve status-button active"
  75. );
  76. buttonElements[index].click(); // Hides Graded tasks
  77.  
  78. document.getElementById("btn-filter-apply").click();
  79.  
  80. submitToVerify();
  81.  
  82. console.log("OnCampusTweaks: Hid completed tasks");
  83. }
  84. }
  85.  
  86. function alwaysShowGrades() {
  87. if (window.location.href.indexOf("progress") > -1) {
  88. document.getElementById("showGrade").click();
  89. console.log("OnCampusTweaks: Grades Shown");
  90. }
  91. }
  92.  
  93. // Sometimes the built in function does not work very well, so we have to try again.
  94. function submitToVerify() {
  95. document.getElementById("filter-status").click();
  96. document.getElementById("btn-filter-apply").click();
  97. }
  98.  
  99. // -------------------
  100. // GPA Calculator
  101. // -------------------
  102.  
  103. var checkGrades = setInterval(function () {
  104. // if the string "progress" is in the url
  105. if (window.location.href.indexOf("progress") > -1) {
  106. if (
  107. document.readyState === "ready" ||
  108. document.readyState === "complete"
  109. ) {
  110. let courseDiv = document.getElementById("courses");
  111. let gradesArray = courseDiv.innerText.match(
  112. /([0-9][0-9][0-9]|[0-9][0-9])\%/gi
  113. );
  114. showGradeAverage(gradesArray);
  115.  
  116. if (shouldAlwaysShowGrades) {
  117. alwaysShowGrades();
  118. }
  119. }
  120. }
  121. }, 500); // check every 500ms
  122.  
  123. function showGradeAverage(gradesArray) {
  124. if (gradesArray) {
  125. runOnce(() => {
  126. let gpaDiv = getGPADiv();
  127. let gpa = getGPA(gradesArray);
  128. gpaDiv.textContent += `Grade Average: ${gpa}%\n | `;
  129.  
  130. for (var i = 0; i < gradesArray.length; i++) {
  131. gradesArray[i] = parseInt(gradesArray[i]);
  132. }
  133.  
  134. let min = Math.min(...gradesArray);
  135. gpaDiv.textContent += `Lowest grade: ${min}%\n | `;
  136.  
  137. let max = Math.max(...gradesArray);
  138. gpaDiv.textContent += `Highest grade: ${max}%\n`;
  139.  
  140. console.log(
  141. "OnCampusTweaks: Calculated and retrieved grade information"
  142. );
  143. });
  144. }
  145. }
  146.  
  147. var hasRun = false;
  148. function runOnce(func) {
  149. if (!hasRun) {
  150. func();
  151. hasRun = true;
  152. }
  153. }
  154.  
  155. function getGPA(gradesArray) {
  156. const average = (array) => array.reduce((a, b) => a + b) / array.length;
  157.  
  158. // turn array of strings into array of ints
  159. for (var i = 0; i < gradesArray.length; i++) {
  160. gradesArray[i] = gradesArray[i].replace("%", "");
  161. gradesArray[i] = parseInt(gradesArray[i]);
  162. }
  163.  
  164. let gpa = average(gradesArray);
  165. return Math.round(gpa * 100) / 100;
  166. // round to two decimal places
  167. }
  168.  
  169. function getGPADiv() {
  170. // Re-purposes unused Performance Div
  171. let div = document.createElement("div");
  172. div.id = "custom-grades";
  173. let performance = document.getElementById("performanceCollapse");
  174. performance.appendChild(div);
  175. return document.getElementById("custom-grades");
  176. }