-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.js
161 lines (129 loc) · 4.08 KB
/
background.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
$(document).ready(function() {
var now = new Date();
var diff = now.getTime() - localStorage['lastCheckDate'];
if(diff > 180000) {
chrome.extension.sendMessage({method: "loading"});
pullNotes();
}
setInterval(pullNotes, 300000);
// setInterval(updateFilledNotes, 600000);
});
function login () {
console.log("logging in");
$.ajax({
type: 'POST',
dataType: 'html',
url: 'https://www.studse.rfh-koeln.de/?func=login_check',
data: localStorage["credentials"],
success: function(data) {
var sessionId = getURLParameter('PHPSESSID', $("a=*[title='Prüfungsrelevante Daten']", data).attr('href'));
if(sessionId.length > 5) {
localStorage["session"] = sessionId;
localStorage["loggedIn"] = true;
chrome.extension.sendMessage({method: "loginSucessful"});
localStorage['stars'] = 0;
pullNotes();
} else {
localStorage["loggedIn"] = false;
chrome.extension.sendMessage({method: "loginFailed"});
}
}
})
return false;
}
function getURLParameter(name, url) {
return decodeURI(
(RegExp(name + '=' + '(.+?)(&|$)').exec(url)||[,null])[1]
);
}
var data;
function pullNotes() {
if(!toBool(localStorage["loggedIn"])) return;
console.log("notes pulling");
chrome.extension.sendMessage({method: "loading"});
$.ajax({
type: 'GET',
dataType: 'html',
url: 'https://www.studse.rfh-koeln.de/vpruef/pruefungsergebnisse.php?PHPSESSID=' + localStorage["session"] +'&nav=1',
success: function(data) {
localStorage['notes'] = data;
var now = new Date.now().toString("dd.MM.yyyy HH:mm:ss");
if($("meta[http-equiv*='refresh']", localStorage['notes']).length > 0) {
console.log("requesting new session");
login();
} else {
console.log("notes pulled");
localStorage['lastCheck'] = now;
localStorage['lastCheckDate'] = new Date().getTime();
var stars = $('td', localStorage['notes'] ).find('center:contains("*")').length;
if(stars < localStorage['stars']) {
chrome.extension.sendMessage({method: "newnotes"});
localStorage['stars'] = stars;
} else {
localStorage['stars'] = stars;
}
// detectMissingNotes();
// pullBANote();
chrome.extension.sendMessage({method: "updateView"});
}
}
});
return data;
}
function pullBANote() {
if(!toBool(localStorage["loggedIn"])) return;
console.log("notes pulling");
chrome.extension.sendMessage({method: "loading"});
$.ajax({
type: 'GET',
dataType: 'html',
url: 'https://www.studse.rfh-koeln.de/vpruef/thesis_beurteilung.php?PHPSESSID=' + localStorage["session"] +'&nav=1',
success: function(data) {
localStorage['banote'] = data;
console.log("ba note pulled");
if($('td:contains("Gesamtnote")', localStorage['banote'] ).length > 0) {
var stars = $('td:contains("*")', localStorage['banote'] ).length;
if(stars < 1) {
newBANote();
chrome.extension.sendMessage({method: "newbanote"});
}
chrome.extension.sendMessage({method: "updateView"});
}
}
});
return data;
}
function newBANote() {
var notification = webkitNotifications.createNotification(
'', // icon url - can be relative
'Bachelorarbeit Note', // notification title
'Bachelorarbeit Note wurde eingetragen! - ' + $('td', localStorage['banote'] ).last().text() // notification body text
);
notification.show();
chrome.browserAction.setBadgeText({"text":"!!!"})
}
function newNotes() {
var notification = webkitNotifications.createNotification(
'', // icon url - can be relative
'Neue Note', // notification title
'Eine neue Note wurde eingetragen!' // notification body text
);
// compareMissingNotes();
notification.show();
chrome.browserAction.setBadgeText({"text":"!"})
}
function pushToIphone() {
$.ajax({
type: 'GET',
url: 'http://bitsunleashed.de/rfhgrades/simpleapi/com.php?action=push&matrikelnummer=' + localStorage["user"],
success: function(data) {}
})
}
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
if (request.method == "login") {
login();
} else if (request.method == "pullNotes") {
pullNotes();
}
});