UploadOnDragnDrop

Upload files on drag and drop on input field

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         UploadOnDragnDrop
// @namespace    sheesh
// @version      1.1
// @author       Ur Momma
// @match        https://shikme.chat/
// @icon         https://shikme.chat/default_images/icon.png?v=1528136794
// @grant        none
// @description Upload files on drag and drop on input field
// ==/UserScript==
const globalFileInput = document.getElementById('content');
const privateFileInput = document.getElementById('message_content');
const fileRealInput = document.getElementById('chat_file');
const privateFileRealInput = document.getElementById('private_file');

globalFileInput.addEventListener('dragover', (event) => {
	event.preventDefault();
	event.stopPropagation();
	globalFileInput.classList.add('dragover');
});

globalFileInput.addEventListener('dragleave', (event) => {
	event.preventDefault();
	event.stopPropagation();
	globalFileInput.classList.remove('dragover');
});

globalFileInput.addEventListener('drop', (event) => {
	event.preventDefault();
	event.stopPropagation();
	globalFileInput.classList.remove('dragover');
  
	const files = event.dataTransfer.files;
	if (files.length > 0) {
		fileRealInput.files = files;
		const event = new Event('change');
		fileRealInput.dispatchEvent(event);
	}
});

privateFileInput.addEventListener('dragover', (event) => {
	event.preventDefault();
	event.stopPropagation();
	privateFileInput.classList.add('dragover');
});

privateFileInput.addEventListener('dragleave', (event) => {
	event.preventDefault();
	event.stopPropagation();
	privateFileInput.classList.remove('dragover');
});

privateFileInput.addEventListener('drop', (event) => {
	event.preventDefault();
	event.stopPropagation();
	privateFileInput.classList.remove('dragover');
  
	const files = event.dataTransfer.files;
	if (files.length > 0) {
		privateFileRealInput.files = files;
		const event = new Event('change');
		privateFileRealInput.dispatchEvent(event);
	}
});