-
Notifications
You must be signed in to change notification settings - Fork 0
/
Grade-Check.user.js
133 lines (119 loc) · 4.52 KB
/
Grade-Check.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
// ==UserScript==
// @name grade-check
// @namespace nak
// @description checks for new grades
// @include https://cis.nordakademie.de/studium/pruefungen/pruefungsergebnisse/
// @include https://cis.nordakademie.de/mein-profil/mein-postfach/leistungsuebersicht/
// @version 0.4.15
// @grant none
// @downloadURL https://github.com/nerdakademie/Grade-Check/raw/master/Grade-Check.user.js
// @updateURL https://github.com/nerdakademie/Grade-Check/raw/master/Grade-Check.meta.js
// ==/UserScript==
function reloadPage(){
location.reload();
}
function isNumeric(num){
return !isNaN(num);
}
function average(arr){
if(arr.length > 1){
var gradesum=0,credsum=0;
//minus 1 for the calculated serverside sum
for(var k=1; k<arr.length; k++){
var grade = arr[k][1];
var credpoint = arr[k][2];
if(arr[k][0] == "Bachelorthesis"){
credpoint *= 3;
}
if(isNumeric(grade.replace(',','.')) && parseFloat(grade.replace(',','.')) > 0 && grade.indexOf("Versuch") == -1){
gradesum = gradesum + (parseFloat(grade.replace(',','.')) * parseFloat(credpoint));
credsum = credsum + parseFloat(credpoint);
}
}
if(gradesum !==0 && credsum !==0){
return (Math.round(gradesum/credsum*1000)/1000);
}
}
return "";
}
var oldTableContent = localStorage.getItem("oldTable");
var oldTableArray = JSON.parse(localStorage.getItem("oldTableArray"));
var compareTable = document.getElementsByClassName("table");
var compareTableContent = compareTable[0].textContent;
var rowCount = compareTable[0].rows.length;
function comparing() {
if (compareTableContent != oldTableContent) {
var subjects = "",array = new Array();
if(oldTableArray === null){
oldTableArray = new Array();
}
for (var i = 1, row; row = compareTable[0].rows[i]; i++) {
if(i < compareTable[0].rows.length-1){ //Ignore last row
if(oldTableArray.length > i ){
if(oldTableArray[i][1] !== row.cells[4].textContent.trim() && row.cells[4].textContent.trim().length > 0){
//Grade has changed
array.push([row.cells[1].textContent.trim() , row.cells[4].textContent.trim() , row.cells[5].textContent.trim()]);
}
}
oldTableArray[i] = [row.cells[1].textContent.trim() , row.cells[4].textContent.trim() , row.cells[5].textContent.trim()];
}
}
for(var j = 0, len = array.length; j < len; j++){
subjects = subjects + array[j][0];
if(j != len -1){
subjects = subjects + ", ";
}
}
if(array.length > 1){
alert('Es gibt neue Noten in den Fächern: ' +subjects);
}else if (array.length === 1){
alert('Es gibt eine neue Note in dem Fach ' + subjects);
}
var oldTable = document.getElementsByClassName("table");
oldTableContent = oldTable[0].textContent;
localStorage.setItem("oldTable", oldTableContent);
localStorage.setItem("oldTableArray", JSON.stringify(oldTableArray));
}
compareTable[0].rows[rowCount-1].cells[4].textContent = average(oldTableArray);
setTimeout(reloadPage,60000);
}
comparing();
function getGradeColor(aNum) {
var gradeNum = parseFloat(aNum.replace(',','.'));
var neg = (gradeNum >= 3);
gradeNum = Math.abs(gradeNum-3);
gradeNum = gradeNum / 2;
gradeNum = gradeNum * 255;
var gradeInt = Math.floor(gradeNum);
if(neg){
var green = (255-gradeInt).toString(16);
if((255-gradeInt)<16){
return '#FF0'+green+'60';
}else{
return '#FF'+green+'60';
}
}else {
var red = (255-gradeInt).toString(16);
if((255-gradeInt)<16){
return '#0'+red+'FF60';
}else{
return '#'+red+'FF60';
}
}
}
function getElementByXpath(path) {
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
}
for(var i = 1; i <= rowCount-1; i++){
var elem = getElementByXpath('//*[@id="curricular"]/table/tbody/tr[' + i + ']/td[5]');
if (elem !== null){
if(elem.innerText.trim().substring(0,3) !== ""){
elem.setAttribute('bgcolor', getGradeColor(elem.innerText.trim().substring(0,3)));
elem.style.backgroundColor = getGradeColor(elem.innerText.trim().substring(0,3));
}
}
}
//Average coloration
var elem = getElementByXpath('//*[@id="curricular"]/table/tbody/tr['+ (rowCount-1) +']/th[5]');
elem.setAttribute('bgcolor', getGradeColor(elem.innerText.replace('.',',')));
elem.style.backgroundColor = getGradeColor(elem.innerText.replace('.',','));