上海海洋大学绩点查询

上海海洋大学URP本学期绩点查询

  1. // ==UserScript==
  2. // @name 上海海洋大学绩点查询
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.5
  5. // @icon https://s1.ax1x.com/2020/07/24/UX8ngg.png
  6. // @description 上海海洋大学URP本学期绩点查询
  7. // @author yuebanquan
  8. // @match http*://urp.shou.edu.cn/student/integratedQuery/scoreQuery/thisTermScores/index
  9. // @match http*://urp.shou.edu.cn/student/integratedQuery/scoreQuery/allTermScores/index
  10. // @grant none
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Your code here...
  18. /*
  19. * 定义所需要的数据&对象
  20. */
  21. var courseNum = 0; //课程数
  22. var allCredits = 0; //学分总和
  23. var allGPA = 0; //绩点总和
  24. var averageGPA = 0; //平均绩点
  25. var nowUrl = window.location.href; //获取页面URL
  26. var mytable; //相应的table
  27. var nowPgaeNum = 0;
  28. var pageNum = 0;
  29.  
  30. var MyDiv = document.getElementById("page-content-template");
  31. var bt = document.createElement("button"); //createElement生成button对象
  32. bt.innerHTML = '查看绩点';
  33. bt.onclick = function() { //绑定点击事件
  34. if (nowUrl.indexOf('allTermScores') != -1) {
  35. //确保能获取到所有数据
  36. //获取页数
  37. nowPgaeNum = document.getElementById("turnpageto_urppagebar").value
  38. pageNum = document.getElementById("totalPage_show_urppagebar").innerHTML
  39. //翻到最下页
  40. if (nowPgaeNum != pageNum) {
  41. // var ele = document.getElementById('pager_scroll');
  42. // ele.scrollTop = ele.scrollHeight
  43. alert("请翻到最下页再计算,否则计算错误!!!!");
  44. }
  45. }
  46.  
  47. CalculateGPA();
  48.  
  49. alert("平均绩点:" + averageGPA); //显示绩点
  50.  
  51. //数据清零
  52. courseNum = 0; //课程数
  53. allCredits = 0; //学分总和
  54. allGPA = 0; //绩点总和
  55. averageGPA = 0; //平均绩点
  56. nowUrl = window.location.href; //获取页面URL
  57. mytable; //相应的table
  58. nowPgaeNum = 0;
  59. pageNum = 0;
  60. }
  61.  
  62. MyDiv.appendChild(bt); //添加到页面
  63.  
  64.  
  65. function CalculateGPA() {
  66. /*
  67. * 每个页面计算方法不同,先判断在哪个页面
  68. */
  69. //判断所在页面,定义学分,成绩,未通过原因所在的列
  70. if (nowUrl.indexOf('thisTermScores') != -1) { //本学期成绩页面
  71. var reasonsForFailRow = 11; //未通过原因所在列
  72. var scoreTxtRow = 8; //成绩所在列
  73. var parseFloatRow = 3; //学分所在列
  74. var mytable = document.getElementById('scoretbody');
  75. courseNum = mytable.rows.length;  //获取课程数
  76. } else if (nowUrl.indexOf('allTermScores') != -1) { //历年成绩页面
  77. reasonsForFailRow = 10; //未通过原因所在列
  78. scoreTxtRow = 9; //成绩所在列
  79. parseFloatRow = 5; //学分所在列
  80. mytable = document.getElementById('scoreintbody');
  81. courseNum = mytable.rows.length;  //获取课程数
  82. }
  83.  
  84. for (var i = 0; i < courseNum; i++) {
  85. var _row = mytable.rows;  //获取table的行
  86. var _cell = _row[i].cells;  //获取第i行的列
  87. //缓考的情况
  88. var reasonsForFail = _cell[reasonsForFailRow].innerText;  //获取未通过原因
  89. if (reasonsForFail.indexOf("缓考") != -1) { //如果有缓考科目,不计入总绩点,跳出这一行
  90. continue;
  91. }
  92.  
  93. var scoreTxt = _cell[scoreTxtRow].innerText;  //获取成绩
  94. //还未出成绩,跳出这一行
  95. if (scoreTxt.length == 0) {
  96. continue;
  97. }
  98.  
  99. var xuefen = parseFloat(_cell[parseFloatRow].innerHTML);  //获取学分
  100.  
  101. allCredits = allCredits + xuefen;
  102. var score = parseFloat(scoreTxt);
  103.  
  104. //绩点换算
  105. if (scoreTxt == "优秀" || scoreTxt == "良好" || scoreTxt == "通过" || scoreTxt == "中等" || scoreTxt == "及格" || scoreTxt == "不及格" || scoreTxt == "不通过") { //如果score为NaN,说明scoreTxt读取到的是五分or两分计分制
  106. //五分or两分计分制换算成绩点
  107. if (scoreTxt == "优秀") {
  108. var gpa = 4.0;
  109. } else if (scoreTxt == "良好" || scoreTxt == "通过") {
  110. gpa = 3.3;
  111. } else if (scoreTxt == "中等") {
  112. gpa = 2.3;
  113. } else if (scoreTxt == "及格") {
  114. gpa = 1.0;
  115. } else if (scoreTxt == "不及格" || scoreTxt == "不通过") {
  116. gpa = 0;
  117. }
  118. } else {
  119. //百分制换算成绩点
  120. if (score >= 90) {
  121. gpa = 4.0;
  122. } else if (score >= 85) {
  123. gpa = 3.7;
  124. } else if (score >= 82) {
  125. gpa = 3.3;
  126. } else if (score >= 78) {
  127. gpa = 3.0;
  128. } else if (score >= 75) {
  129. gpa = 2.7;
  130. } else if (score >= 72) {
  131. gpa = 2.3;
  132. } else if (score >= 68) {
  133. gpa = 2.0;
  134. } else if (score >= 66) {
  135. gpa = 1.7;
  136. } else if (score >= 64) {
  137. gpa = 1.5;
  138. } else if (score >= 60) {
  139. gpa = 1.0;
  140. } else if (score < 60) {
  141. gpa = 0.0;
  142. }
  143. }
  144.  
  145. allGPA = allGPA + xuefen * gpa;
  146. }
  147. averageGPA = allGPA / allCredits;
  148. }
  149. })();