-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
120 lines (81 loc) · 2.85 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
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
119
120
/************************************************************************************
This is your background code.
For more information please visit our wiki site:
http://docs.crossrider.com/#!/guide/scopes_background
*************************************************************************************/
function error(errorText, cards, card) {
if (cards && card) {
cards.error(card, errorText);
} else {
alert(errorText);
}
}
function notifychangedvalues(card, changedvalues) {
try {
appAPI.message.toActiveTab({
type: 'notifychangedvalues',
notification: {
'card': card,
'changedvalues': changedvalues
}
});
} catch(e) { error("notifychangedvalues: " + e); }
}
function notifychangedmessages(card, changedmessages) {
try {
appAPI.message.toActiveTab({
type: 'notifychangedmessages',
notification: {
'card': card,
'changedmessages': changedmessages
}
});
} catch(e) { error("notifychangedmessages: " + e); }
}
function refreshvalues(cards, card) {
try {
cards.refreshvalues(
card,
function(card, changedvalues) {
if (Object.keys(changedvalues).length > 0 && !card['you']) notifychangedvalues(card, changedvalues);
}, function(errorText) {
error(errorText, cards, card);
});
} catch(e) { error("refreshvalues: " + e, cards, card); }
}
function refreshmessages(messages, cards, card) {
try {
messages.refreshmessages(
card,
function(messages, changedmessages) {
if (Object.keys(changedmessages).length > 0) notifychangedmessages(card, changedmessages);
}, function(errorText) {
error(errorText, cards, card);
});
} catch(e) { error("refreshmessages: " + e, cards, card); }
}
appAPI.ready(function() {
var xdipost = eval(appAPI.resources.get('xdipost.js'));
var xdi = eval(appAPI.resources.get('xdi.js'));
var cards = eval(appAPI.resources.get('cards.js'));
var messages = eval(appAPI.resources.get('messages.js'));
appAPI.browserAction.setResourceIcon('app20.png');
appAPI.browserAction.setBadgeText('5', [0,0,0,128]);
appAPI.browserAction.setTitle('');
appAPI.webRequest.onBeforeNavigate.addListener(function(details, data) {
if (details.pageUrl.indexOf('=') === 0 || details.pageUrl.indexOf('+') === 0)
return { redirectTo: "https://cloud-cards.xdi2.org/" + encodeURIComponent(details.pageUrl) };
}, null);
appAPI.browserAction.setPopup({
resourcePath:'popup.html',
width: 600,
height: 400
});
appAPI.setInterval(function() {
var youcardlist = cards.listYOU();
var flwcardlist = cards.listFLW();
for (var address in youcardlist) refreshvalues(cards, youcardlist[address]);
for (var address in flwcardlist) refreshvalues(cards, flwcardlist[address]);
for (var address in youcardlist) refreshmessages(messages, cards, youcardlist[address]);
}, 30000);
});