Skip to content

Instantly share code, notes, and snippets.

@ww24
Created March 20, 2012 02:11
Show Gist options
  • Save ww24/2130122 to your computer and use it in GitHub Desktop.
Save ww24/2130122 to your computer and use it in GitHub Desktop.
ブラウザで開いている画像をBase64エンコードするブックマークレット
javascript:(function(){var x=new XMLHttpRequest();x.open('GET',location.href);x.overrideMimeType('text/plain;charset=x-user-defined');x.onload=function(){var n=[],b=x.responseText,a=[];for(var s=b.length,i=0;i<s;i++){n[i]=b.charCodeAt(i)&0xff}for(var l=n.length,i=0;i<l;i++){a[i]=parseInt(n[i],10).toString(2);for(var p=8-a[i].length,j=0;j<p;j++){a[i]='0'+String(a[i])}}a=a.join('');n=a.length%6;if(n!==0){for(var l=6-n,i=0;i<l;i++){a+='0'}}b=[];for(var l=a.length/6,i=0;i<l;i++){var m='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',n=parseInt(a.substr(i*6,6),2);b[i]=m.substr(n,1)}b=b.join('');n=b.length%4;if(n!==0){for(var l=4-n,i=0;i<l;i++){b+='='}}window.open('data:image/png;base64,'+b,'')};x.send(null)})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment