// ==UserScript== // @name iqdb Ctrl + V // @name:en iqdb Ctrl + V // @namespace http://tampermonkey.net/ // @version 0.1.1 // @description 在 iqdb 中使用 Ctrl + V 上传图片 // @description:en Upload image to iqdb by Ctrl + V // @author apkipa // @match https://www.iqdb.org // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; function handlePaste(e) { var clipboardData, pastedData; clipboardData = e.clipboardData || window.clipboardData; pastedData = clipboardData.items[0]; if (pastedData.type.indexOf("image") !== -1) { e.stopPropagation(); e.preventDefault(); var fileInput = document.getElementById("file"); var formUpload = document.querySelectorAll("input[type=submit]")[0]; /* ? Not working here fileInput.addEventListener("change", () => { formUpload.form.submit(); }); */ fileInput.files = clipboardData.files; // Automatically submit the pasted image // (If this is not desired, comment the next line) formUpload.form.submit(); } else { console.log("Not an image, paste event propagated"); } } window.addEventListener('paste', handlePaste); })();