thanhnguyen2187 / crypta

An offline-first code snippet manager
https://thanhnguyen2187.github.io/crypta/
MIT License
7 stars 0 forks source link

Allow image uploading #46

Open thanhnguyen2187 opened 7 months ago

thanhnguyen2187 commented 7 months ago

If it is within a Markdown snippet, makes the experience similar to GitHub's. Otherwise, turn the whole snippet into an image?

thanhnguyen2187 commented 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);
  }
});