Skip to content

Instantly share code, notes, and snippets.

@xulapp
Created February 12, 2011 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xulapp/823791 to your computer and use it in GitHub Desktop.
Save xulapp/823791 to your computer and use it in GitHub Desktop.
dropInputFileName.uc.js
// ==UserScript==
// @name dropInputFileName.uc.js
// @description
// @include main
// @charset utf-8
// @compatibility Firefox 3.6+
// @namespace http://twitter.com/xulapp
// @author xulapp
// @license MIT License
// @version 2011/02/12 23:00 +09:00
// ==/UserScript==
(function dropInputFileName() {
const XHTML_NS = function() 'http://www.w3.org/1999/xhtml';
document.addEventListener('drop', function DIFN_onDrop(event) {
var {files} = event.dataTransfer;
if (!files.length) return;
var {target} = event;
target = target.ownerDocument.evaluate('ancestor-or-self::html:input[@type="file"]', target, XHTML_NS, 9, null).singleNodeValue;
if (!target) return;
event.preventDefault();
event.stopPropagation();
var paths = Array.map(files, function(file) file.mozFullPath);
var length = target.multiple ? paths.length : 1;
target.mozSetFileNameArray(paths, length);
}, true, false);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment