UploadOnDragnDrop

Upload files on drag and drop on input field

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

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