-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.html
More file actions
86 lines (67 loc) · 2.38 KB
/
background.html
File metadata and controls
86 lines (67 loc) · 2.38 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
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
<html>
<head>
<script src='scripts/jquery-1.6.1.min.js'></script>
<script src="scripts/parse.js"></script>
<script>
function showNotificationAndSetCookie(domain, name){
//show notification
var notification = webkitNotifications.createHTMLNotification(
'notification.html'
);
notification.show();
//then set today cookie to prevent other shows in today
var today = String(new Date().getDate());//get todays date
chrome.cookies.set({ url: domain, name: name, value: (today), expirationDate: (new Date().getTime()/1000) + (24*3600) });//set today date in a cookie with a 24 hours life time
}
function getCookies(domain, name, callback) {
//get out cookie from chrome
chrome.cookies.get({"url": domain, "name": name}, function(cookie) {
if(cookie == null){//if cookie is not set we set it manualy
showNotificationAndSetCookie(domain,name);
}
chrome.cookies.get({"url": domain, "name": name}, function(cookie) {//get the date from cookie that set before
if(callback) {
callback(cookie.value)
}
});
});
}
/**
*this function check if today date is set in cookie (means that we show this extension massage once today)
*prevent to show the massage agian
*else if this is the frist time that user see this message
*show the massage and set the cookie to prevent from next shows in this day
*/
getCookies("http://g5line.com/", "todayDate", function(date) {
if((String(new Date().getDate())) != date)
showNotificationAndSetCookie("http://g5line.com/","todayDate");
});
function fetch_feed(url, callback) {
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(data) {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var data = xhr.responseText;
callback(data);
} else {
callback(null);
}
}
}
// Note that any URL fetched here must be matched by a permission in
// the manifest.json file!
xhr.open('GET', url, true);
xhr.send();
}
function onRequest(request, sender, callback) {
if (request.action == 'fetch_feed') {
fetch_feed(request.url, callback);
}
}
// Wire up the listener.
chrome.extension.onRequest.addListener(onRequest);
</script>
</head>
<body>
</body>
</html>