Open thanhnguyen2187 opened 7 months ago
Related article: https://web.dev/patterns/clipboard/paste-images
const pasteButton = document.querySelector('#paste-button');
pasteButton.addEventListener('click', async () => {
try {
const clipboardItems = await navigator.clipboard.read();
for (const clipboardItem of clipboardItems) {
const imageTypes = clipboardItem.types.find(type => type.startsWith('image/'))
for (const imageType of imageTypes) {
const blob = await clipboardItem.getType(imageType);
// Do something with the image blob.
}
}
} catch (err) {
console.error(err.name, err.message);
}
});
If it is within a Markdown snippet, makes the experience similar to GitHub's. Otherwise, turn the whole snippet into an image?