useful for io games like woomy-arras.io
当前为
// ==UserScript==
// @name canvas screenshot to tga
// @namespace http://bzzzzdzzzz.blogspot.com/
// @description useful for io games like woomy-arras.io
// @author BZZZZ
// @include *
// @version 0.1
// @grant none
// @run-at document-end
// ==/UserScript==
(function(){
var a=document.createElement("div");
a.setAttribute('onclick','document.getElementsByTagName("body")[0].addEventListener("keyup",new Function("evnt",'+JSON.stringify(
'if(evnt.code!="Semicolon")return;'+
'var i=document.getElementsByTagName("canvas")[0],img=i.getContext("2d").getImageData(0,0,i.width,i.height),'+
'w=img.width,h=img.height,raw=img.data,i2=raw.length,tga=new Uint8Array(18+i2);'+
'tga[2]=2;'+
'tga[12]=w&255;'+
'tga[13]=w>>8;'+
'tga[14]=h&255;'+
'tga[15]=h>>8;'+
'tga[16]=32;'+
'i=18;'+
'var w4=w*4,end,i3;'+
'while(0<i2){'+
'end=i+w4;'+
'i2-=w4;'+
'i3=i2;'+
'while(i<end){'+
'tga[2+i]=raw[i3++];'+
'tga[1+i]=raw[i3++];'+
'tga[i]=raw[i3++];'+
'tga[3+i]=raw[i3++];'+
'i+=4;'+
'}'+
'}'+
'raw=null;'+
'img=null;'+
'i=document.createElement("a");'+
'i.href=URL.createObjectURL(new Blob([tga],{"type":"image/x-targa"}));'+
'tga=null;'+
'i.download="shot.tga";'+
'evnt.target.appendChild(i);'+
'i.click();'+
'evnt.target.removeChild(i);'+
'URL.revokeObjectURL(i.href);'
)+'),false);');
a.click();
})();