-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsocketiointerceptor.js
More file actions
1 lines (1 loc) · 2.04 KB
/
Copy pathsocketiointerceptor.js
File metadata and controls
1 lines (1 loc) · 2.04 KB
1
(()=>{if(window.__sockGUI)return;if(!window.io||!io.Socket){alert("Socket.IO not found");return}window.__sockGUI=1;let paused=0,bo=new Set(),bi=new Set();const d=document.createElement("div");d.style="position:fixed;top:20px;right:20px;width:360px;height:520px;background:#111;color:#0f0;z-index:999999;font-family:monospace;border:1px solid #0f0;padding:0";d.innerHTML='<div id=h style="cursor:move;padding:6px;border-bottom:1px solid #0f0"><b>Socket GUI</b> <button id=p>PAUSE</button></div><div style="padding:6px">Block OUT:<input id=bo style=width:100%>Block IN:<input id=bi style=width:100%><hr><input id=ev placeholder=event style=width:100%><textarea id=data placeholder=json style=width:100%;height:60px></textarea><button id=s>SEND</button><hr><div id=l style=height:280px;overflow:auto></div></div>';document.body.appendChild(d);d.querySelector("#h").onmousedown=e=>{let r=d.getBoundingClientRect(),x=e.clientX-r.left,y=e.clientY-r.top;document.onmousemove=m=>{d.style.left=m.clientX-x+"px";d.style.top=m.clientY-y+"px"};document.onmouseup=()=>document.onmousemove=null};const log=t=>{let x=document.createElement("div");x.textContent=t;d.querySelector("#l").prepend(x)};d.querySelector("#p").onclick=()=>{paused=!paused;d.querySelector("#p").textContent=paused?"RESUME":"PAUSE"};const upd=()=>{bo=new Set(d.querySelector("#bo").value.split(",").map(x=>x.trim()).filter(x=>x));bi=new Set(d.querySelector("#bi").value.split(",").map(x=>x.trim()).filter(x=>x))};d.querySelector("#bo").oninput=upd;d.querySelector("#bi").oninput=upd;const S=io.Socket.prototype;S.__emit=S.emit;S.__on=S.on;S.emit=function(e,...a){log("OUT "+e);if(paused||bo.has(e))return;return S.__emit.call(this,e,...a)};S.on=function(e,f){return S.__on.call(this,e,function(...a){log("IN "+e);if(paused||bi.has(e))return;f.apply(this,a)})};const gs=()=>Object.values(io.managers)[0]?.nsps["/"]?.socket;d.querySelector("#s").onclick=()=>{let e=d.querySelector("#ev").value,v;try{v=JSON.parse(d.querySelector("#data").value||"{}")}catch{return alert("bad json")}gs()?.emit(e,v)};alert("Socket GUI loaded")})();