-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground_task.js
52 lines (41 loc) · 1.02 KB
/
background_task.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
function refreshGames()
{
checkServerStatus(function(text) {
DGSState.currentGames = parseStatus(text);
DGSState.save()
if (DGSState.currentGames == 'Error') {
chrome.browserAction.setBadgeText({'text': '!'})
return
}
var count = 0
if (DGSState.currentGames) {
count = DGSState.currentGames.length
}
if (count > 0) {
chrome.browserAction.setBadgeText({'text': count.toString()});
} else {
chrome.browserAction.setBadgeText({'text': ''});
}
})
}
function startChecking()
{
var options = null
if (localStorage["background_task_id"] != null) {
clearInterval(localStorage["background_task_id"])
}
if (localStorage['dgs_options']) {
options = JSON.parse(localStorage['dgs_options'])
}
if (options == null) {
options = {}
}
var freq = options.frequency
if (freq == null) {
freq = 300000;
}
var intervalId = setInterval(refreshGames, freq);
localStorage["background_task_id"] = intervalId;
refreshGames()
}
startChecking()