PlantNet Paste Image

Inject code to handle paste event for PlantNet

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         PlantNet Paste Image
// @namespace    vinz3210.gg
// @version      1.0
// @license      MIT
// @author       vinz3210
// @description  Inject code to handle paste event for PlantNet
// @match        https://identify.plantnet.org/*
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  window.addEventListener('paste', async e => {
    const items = e.clipboardData.items;
    for (let i = 0; i < items.length; i++) {
      if (items[i].type.startsWith('image/')) {
        const blob = items[i].getAsFile(); // Get the pasted image as a Blob
        if (blob) {
          const file = new File([blob], "pasted_image.png", { type: blob.type }); // Create a File object
          const dataTransfer = new DataTransfer();
          dataTransfer.items.add(file);
          document.getElementById("file").files = dataTransfer.files;
          // Optionally, trigger a change event if needed
          const event = new Event('change', { bubbles: true });
          document.getElementById("file").dispatchEvent(event);
          break; // Stop after the first image is pasted (if you only want to handle one)
        }
      }
    }
  });
})();