-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
52 lines (41 loc) · 1.34 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
let originalBadgeColor = '';
function updateBadge(price) {
chrome.action.setBadgeText({ text: price.toString() });
if (originalBadgeColor === '') {
chrome.action.getBadgeBackgroundColor({}, result => {
originalBadgeColor = result;
});
}
chrome.action.setBadgeBackgroundColor({ color: [255, 215, 0, 255] });
setTimeout(() => {
chrome.action.setBadgeBackgroundColor({ color: originalBadgeColor });
}, 1000); // (1 second)
}
function fetchxahauPrice() {
fetch('https://api.coingecko.com/api/v3/simple/price?ids=xahau&vs_currencies=usd')
.then(response => response.json())
.then(data => {
const xahauPrice = parseFloat(data.xahau.usd);
const formattedPrice = `${xahauPrice.toFixed(3)}`;
updateBadge(formattedPrice);
})
.catch(error => {
console.error('Error fetching XRP price:', error);
updateBadge('Error');
});
}
chrome.runtime.onInstalled.addListener(() => {
fetchxahauPrice();
});
chrome.runtime.onStartup.addListener(() => {
fetchxahauPrice();
});
chrome.action.onClicked.addListener(() => {
fetchxahauPrice();
});
chrome.idle.onStateChanged.addListener(state => {
if (state === 'active') {
fetchxahauPrice();
}
});
setInterval(fetchxahauPrice, 300000); //5 Minutes