Files
spectral-display/chrome-extension/background.js
Yorgei e23ac642a7 init
2026-01-18 14:29:12 +10:00

36 lines
1.4 KiB
JavaScript

// CORS
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'fetchPrice') {
fetch(`https://www.ely.gg/chart/${request.itemId}/prices`)
.then(response => response.json())
.then(data => sendResponse({ success: true, data }))
.catch(error => sendResponse({ success: false, error: error.message }));
return true;
} else if (request.action === 'fetchData') {
fetch(request.url)
.then(response => response.json())
.then(data => sendResponse({ success: true, data }))
.catch(error => sendResponse({ success: false, error: error.message }));
return true;
}
});
//Firefox compatibility
if (typeof browser !== 'undefined') {
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'fetchPrice') {
fetch(`https://www.ely.gg/chart/${request.itemId}/prices`)
.then(response => response.json())
.then(data => sendResponse({ success: true, data }))
.catch(error => sendResponse({ success: false, error: error.message }));
return true;
} else if (request.action === 'fetchData') {
fetch(request.url)
.then(response => response.json())
.then(data => sendResponse({ success: true, data }))
.catch(error => sendResponse({ success: false, error: error.message }));
return true;
}
});
}