forked from normano/ycChrome
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.html
More file actions
118 lines (106 loc) · 2.47 KB
/
background.html
File metadata and controls
118 lines (106 loc) · 2.47 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
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
<html>
<head>
<script>
// First run? Set these
if(localStorage.getItem('hnNROnline') === null)
{
localStorage.setItem('hnNROnline', 'yes');
}
if(localStorage.getItem('classObjs') === null){
var defaultObj = {
'notInterested': { wordCounts: {}, hashes: [], titleList: [] },
'interested': { wordCounts:{}, hashes: [], titleList: [] }
};
localStorage.setItem('classObjs', JSON.stringify(defaultObj));
}
// Page basis
var online = localStorage.getItem('hnNROnline');
var newsUrl = new RegExp("news.ycombinator.com", "i");
function setPageAction(tab)
{
var iconImg = "icon.png";
if(online === "yes")
{
iconImg = "iconOff.png";
title = "Offline"
online = "no";
}
else
{
online = "yes";
title = "Our recommender is online!"
}
chrome.pageAction.setIcon({tabId: tab.id, path: iconImg});
chrome.pageAction.setTitle({tabId: tab.id, title: title});
localStorage.setItem('hnNROnline', online);
}
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab){
if(tab.url.match(newsUrl))
{
if(changeInfo.status === "complete")
{
chrome.pageAction.show(tabId);
}
else
{
chrome.pageAction.hide(tabId);
}
setPageAction(tab);
}
});
chrome.pageAction.onClicked.addListener(function(tab) {
setPageAction(tab);
});
chrome.extension.onRequest.addListener(function(messageData, sender, sendResponse){
var response = {}
switch(messageData.request)
{
case "available":
if(!messageData.value)
{
response.status = online;
}
else
{
online = messageData.value
localStorage.setItem('hnNROnline', online);
}
break;
case "localStorage":
if(messageData.op === "get")
{
response[messageData.key] = localStorage.getItem(messageData.key);
}
else if(messageData.op === "set")
{
localStorage.setItem(messageData.key, messageData.value);
}
else if(messageData.op === "remove")
{
localStorage.removeItem(messageData.key);
}
break;
default:
response.statusMessage = "I don't know how to respond";
}
sendResponse(response);
});
/*
// Create a simple text notification:
var notification = webkitNotifications.createNotification(
'48.png', // icon url - can be relative
'Hello!', // notification title
'Lorem ipsum...' // notification body text
);
// Or create an HTML notification:
var notification = webkitNotifications.createHTMLNotification(
'notification.html' // html url - can be relative
);
// Then show the notification.
notification.show();
*/
</script>
</head>
<body>
</body>
</html>