UploadOnDragnDrop

Upload files on drag and drop on input field

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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         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);
	}
});