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.
 
 
 
 

43 lines
1.1 KiB

chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
url = message.url;
action = message.action;
console.log({ url, action });
if (action === 'save') {
fetch(`https://pod.gregoryleeman.com/add?url=${encodeURIComponent(url)}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
.then((response) => response.json())
.then((data) => {
console.log({ data });
sendResponse({ success: true, data });
})
.catch((error) => {
console.error({ error });
sendResponse({ success: false, error });
});
return true;
} else if ( action == 'check' ) {
fetch(`https://pod.gregoryleeman.com/check?url=${encodeURIComponent(url)}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json'
}
})
.then((response) => response.json())
.then((data) => {
console.log({ data });
sendResponse({ success: true, data });
})
.catch((error) => {
console.error({ error });
sendResponse({ success: false, error });
});
return true;
} else {
sendResponse({ success: false, error: 'Invalid action' });
}
});