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.

40 lines
1014 B

1 month ago
function saveImageFromUrl(info, tab) {
const url = info.srcUrl;
const data = new URLSearchParams({
url: url
});
fetch("https://images.gregoryleeman.com/upload-url", {
method: "POST",
body: data,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
})
.then(response => {
if (!response.ok) {
console.error("Server responded with a non-OK status.");
return response.text().then(text => {
console.error("Server response:", text);
throw new Error("Server error");
});
} else {
console.log("Image successfully uploaded.");
}
})
.catch(error => {
console.error('Fetch error:', error.message);
});
}
chrome.contextMenus.create({
id: "save-image",
title: "Save Image",
contexts: ["image"]
});
chrome.contextMenus.onClicked.addListener(function(info, tab) {
saveImageFromUrl(info, tab);
});