Upload from clipboard

upload images to sillypost from your clipboard!

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

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