-
Notifications
You must be signed in to change notification settings - Fork 92
/
gpameter.user.js
145 lines (129 loc) · 7.16 KB
/
gpameter.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
134
135
136
137
138
139
140
141
142
143
144
145
// ==UserScript==
// @name GPA meter
// @namespace https://aims.iith.ac.in/
// @description A user script to show GPA on aims page
// @include https://aims.iith.ac.in/aims/courseReg/myCrsHistoryPage?*
// @version 1
// @grant none
// ==/UserScript==
var exclude_list = [
'Minor Core',
'Honors Core',
'Honours project',
'Honours coursework',
'FCC',
'Additional',
'Audit',
];
const BASIC_SC = 'Basic Sciences';
const BASIC_ES = 'Basic Engineering\nSkills';
const DEPTT_CORE = 'Departmental Core Theory';
const DEPTT_ELEC = 'Departmental Elective';
const FREE_ELEC = 'Free Elective';
const TYPE_LA = 'Liberal Arts Elective';
const TYPE_CA = 'Creative Arts';
var grade_values = {
'A+': 10,
'A': 10,
'A-': 9,
'B': 8,
'B-': 7,
'C': 6,
'C-': 5,
'D': 4,
'FR': 0,
'FS': 0
};
console.log(studentId);
append_checkbox = function (parent, is_checked) {
parent.append("<input class=\"cgpa_cal_check\" type=\"checkbox\" " + (is_checked ? "checked" : "") + " />");
}
add_checkboxes = function () {
var courses_checked = new Set();
$(".cgpa_cal_check").remove();
elems = $(".hierarchyLi.dataLi").not(".hierarchyHdr, .hierarchySubHdr");
elems.each(function (i) {
var course_id = $(this).children(".col1").html().trim();
if (courses_checked.has(course_id)) {
append_checkbox($(this).children(".col1"), false);
return;
}
is_checked = true;
type = $(this).children(".col5").html().trim().slice(6);
grade = $(this).children(".col8").html().trim().slice(6);
console.log(grade, grade.length);
if (exclude_list.indexOf(type) > -1 || grade == "" || grade == "I")
is_checked = false;
if (is_checked)
courses_checked.add(course_id);
append_checkbox($(this).children(".col1"), is_checked);
});
}
show_total_gpa = function () {
$('#gpa_button').val('Calculating');
$('#gpa_bar').remove();
cg_total_grades = 0;
cg_total_credits = 0;
total_credits = 0;
basic_sc = 0;
basic_es = 0;
felec = 0;
dep_el = 0;
dep_core = 0;
laca = 0;
if ($(".cgpa_cal_check").length == 0)
add_checkboxes();
elems = $(".hierarchyLi.dataLi").not(".hierarchyHdr, .hierarchySubHdr");
elems.each(function (i) {
if ($(this).find(".cgpa_cal_check:checked").length == 0)
return;
grade = $(this).children(".col8").html().trim().slice(6);
credits = $(this).children(".col3").html().trim().slice(6);
type = $(this).children(".col5").html().trim().slice(6);
credits = Number(credits);
if (type == BASIC_SC) basic_sc += credits;
else if (type == BASIC_ES) basic_es += credits;
else if (type == DEPTT_ELEC) dep_el += credits;
else if (type == DEPTT_CORE) dep_core += credits;
else if (type == FREE_ELEC) felec += credits;
else if (type == TYPE_LA || type == TYPE_CA) laca += credits;
total_credits += credits;
if (!(grade in grade_values))
return;
grade = grade_values[grade];
cg_total_grades += credits * grade;
cg_total_credits += credits;
});
console.log(cg_total_grades, cg_total_credits);
console.log('Basic-sc: ');
console.log(basic_sc);
console.log('Basic-Engineering-Skills: ');
console.log(basic_es);
console.log('Deptt Elective: ');
console.log(dep_el);
console.log('Dept Core theory: ');
console.log(dep_core);
console.log('Free Elec: ');
console.log(felec);
console.log('LA CA: ');
console.log(laca);
var gpa = (cg_total_grades / cg_total_credits).toFixed(2);
$('#gpa_button').val('Show Gpa');
$('#courseHistoryUI .clear').after('<ul id="gpa_bar" class="subCnt"><li class="hierarchyLi dataLi hierarchyHdr changeHdrCls"><span class="col"> TOTAL GPA </span></li> \
<li class="hierarchyLi dataLi"><span class="col1 col"> </span><span class="col2 col"> Total GPA of graded courses </span><span class="col3 col"> </span><span class="col4 col"> </span><span class="col5 col"> </span><span class="col6 col"> </span><span class="col7 col"> </span><span class="col4 col">' + gpa + '</span></li> \
<li class="hierarchyLi dataLi"><span class="col1 col"> </span><span class="col2 col"> Deptt Core Theory </span><span class="col3 col"> </span><span class="col4 col"> </span><span class="col5 col"> </span><span class="col6 col"> </span><span class="col7 col"> </span><span class="col4 col">' + dep_core + '</span></li> \
<li class="hierarchyLi dataLi"><span class="col1 col"> </span><span class="col2 col"> Deptt Elective </span><span class="col3 col"> </span><span class="col4 col"> </span><span class="col5 col"> </span><span class="col6 col"> </span><span class="col7 col"> </span><span class="col4 col">' + dep_el + '</span></li> \
<li class="hierarchyLi dataLi"><span class="col1 col"> </span><span class="col2 col"> Free Elective </span><span class="col3 col"> </span><span class="col4 col"> </span><span class="col5 col"> </span><span class="col6 col"> </span><span class="col7 col"> </span><span class="col4 col">' + felec + '</span></li> \
<li class="hierarchyLi dataLi"><span class="col1 col"> </span><span class="col2 col"> LA/CA </span><span class="col3 col"> </span><span class="col4 col"> </span><span class="col5 col"> </span><span class="col6 col"> </span><span class="col7 col"> </span><span class="col4 col">' + laca + '</span></li> \
<li class="hierarchyLi dataLi"><span class="col1 col"> </span><span class="col2 col"> Basic Sciences </span><span class="col3 col"> </span><span class="col4 col"> </span><span class="col5 col"> </span><span class="col6 col"> </span><span class="col7 col"> </span><span class="col4 col">' + basic_sc + '</span></li> \
<li class="hierarchyLi dataLi"><span class="col1 col"> </span><span class="col2 col"> Basic Engineering Skills </span><span class="col3 col"> </span><span class="col4 col"> </span><span class="col5 col"> </span><span class="col6 col"> </span><span class="col7 col"> </span><span class="col4 col">' + basic_es + '</span></li> \
<li class="hierarchyLi dataLi"><span class="col1 col"> </span><span class="col2 col"> Total credits </span><span class="col3 col"> </span><span class="col4 col"> </span><span class="col5 col"> </span><span class="col6 col"> </span><span class="col7 col"> </span><span class="col4 col">' + total_credits + '</span></li> \
</ul>');
}
if (!(typeof unsafeWindow === 'undefined')) {
unsafeWindow.show_total_gpa = show_total_gpa;
unsafeWindow.exclude_list = exclude_list;
unsafeWindow.add_checkbox = add_checkbox;
unsafeWindow.grade_values = grade_values;
}
$('#studentCourseSearch').before('<input id="gpa_button" class="btn" value="Show Gpa" style="width:75px; margin-right:10px; opacity:1;" type="button" onclick="show_total_gpa();"></input>');