Created
February 12, 2011 14:25
-
-
Save xulapp/823791 to your computer and use it in GitHub Desktop.
dropInputFileName.uc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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