-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
152 lines (127 loc) · 4.19 KB
/
popup.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
var notes;
var updateTimout;
$(document).ready(function() {
$("#divVersion").html(getVersion());
$("#btnLogin").click(prepareLogin);
$("#btnLogout").click(logout);
$("#btnOptionen").click(openOptionsTab);
$('#user').val(localStorage["user"]);
$('#pass').val(localStorage["pass"]);
if(toBool(localStorage["loggedIn"])) {
$('#divLogin').hide();
$('#divLogout').show();
updateView();
} else {
$('#divLogin').show();
$('#divLogout').hide();
$('#resp').hide();
$('#divContainer').hide();
}
chrome.browserAction.setBadgeText({"text":""})
updateTimout = setInterval(updateView, 5000);
var now = new Date();
var diff = now.getTime() - localStorage['lastCheckDate'];
if(diff > 180000) {
$('#divLoading').show();
}
if(localStorage["mail"] === undefined && toBool(localStorage["loggedIn"])) {
localStorage["allowedSubmission"] = true;
localStorage["mail"] = "";
// openOptionsTab();
}
$('a').click(function(){
chrome.tabs.create({url: $(this).attr('href')});
return false;
});
});
chrome.extension.onMessage.addListener(function(request, sender, sendResponse) {
// console.log(request.method );
if (request.method == "loginSucessful") {
$('#divLogin').hide();
$('#divLogout').show();
} else if (request.method == "loginFailed") {
$('#divInfo').html("Logging failed!").fadeIn('slow');
} else if (request.method == "loading") {
console.log("show spinner");
$('#divLoading').show();
} else if (request.method == "newnotes") {
newNotes();
} else if (request.method == "newbanote") {
newBANote();
}else {
updateView();
}});
function getVersion() {
var details = chrome.app.getDetails();
return details.version;
}
function updateView() {
if(!toBool(localStorage["loggedIn"])) return;
$('#divContainer').show();
$('#resp').show().html($('table' , localStorage["notes"]));
$("#resp [class*='header_top']").remove();
$('#resp tr td:nth-child(2)').hide();
$("#resp td[colspan*=3]").filter("[class!='termin_bez']").filter("[class!='semester_bez']").remove();
if($('#resp td').length > 0) {
var stars = $('#resp td').find('center:contains("*")').length;
if(stars < localStorage['stars']) {
newNotes();
localStorage['stars'] = stars;
} else {
localStorage['stars'] = stars;
}
}
$('#divInfo').html("Ausstehende Noten : <b>" + stars + "</b><br/>Letztes Update : " + localStorage["lastCheck"]);
$('#resp .button').replaceWith('<b>Neue Note!</b>');
setTimeout(function(){ $('#divLoading').hide(); }, 2000);
$('#studselink').attr('href', 'https://www.studse.rfh-koeln.de/vpruef/pruefungsergebnisse.php?PHPSESSID=' + localStorage["session"] + '&nav=1');
}
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 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 pushToIphone() {
$.ajax({
type: 'GET',
url: 'http://bitsunleashed.de/rfhgrades/simpleapi/com.php?action=push&matrikelnummer=' + localStorage["user"],
success: function(data) {}
})
}
function prepareLogin() {
console.log("trying to login");
$('#divInfo').html("Logging in ...").fadeIn('slow');
localStorage["user"] = $('#user').val()
localStorage["pass"] = $('#pass').val()
localStorage["credentials"] = $("#fLogin").serialize();
localStorage['stars'] = 0;
chrome.extension.sendMessage({method: "login"});
}
function logout() {
clearTimeout(updateTimout);
localStorage["user"] = "";
localStorage["pass"] = "";
localStorage["notes"] = "";
localStorage["session"] = "";
localStorage["loggedIn"] = false;
$('#divContainer').hide();
$('#divLogin').show();
$('#divLogout').hide();
$('#divInfo').html("");
$('#resp').html("");
$('#resp').hide();
}