PlantNet Paste Image

Inject code to handle paste event for PlantNet

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

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