Upload from clipboard

upload images to sillypost from your clipboard!

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

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