-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
55 lines (45 loc) · 1.43 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
// does not run on page, but runs in an isolated environment. Not able to access DOM or any of its properties
$(function(){
main();
// 1 sec = 1000
//refresh every 30 min
// 1800000 == 30 min
setInterval(main, 1800000);
});
var options = {
type: "basic",
title: "New Update",
message: "The site has been updated. Please take a look.",
iconUrl: "icon.png"
};
function redirectWindow(){
window.open("https://prantar.me/");
}
function main(){
$.get('https://prantar.me/', function(data){
var htmlData = data;
var currDate;
var prevDate;
// get currDate
$data = $('body').append($(htmlData).find('#lastModified').eq(0));
currDate = $('body').find('#lastModified').text();
// get prevDate
chrome.storage.local.get('data', function (result) {
prevDate = (result.data);
console.log("Cur val: " + currDate);
console.log("Prev val: " + prevDate);
// if they are not same set prevDate = currDate
if (currDate != prevDate){
prevDate = currDate;
chrome.storage.local.set({'data': prevDate}, function (result) {});
console.log("NEW Cur val: " + currDate);
console.log("NEW Prev val: " + prevDate);
// if new version available inform user with badge notification
chrome.browserAction.setBadgeText ( { text: "1" } );
// create rich notifications
chrome.notifications.create(options);
chrome.notifications.onClicked.addListener(redirectWindow);
}
});
});
};