You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

41 lines
1.4 KiB

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
const data = message.data;
data.url = message.url;
if (message.action === 'saveMedia') {
fetch('https://media.gregoryleeman.com/api/items', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then((response) => response.json())
.then((responseData) => {
console.log('Success:', responseData);
sendResponse({ success: true, responseData });
})
.catch((error) => {
console.error('Error:', error);
sendResponse({ success: false, error });
});
return true; // Keep the message channel open for async response
} else if ( message.action == 'checkMedia' ) {
fetch('https://media.gregoryleeman.com/api/items/check?url=' + encodeURIComponent(data.url), {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
.then((response) => response.json())
.then((responseData) => {
console.log('Success:', responseData);
sendResponse({ success: true, responseData });
})
.catch((error) => {
console.error('Error:', error);
sendResponse({ success: false, error });
});
return true; // Keep the message channel open for async response
}
});