PlantNet Paste Image

Inject code to handle paste event for PlantNet

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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)
        }
      }
    }
  });
})();