Skip to content

Instantly share code, notes, and snippets.

@staxmanade
Created February 21, 2014 22:41
Show Gist options
  • Save staxmanade/9145105 to your computer and use it in GitHub Desktop.
Save staxmanade/9145105 to your computer and use it in GitHub Desktop.
downloadable github files
/*
*
* The hope was to be able to drag out of the browser files from github onto the file system.
* I thought I saw the prototype work correctly once, but can't get it working anymore :(
*
*
*
*
* License: Make It Work: ( someone help me make this work )
*
* TODO:
* - Make this work correctly
* - Turn into a Chrome plugin
* - Look to correclty support mime types. (don't hard-code text/plain)
*/
$('.js-directory-link').each(function(){
$(this).attr('draggable', true);
var filePath = $(this).attr('href');
var downloadUrl = "https://raw2.github.com" + filePath.replace("/blob/", '/');
var fileName = downloadUrl.slice(downloadUrl.lastIndexOf("/")+1)
var url = "text/plain:" + fileName + ":" + downloadUrl;
this.addEventListener("dragstart",function(e){
console.log('downloading...:', url);
e.dataTransfer.setData("DownloadURL", url);
},false);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment