36 lines
1.4 KiB
JavaScript
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;
|
|
}
|
|
});
|
|
}
|