-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
58 lines (48 loc) · 1.62 KB
/
background.js
File metadata and controls
58 lines (48 loc) · 1.62 KB
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
var settings = {};
function start_watch(log_type) {
var d = new Date(), year = d.getFullYear(), month = ('0' + (d.getMonth()+1)).slice(-2),date = d.getDate();
$.ajax({
type: "GET",
url: "https://" + settings.server + logs_path + log_type + "-blade" + settings['blade-1'] + "-" + settings['blade-2'] + "-appserver-" + year + month + date + ".log",
beforeSend: function (xhr){
xhr.setRequestHeader('Authorization', make_base_auth(settings.username, settings.password));
},
error : function() {
console.log('File does not exists.');
},
success: function (response){
console.log('File exists.');
var regex = new RegExp(/\[\d+\-\d+\-\d+ \d+:\d+:\d+\.\d+ GMT]/);
var errors = response.split(regex);
var date = new Date();
var notifId = "" + date.getFullYear() + '_' + date.getMonth() + '_' + date.getDate() + '_' + errors.length;
chrome.notifications.create(notifId, {
title : "New log change: " + log_type,
message : errors.pop(),
type : "basic",
iconUrl : "icon.png"
}, function() {
});
}
});
}
function do_notifications() {
for(var i = 0, n = logs_available.length; i < n; i+=1) {
if(settings['log-' + logs_available[i]]) {
start_watch(logs_available[i]);
}
}
}
chrome.storage.local.get(settings_list, function(_settings) {
settings = $.extend(settings, _settings);
do_notifications();
});
chrome.alarms.create('realtime', {
periodInMinutes : 1,
delayInMinutes : 1
});
chrome.alarms.onAlarm.addListener(function(alarm) {
if(alarm.name == 'realtime') {
do_notifications();
}
});