Greasy Fork is available in English.

ObrazekZeSchowka 2022

Wklej obrazek ze schowka, w pole tekstowe wpisu lub komentarza - skrypt sam go doda, jako załączony obrazek.

// ==UserScript==
// @name        ObrazekZeSchowka 2022
// @description	Wklej obrazek ze schowka, w pole tekstowe wpisu lub komentarza - skrypt sam go doda, jako załączony obrazek.
// @version     0.5
// @author      look997
// @include     https://www.wykop.pl/*
// @homepageURL https://www.wykop.pl/ludzie/addons/look997/
// @namespace   https://www.wykop.pl/ludzie/addons/look997/
// @grant       none
// @require
// @run-at      document-end
// @resource    metadata https://greasyfork.org/scripts/445949-obrazekzeschowka-2022/code/ObrazekZeSchowka%202022.user.js
// @icon        https://raw.githubusercontent.com/look997/host/main/ObrazekZeSchowka.svg
// @icon64      https://raw.githubusercontent.com/look997/host/main/ObrazekZeSchowka.svg
// ==/UserScript==

(function() {
'use strict';


//#region HEAD

function loadModal (/** @type {HTMLInputElement} */ input) {
	const popup = document.querySelector("div.embedFile")?.closest("div.summary.popup.addMediaOverlay");
	if (!popup) { return; }
	
	const loading = document.createElement("h4");
	loading.textContent = "\n\n\nTRWA DODAWANIE OBRAZU DO WPISU...";
	loading.setAttribute("style", "font-size: 2.1rem; text-align: center; white-space: pre;");
	
	const first = popup.querySelector("ul.sub-menu.inline-list");
	const second = popup.querySelector("input.embedUrl");
	const t = popup.querySelector("div.embedFile");
	const d = popup.querySelector("fieldset.buttons");
	if (!first || !second || !t || !d) { return; }
	first.hidden = true;
	second.hidden = true;
	t.hidden = true;
	d.hidden = true;
	
	first.before(loading);
	
	return function unloadModal () {
		input.removeEventListener("change", unloadModal);
		if (!popup) { return; }
		first. hidden = false;
		second.hidden = false;
		t.hidden = false;
		d.hidden = false;
		loading.remove();
	}
}

//#endregion

//#region BODY

window.document.documentElement.addEventListener('paste', e=>{
	
	const image = e.clipboardData?.files[0] && e.clipboardData.files[0].type.startsWith("image/");
	if (!image) { return; }
	
	const getInput = ()=>document.querySelector(".embedFile input");
	
	if (!getInput()) {
		const target = /** @type {Element} */ (e.target);
		const el = target.closest("form")?.querySelector("a.button.openAddMediaOverlay");
		if (!el) { return; }
		el.click();
	}
	
	const input = getInput();
	if (input) {
		const unloadModal = loadModal(input);
		
		input.files = e.clipboardData.files;
		input.dispatchEvent(new Event('change'));
		
		unloadModal&&input.addEventListener("change", unloadModal);
	}
	
});

//#endregion

})();