init
This commit is contained in:
35
chrome-extension/background.js
Normal file
35
chrome-extension/background.js
Normal file
@@ -0,0 +1,35 @@
|
||||
// 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;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user