This repository has been archived by the owner on Dec 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
GesAverage.js
59 lines (56 loc) · 1.92 KB
/
GesAverage.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
// ==UserScript==
// @name GESAverage
// @namespace https://github.com/Nsbx/GesAverage
// @updateURL https://raw.githubusercontent.com/Nsbx/GesAverage/master/GesAverage.js
// @downloadURL https://raw.githubusercontent.com/Nsbx/GesAverage/master/GesAverage.js
// @version 0.3
// @description Add average in myges
// @author Nicolas Bondoux
// @match https://www.myges.fr/student/marks
// @grant none
// ==/UserScript==
$( document ).ready(function() {
calculateAverage();
$('#marksForm select').change(function(){
setTimeout(function () {
calculateAverage();
}, 2000);
})
});
function calculateAverage(){
gesTableBody = $('table[role="grid"]').find('tbody')[0];
gesTableData = $(gesTableBody).find('tr');
gesNotes = [];
nbrColumn = parseInt(gesTableData[0].childElementCount);
for(let i = 0; i < gesTableData.length; i++){
for(let j = 4; j < nbrColumn; j++)
{
if(gesTableData[i].cells[j].innerText != ""){
gesNotes.push({
coef: parseFloat(gesTableData[i].cells[2].innerText),
note: parseFloat(gesTableData[i].cells[j].innerText)
});
}
}
}
gesNotesSum = 0;
gesCoefSum = 0;
for(let i = 0; i < gesNotes.length; i++){
gesNotesSum += gesNotes[i].note * gesNotes[i].coef;
gesCoefSum += gesNotes[i].coef;
}
gesAverage = gesNotesSum / gesCoefSum;
$(gesTableBody)
.append(
$('<tr>').append(
$('<td colspan="4" style="font-weight: bold; font-size: 11px; color: #217BB1">').append(
$('<span>').text("Moyenne Générale")
),
$('<td colspan="'+ (nbrColumn - 4) +'" style="text-align: center; font-weight: bold">').append(
$('<span>').text(gesAverage.toFixed(2))
)
)
)
;
}
console.log("GESAverage.js loaded");