Skip to content

Instantly share code, notes, and snippets.

@surjikal
Last active April 1, 2017 11:10
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 surjikal/57c509749ad805a81c6827f4f5becbc1 to your computer and use it in GitHub Desktop.
Save surjikal/57c509749ad805a81c6827f4f5becbc1 to your computer and use it in GitHub Desktop.
!function(a,b){"function"==typeof define&&define.amd?define([],b):"object"==typeof exports?module.exports=b():a.download=b()}(this,function(){return function a(b,c,d){function q(a){var b=a.split(/[:;,]/),c=b[1],d="base64"==b[2]?atob:decodeURIComponent,e=d(b.pop()),f=e.length,g=0,h=new Uint8Array(f);for(g;g<f;++g)h[g]=e.charCodeAt(g);return new l([h],{type:c})}function r(a,b){if("download"in j)return j.href=a,j.setAttribute("download",m),j.className="download-js-link",j.innerHTML="downloading...",j.style.display="none",document.body.appendChild(j),setTimeout(function(){j.click(),document.body.removeChild(j),b===!0&&setTimeout(function(){e.URL.revokeObjectURL(j.href)},250)},66),!0;if(/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//.test(navigator.userAgent))return a=a.replace(/^data:([\w\/\-\+]+)/,f),window.open(a)||confirm("Displaying New Document\n\nUse Save As... to download, then click back to return to this page.")&&(location.href=a),!0;var c=document.createElement("iframe");document.body.appendChild(c),b||(a="data:"+a.replace(/^data:([\w\/\-\+]+)/,f)),c.src=a,setTimeout(function(){document.body.removeChild(c)},333)}var n,o,e=window,f="application/octet-stream",g=d||f,h=b,i=!c&&!d&&h,j=document.createElement("a"),k=function(a){return String(a)},l=e.Blob||e.MozBlob||e.WebKitBlob||k,m=c||"download";if(l=l.call?l.bind(e):Blob,"true"===String(this)&&(h=[h,g],g=h[0],h=h[1]),i&&i.length<2048&&(m=i.split("/").pop().split("?")[0],j.href=i,j.href.indexOf(i)!==-1)){var p=new XMLHttpRequest;return p.open("GET",i,!0),p.responseType="blob",p.onload=function(b){a(b.target.response,m,f)},setTimeout(function(){p.send()},0),p}if(/^data\:[\w+\-]+\/[\w+\-]+[,;]/.test(h)){if(!(h.length>2096103.424&&l!==k))return navigator.msSaveBlob?navigator.msSaveBlob(q(h),m):r(h);h=q(h),g=h.type||f}if(n=h instanceof l?h:new l([h],{type:g}),navigator.msSaveBlob)return navigator.msSaveBlob(n,m);if(e.URL)r(e.URL.createObjectURL(n),!0);else{if("string"==typeof n||n.constructor===k)try{return r("data:"+g+";base64,"+e.btoa(n))}catch(a){return r("data:"+g+","+encodeURIComponent(n))}o=new FileReader,o.onload=function(a){r(this.result)},o.readAsDataURL(n)}return!0}});

function fetch() {
    var filename = "place-" + Date.now() + ".png";
    download($('canvas')[0].toDataURL('image/png'), filename, 'image/png');
}
timer = setInterval(fetch, 1000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment