Upload from clipboard

upload images to sillypost from your clipboard!

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Upload from clipboard
// @namespace    http://tampermonkey.net/
// @version      2025-05-13-2
// @description  upload images to sillypost from your clipboard!
// @author       niko.earth
// @match        https://sillypost.net/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=sillypost.net
// @grant        none
// @license GNU GPLv3
// ==/UserScript==

(function() {
    'use strict';

    async function onbuttonclicked() {
        const clipboardItems = await navigator.clipboard.read();
        if (clipboardItems.length == 0) {
            alert("clipboard was empty! did you try to paste a file instead of image data?");
        }
        clipboardItems.forEach(async element => {
            element.types.forEach(async type => {
                if (!["image/png", "image/gif", "image/jpeg"].includes(type)) { return }
                if (element.types.includes(type)) {
                    const blob = await element.getType(type)

                    let file = new File([blob], `clipboard-${new Date().toISOString().split(".")[0]}.${type.split("/")[1]}`,{type:type, lastModified:new Date().getTime()});
                    let container = new DataTransfer();
                    container.items.add(file);

                    document.getElementById("sketch").files = container.files;
                }
            })
        });
    }

    const sketchButton = document.getElementById("sketch");
    const clipboardButton = document.createElement("button");
    clipboardButton.innerText = "image from clipboard..."
    clipboardButton.onclick = onbuttonclicked;
    clipboardButton.setAttribute("type", "button");
    sketchButton.after(clipboardButton)
})();