2 lines
2.0 KiB
JavaScript
2 lines
2.0 KiB
JavaScript
/*! @source http://purl.eligrey.com/github/FileSaver.js/blob/master/FileSaver.js */
|
|
var saveAs=saveAs||(function(l){"use strict";var k=l.URL||l.webkitURL||l,f=l.webkitRequestFileSystem,m=l.requestFileSystem||f||l.mozRequestFileSystem,c=function(n){(l.setImmediate||setTimeout)(function(){throw n},0)},j="application/octet-stream",h=0,g=[],e=function(){var o=g.length;while(o--){var n=g[o];if(typeof n==="string"){k.revokeObjectURL(n)}else{n.remove()}}g.length=0},i=function(o,n,r){n=[].concat(n);var q=n.length;while(q--){var s=o["on"+n[q]];if(typeof s==="function"){try{s.call(o,r||o)}catch(p){c(p)}}}},b=function(o,q){var n=this,r=o.type,t=function(){var u=k.createObjectURL(o);p.location.href=u;g.push(u);n.readyState=2;i(n,"writestart progress write writeend".split(" "))},s=function(u){return function(){if(n.readyState!==2){return u.apply(this,arguments)}}},p;n.readyState=n.INIT;if(!q){q="download"}if(o.webkitSlice&&r!==j){o=o.webkitSlice(0,o.size,j)}if(f&&q!=="download"){q+=".download"}if(r===j||f){p=self}else{p=open()}if(!m){t();return}h+=o.size;m(l.TEMPORARY,h,s(function(u){u.root.getDirectory("saved",{create:true,exclusive:false},s(function(v){var w=function(){v.getFile(q,{create:true,exclusive:false},s(function(x){x.createWriter(s(function(y){y.onwriteend=function(z){p.location.href=x.toURL();g.push(x);n.readyState=n.DONE;i(n,"writeend",z)};y.onerror=function(){var z=y.error;if(z.code!==z.ABORT_ERR){t()}};"writestart progress write abort".split(" ").forEach(function(z){y["on"+z]=n["on"+z]});y.write(o);n.abort=function(){y.abort();n.readyState=n.DONE};n.readyState=n.WRITING}),t)}),t)};v.getFile(q,{create:false},s(function(x){x.remove();w()}),s(function(x){if(x.code===x.NOT_FOUND_ERR){w()}else{t()}}))}),t)}),t)},a=b.prototype,d=function(n,o){return new b(n,o)};a.abort=function(){var n=this;n.readyState=n.DONE;i(n,"abort")};a.readyState=a.INIT=0;a.WRITING=1;a.DONE=2;a.error=a.onwritestart=a.onprogress=a.onwrite=a.onabort=a.onerror=a.onwriteend=null;l.addEventListener("unload",e,false);return d}(self)); |