IWBH_01

tinycore linux firefox file upload crash workaround improved

Jul 27th, 2020
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. put this portion inside a bookmark in Firefox with "javascript:" protocol prefix
  3.  
  4. this script depends on 2 of my other scripts:
  5.  node_insec_basic_wup.js  (a simple nodejs server)
  6.  and fuwp.html, a file that uses the server to request uploads
  7.  you can find both of these in my public pastes https://pastebin.com/u/IWBH_01
  8. */
  9. self.firdy=new WeakMap(); //file input ready
  10.  
  11. HTMLInputElement.prototype.__defineGetter__("files",
  12. function(){ if(firdy.has(this))return firdy.get(this); }
  13. );
  14.  
  15. var itemF=function item(i){ return this[i]; };
  16. FileList.prototype.__defineGetter__("item",function(){ return itemF; });
  17.  
  18.  
  19. self._w2_=self.open("http://127.0.0.1:120/*fuwp.html?or="+btoa(self.origin));
  20.  
  21.  
  22.  
  23. //opening file browse box
  24. var FnavBox=document.createElement("div"),
  25. FBs=FnavBox.style;
  26. FBs.backgroundColor="white";
  27. FBs.position="fixed";
  28. FBs.top="50px";
  29. FBs.left="50px";
  30. FBs.width="400px";
  31. FBs.height="300px";
  32. FBs.border="2px solid gray";
  33. FBs.zIndex="999999";
  34.  
  35. var fiBx2=document.createElement("div"),
  36. f2s=fiBx2.style;
  37. f2s.overflow="scroll";
  38. f2s.border="2px solid grey";
  39. f2s.width="350px";
  40. f2s.height="200px";
  41. fiBx2.onclick=function(e){
  42.  var tar=e.target||e.srcElement;
  43.  if(tar.nodeName=="BUTTON"){
  44.   pthD.value+=tar.innerText;
  45.   if(tar.parentNode.parentNode.children[1].innerText=="Folder"){pthD.value+="/";
  46.    _w2_.postMessage({"nav":!0,"do":pthD.value},"http://127.0.0.1:120");
  47.   }
  48.  }
  49. };
  50. FnavBox.appendChild(fiBx2);
  51.  
  52. var pthD=document.createElement("input");
  53. pthD.type="text";
  54. FnavBox.appendChild(pthD);
  55.  
  56. var opnB=document.createElement("button");
  57. opnB.innerText="Open";
  58. opnB.onclick=function(){
  59.  if(pthD.value){ //if path selected
  60.   var o2={"do":pthD.value};
  61.   if(o2.do[o2.do.length-1]=="/"){
  62.    o2.nav=!0;
  63.   }else{ //if path is not dir
  64.    o2.l0d=!0;
  65.   }
  66.   _w2_.postMessage(o2,"http://127.0.0.1:120");
  67.  }
  68. };
  69. FnavBox.appendChild(opnB);
  70.  
  71. var clsB=document.createElement("button");
  72. clsB.innerText="Cancel";
  73. clsB.onclick=function(){
  74.  document.body.removeChild(FnavBox);
  75.  pthD.value="";
  76.  fiBx2.innerHTML="";
  77. };
  78. FnavBox.appendChild(clsB);
  79.  
  80.  
  81.  
  82.  
  83. self.addEventListener("click",self.fuhf_=function(e){
  84.  var tar=e.target||e.srcElement;
  85.  if(tar.nodeName=="INPUT"&&tar.type=="file"){
  86.   e.preventDefault();
  87.  
  88.   self.curAinp=tar;
  89.  
  90.   document.body.appendChild(FnavBox);
  91.   _w2_.postMessage({"nav":!0,"do":"/"},"http://127.0.0.1:120");
  92.  }
  93. });
  94.  
  95. self.addEventListener("message",function(e){
  96.  self._LM_=e;
  97.  if(e.source==_w2_){
  98.   var da=e.data;
  99.   if(da.dir){
  100.    //render dir
  101.    var i=0,fc=da.dir,L=fc.length,ci,rH="<table><tbody>";
  102.    while(i<L){
  103.     ci=fc[i];
  104.     rH+="<tr><td><button>"+ci[0]+"</button></td><td>"+ci.slice(1).join("</td><td>")+"</td></tr>";
  105.     i++;
  106.    }
  107.    fiBx2.innerHTML=rH+"</tbody></table>";
  108.   }else if(da.files){
  109.    //upload files
  110.    var i=0,files=[],Lifs=da.files,L=Lifs.length,cf;
  111.    while(i<L){ cf=Lifs[i]; files.push(new File([cf[0]],cf[1],{"type":cf[2]})); i++;}  
  112.  
  113.    files.__proto__=FileList.prototype;
  114.    firdy.set(curAinp,files);
  115.    
  116.    var ae=new Event("change");
  117.  
  118.    curAinp.dispatchEvent(ae);
  119.   }
  120.  }
  121. });
  122.  
  123.  
  124. //end main page side script
  125.  
  126.  
  127.  
  128.  
  129.  
Add Comment
Please, Sign In to add comment