Enable image pasting from clipboard in Poe

Simulate drag and drop when pasting an image from the clipboard

  1. // ==UserScript==
  2. // @name Enable image pasting from clipboard in Poe
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Simulate drag and drop when pasting an image from the clipboard
  6. // @author You
  7. // @match https://poe.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Helper function to dispatch an event
  16. function dispatchEvent(type, target, dataTransfer) {
  17. const event = new Event(type, {
  18. bubbles: true,
  19. cancelable: true
  20. });
  21.  
  22. // Set the dataTransfer property if available
  23. if (dataTransfer) {
  24. event.dataTransfer = dataTransfer;
  25. }
  26.  
  27. // Dispatch the event on the target element
  28. target.dispatchEvent(event);
  29. }
  30.  
  31. // Add event listener for paste events
  32. window.addEventListener('paste', (event) => {
  33. let items = (event.clipboardData || event.originalEvent.clipboardData).items;
  34.  
  35. for (let index in items) {
  36. let item = items[index];
  37. if (item.kind === 'file') {
  38. let blob = item.getAsFile();
  39. let dataTransfer = new DataTransfer();
  40. dataTransfer.items.add(blob);
  41.  
  42. // Identify the drop zone element. You need to adjust this selector for the webpage.
  43. let dropZone = document.querySelector("div[class*=ChatDragDropTarget_dropTarget]");
  44.  
  45. // Simulate the drag and drop events
  46. dispatchEvent('dragenter', dropZone, dataTransfer);
  47. dispatchEvent('dragover', dropZone, dataTransfer);
  48. dispatchEvent('drop', dropZone, dataTransfer);
  49.  
  50. // Prevent the default paste action
  51. event.preventDefault();
  52. }
  53. }
  54. });
  55. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址