Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- put this portion inside a bookmark in Firefox with "javascript:" protocol prefix
- this script depends on 2 of my other scripts:
- node_insec_basic_wup.js (a simple nodejs server)
- and fuwp.html, a file that uses the server to request uploads
- you can find both of these in my public pastes https://pastebin.com/u/IWBH_01
- */
- self.firdy=new WeakMap(); //file input ready
- HTMLInputElement.prototype.__defineGetter__("files",
- function(){ if(firdy.has(this))return firdy.get(this); }
- );
- var itemF=function item(i){ return this[i]; };
- FileList.prototype.__defineGetter__("item",function(){ return itemF; });
- self._w2_=self.open("http://127.0.0.1:120/*fuwp.html?or="+btoa(self.origin));
- //opening file browse box
- var FnavBox=document.createElement("div"),
- FBs=FnavBox.style;
- FBs.backgroundColor="white";
- FBs.position="fixed";
- FBs.top="50px";
- FBs.left="50px";
- FBs.width="400px";
- FBs.height="300px";
- FBs.border="2px solid gray";
- FBs.zIndex="999999";
- var fiBx2=document.createElement("div"),
- f2s=fiBx2.style;
- f2s.overflow="scroll";
- f2s.border="2px solid grey";
- f2s.width="350px";
- f2s.height="200px";
- fiBx2.onclick=function(e){
- var tar=e.target||e.srcElement;
- if(tar.nodeName=="BUTTON"){
- pthD.value+=tar.innerText;
- if(tar.parentNode.parentNode.children[1].innerText=="Folder"){pthD.value+="/";
- _w2_.postMessage({"nav":!0,"do":pthD.value},"http://127.0.0.1:120");
- }
- }
- };
- FnavBox.appendChild(fiBx2);
- var pthD=document.createElement("input");
- pthD.type="text";
- FnavBox.appendChild(pthD);
- var opnB=document.createElement("button");
- opnB.innerText="Open";
- opnB.onclick=function(){
- if(pthD.value){ //if path selected
- var o2={"do":pthD.value};
- if(o2.do[o2.do.length-1]=="/"){
- o2.nav=!0;
- }else{ //if path is not dir
- o2.l0d=!0;
- }
- _w2_.postMessage(o2,"http://127.0.0.1:120");
- }
- };
- FnavBox.appendChild(opnB);
- var clsB=document.createElement("button");
- clsB.innerText="Cancel";
- clsB.onclick=function(){
- document.body.removeChild(FnavBox);
- pthD.value="";
- fiBx2.innerHTML="";
- };
- FnavBox.appendChild(clsB);
- self.addEventListener("click",self.fuhf_=function(e){
- var tar=e.target||e.srcElement;
- if(tar.nodeName=="INPUT"&&tar.type=="file"){
- e.preventDefault();
- self.curAinp=tar;
- document.body.appendChild(FnavBox);
- _w2_.postMessage({"nav":!0,"do":"/"},"http://127.0.0.1:120");
- }
- });
- self.addEventListener("message",function(e){
- self._LM_=e;
- if(e.source==_w2_){
- var da=e.data;
- if(da.dir){
- //render dir
- var i=0,fc=da.dir,L=fc.length,ci,rH="<table><tbody>";
- while(i<L){
- ci=fc[i];
- rH+="<tr><td><button>"+ci[0]+"</button></td><td>"+ci.slice(1).join("</td><td>")+"</td></tr>";
- i++;
- }
- fiBx2.innerHTML=rH+"</tbody></table>";
- }else if(da.files){
- //upload files
- var i=0,files=[],Lifs=da.files,L=Lifs.length,cf;
- while(i<L){ cf=Lifs[i]; files.push(new File([cf[0]],cf[1],{"type":cf[2]})); i++;}
- files.__proto__=FileList.prototype;
- firdy.set(curAinp,files);
- var ae=new Event("change");
- curAinp.dispatchEvent(ae);
- }
- }
- });
- //end main page side script
Add Comment
Please, Sign In to add comment