forked from davidplumpton/brown
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.html
More file actions
56 lines (50 loc) · 1.3 KB
/
background.html
File metadata and controls
56 lines (50 loc) · 1.3 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
<html>
<script>
var storage = 'brown.data';
function compareSite(s1, s2) {
if (s1.nextTime < s2.nextTime) return -1;
if (s1.nextTime > s2.nextTime) return 1;
return 0;
}
function getDelay(site) {
var frequency = site.frequency;
var amount = parseInt(frequency.substring(0, frequency.length - 1));
var period = frequency.substring(frequency.length - 1);
if (period == 'd') {
return amount * 24 * 60 * 60 * 1000;
}
if (period == 'h') {
return amount * 60 * 60 * 1000;
}
if (period == 'w') {
return amount * 7 * 24 * 60 * 60 * 1000;
}
alert('Bad frequency value: ' + frequency);
}
function nextPage() {
var data = localStorage[storage];
var sites = JSON.parse(data);
sites.sort(compareSite);
var site = sites[0];
var now = new Date().getTime();
if (site.nextTime > now) {
alert('Not yet scheduled: ' + site.url);
}
var url = site.url;
if (url.indexOf('http') == -1)
{
url = 'http://' + url;
}
site.nextTime = now + getDelay(site);
sites.sort(compareSite);
chrome.tabs.create({url: url, selected: false});
localStorage[storage] = JSON.stringify(sites);
}
chrome.extension.onConnect.addListener(function(port) {
nextPage();
});
</script>
<body>
background
</body>
</html>