iqdb Ctrl + V

在 iqdb 中使用 Ctrl + V 上传图片

Από την 14/06/2021. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

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.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name            iqdb Ctrl + V
// @name:en         iqdb Ctrl + V
// @namespace       http://tampermonkey.net/
// @version         0.1.2
// @description     在 iqdb 中使用 Ctrl + V 上传图片
// @description:en  Upload image to iqdb by Ctrl + V
// @author          apkipa
// @match           https://www.iqdb.org
// @grant           none
// ==/UserScript==

(function() {
    'use strict';

    function extractImageFilesFromClipboard(event) {
        var clipboardData = event.clipboardData || window.clipboardData;
        var files = clipboardData.files;
        var a = new DataTransfer();

        for (var i = 0; i < files.length; i++) {
            if (files[i].type.indexOf("image") !== -1) {
                a.items.add(files[i]);
            }
        }

        if (a.files.length < 1) {
            return null;
        }

        return a.files;
    }

    function createFilelistFromSingleFile(file) {
        var a = new DataTransfer();
        a.items.add(file);
        return a.files;
    }

    function handlePaste(e) {
        var clipboardData, pastedData;

        var files = extractImageFilesFromClipboard(e);

        if (files !== null) {
            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 = createFilelistFromSingleFile(files[0]);

            // Automatically submit the pasted image
            // (If this is not desired behavior, comment the next line)
            formUpload.form.submit();
        }
        else {
            console.log("Not an image, paste event propagated");
        }
    }

    window.addEventListener('paste', handlePaste);
})();