@mwahaj36/robotcheck 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/widget.js +1 -0
  2. package/package.json +21 -0
package/dist/widget.js ADDED
@@ -0,0 +1 @@
1
+ (()=>{var y=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var b=y((oe,P)=>{var x=performance.now(),f={mousePath:[],clickTimings:[],loadToFirstMove:null,loadToFirstClick:null,tileSelectOrder:[],hoverDwellTimes:[],checkboxDelay:null,totalTime:null,pageHidden:!1,devicePixelRatio:window.devicePixelRatio,touchEvents:0},R=0;document.addEventListener("mousemove",function(e){let t=performance.now();f.loadToFirstMove===null&&(f.loadToFirstMove=t-x),t-R>16&&(f.mousePath.push({x:e.clientX,y:e.clientY,t}),R=t)});document.addEventListener("click",function(e){let t=performance.now();f.loadToFirstClick==null&&(f.loadToFirstClick=t-x),f.clickTimings.push(t)});document.addEventListener("touchstart",function(e){f.touchEvents++});document.addEventListener("visibilitychange",function(e){document.hidden&&(f.pageHidden=!0)});P.exports={signals:f,pageLoadTime:x}});var O=y((ie,D)=>{var{signals:k,pageLoadTime:S}=b(),F=["needs coffee","oversleeps","hungry","forgets PW","loses keys","stubbed toe","daydreams","sneezes","spills drink","bites nails","gets angry","bad hair day","takes naps","loves pizza","feels lonely","loses phone","giggles","eats snacks","calls mom","talks to pet","is confused","sleepy","gets bored","needs nap","snoozes","spills tea","overthinks","feels guilt","has anxiety","gets jealous","impulsive","cries at ads","slacks off","hates Mon","buys junk","gets tired","makes typos","oversleeping","crying"],I=["0ms latency","no sleep","fast math","focused","never tires","binary logic","infinite RAM","sorts arrays","runs Python","likes C++","no feelings","debugs code","never blinks","exact timing","parses regex","reads binary","always ready","pure logic","needs power","no heartbeat","zero delay","perfect RAM","100% uptime","knows pi","CPU at 100%","parses JSON","runs code","solves math","never angry","no DNA","silicon life","overclocks","pings host","updates OS","clears cache","zero latency","no loops","compiles C","math solver"];function W(e,t){let o=e.filter(n=>t.includes(n)).length,i=e.filter(n=>!t.includes(n)).length;return o===t.length&&i===0?5:Math.max(0,i*3-o*2)}function B(e,t){let o=F.sort(()=>Math.random()-.5).slice(0,5),i=I.sort(()=>Math.random()-.5).slice(0,4),n=o.concat(i);n.sort(()=>Math.random()-.5);let l=[];for(let r=0;r<n.length;r++)o.includes(n[r])&&l.push(r);e.innerHTML="";let s=document.createElement("h1");s.innerText="Prove you are not a robot: Select human behaviors",e.appendChild(s);let u=document.createElement("div");u.className="tile-container",e.appendChild(u);let a=[],m=[],d=S;n.forEach((r,p)=>{let c=document.createElement("div");c.className="tile",c.innerText=r;let w=0;c.addEventListener("mouseenter",L=>{w=performance.now()}),c.addEventListener("mouseleave",L=>{w>0&&k.hoverDwellTimes.push(performance.now()-w)}),c.addEventListener("click",L=>{d=performance.now(),c.classList.toggle("selected");let T=c.getBoundingClientRect(),U=T.left+T.width/2,z=T.top+T.height/2;m.push({x:U,y:z,mouseIndex:k.mousePath.length});let M=a.indexOf(p);M>-1?a.splice(M,1):(a.push(p),k.tileSelectOrder.push(p))}),u.appendChild(c)});let h=document.createElement("button");h.innerText="Verify",h.className="verify-btn",h.addEventListener("click",function(r){k.totalTime=performance.now()-S,k.checkboxDelay=performance.now()-d,t(a,l,m)}),e.appendChild(h)}D.exports={scoreQuizAnswer:W,renderTiles:B}});var H=y((se,A)=>{function C(e){if(e.length===0)return 0;{let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t/e.length}}function j(e){let t=C(e),o=[];for(let i=0;i<e.length;i++)o.push(Math.pow(e[i]-t,2));return Math.sqrt(C(o))}function Y(e){let t=C(e),o=j(e),i=0;return t<80?i+=35:t<135?i+=20:t>800&&(i+=15),o<15?i+=25:o<30&&(i+=10),Math.min(100,i)}function K(e,t){let o=0,i=[],n=!1,l=0,s=null;e.innerHTML="";let u=document.createElement("h1");u.textContent="Click the box the moment it turns red",e.append(u);let a=document.createElement("div");a.className="reaction-box",e.append(a),a.addEventListener("click",function(){if(n){let d=performance.now()-l;i.push(d),o++,o===3?(e.innerText="",t(i)):m()}else clearTimeout(s),a.innerText="Too early, restarting...",setTimeout(m,1e3)});let m=()=>{n=!1,a.innerText="Wait...",a.classList.remove("red");let d=1e3+Math.random()*3e3;s=setTimeout(function(){n=!0,a.innerText="CLICK NOW !",a.classList.add("red"),l=performance.now()},d)};m()}A.exports={scoreReaction:Y,renderReaction:K}});var N=y((le,q)=>{var{signals:v,pageLoadTime:_}=b();function E(e){if(e.length===0)return 0;{let t=0;for(let o=0;o<e.length;o++)t+=e[o];return t/e.length}}function $(e){let t=E(e),o=[];for(let i=0;i<e.length;i++)o.push(Math.pow(e[i]-t,2));return Math.sqrt(E(o))}function J(e){let t=0;if(e.keystrokeTimings.length===0)return 100;if(e.pasteDetected&&(t+=40),e.typingDelay<200&&(t+=20),e.keystrokeTimings.length>3){let o=[];for(let n=1;n<e.keystrokeTimings.length;n++)o.push(e.keystrokeTimings[n]-e.keystrokeTimings[n-1]);$(o)<15&&(t+=30),E(o)<30&&(t+=20)}return Math.min(t,100)}function V(e,t){e.innerHTML="";let o=document.createElement("h1");o.textContent="Briefly describe what you had for your last meal",e.append(o);let i=document.createElement("textarea");e.append(i),i.addEventListener("keydown",l=>{let s=performance.now();v.typingDelay==null&&(v.typingDelay=s-_),v.keystrokeTimings.push(s)}),i.addEventListener("paste",l=>{v.pasteDetected=!0});let n=document.createElement("button");n.innerText="Submit",n.addEventListener("click",l=>{if(i.value==""){window.alert("Enter Text First ");return}t()}),e.append(n)}q.exports={scoreTyping:J,renderTextArea:V}});var te=y(()=>{var{signals:g,pageLoadTime:re}=b(),{renderTiles:X}=O(),{renderReaction:G}=H(),{renderTextArea:Q}=N();function Z(){let e=null,t=[],o=document.querySelector(".robotcheck");if(o==null)return;let i=o.dataset.sitekey,n=window.ROBOTCHECK_CONFIG?.apiUrl;if(!i||!n){console.warn("CANT PROCESS Without API URL AND SITEKEY");return}let l=document.createElement("iframe");l.src=`${n}/widget?sitekey=${i}&origin=${encodeURIComponent(window.location.origin)}`,l.setAttribute("sandbox","allow-scripts allow-same-origin allow-forms"),l.style.border="none",l.style.width="380px",l.style.height="280px",l.style.overflow="hidden";let s=document.createElement("input");s.type="text",s.name="confirmEmail",s.setAttribute("autocomplete","off"),s.tabIndex=-1,s.style.position="absolute",s.style.left="-9999px",s.style.opacity="0",s.style.width="0",s.style.height="0",s.style.border="none",o.appendChild(s),o.appendChild(l),window.addEventListener("message",u=>{let a=new URL(n).origin;if(u.origin==a&&u.data.type==="robotcheck:pass"){if(s&&s.value!==""){console.warn("Honeypot field filled. Pass token blocked.");return}e=u.data.token,t.forEach(m=>{m(e)})}}),window.robotcheck={getToken(){return e},onPass(u){t.push(u),e!=null&&u(e)},isReady(){return!0},reset(){e=null,l.contentWindow&&l.contentWindow.postMessage({type:"robotcheck:reset"},new URL(n).origin)}}}function ee(){let e=new URLSearchParams(window.location.search),t=e.get("sitekey"),o=e.get("origin"),i=null;document.body.innerHTML="";let n=document.createElement("div");n.style.height="240px",document.body.appendChild(n);let l=document.createElement("div");l.style.marginTop="4px",l.style.fontSize="10px";let s=document.createElement("a");s.href="https://robotcheck.dev",s.target="_blank",s.innerText="protected by roBOTcheck",s.style.color="#8b949e",s.style.textDecoration="none",l.appendChild(s),document.body.appendChild(l),m();function u(d){switch(d){case 1:X(n,(h,r,p)=>{g.selected=h,g.correct=r,g.clickTargets=p,a(1,g)});break;case 2:G(n,h=>{g.reactionTimes=h,a(2,g)});break;case 3:Q(n,()=>{a(3,g)});break}}function a(d,h){fetch("/submit",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:i,round:d,signals:h})}).then(r=>r.json()).then(r=>{if(r.verdict==="human"){n.innerHTML="";let p=document.createElement("h1");p.textContent="Welcome, Human.";let c=document.createElement("p");c.textContent="Your slow, inconsistent, and error-prone behaviour has been verified. You may proceed.",n.appendChild(p),n.appendChild(c),window.parent.postMessage({type:"robotcheck:pass",token:r.resultToken},o)}else if(r.verdict==="robot"){n.innerHTML="";let p=document.createElement("h1");p.textContent="Access Denied.";let c=document.createElement("p");d===1?c.textContent="Suspicious signals detected: Click patterns, speeds, or paths are not chaotic enough.":d===2?c.textContent="Reaction data collected: Physically impossible reaction speeds or robotic variance.":c.textContent="Typing analysis: Cadence is too consistent and typing speeds are superhuman.",n.appendChild(p),n.appendChild(c)}else if(r.verdict==="uncertain"){i=r.token||r.challengeToken||i,n.innerHTML="";let p=document.createElement("h1");p.textContent="Uncertain Heuristics...";let c=document.createElement("p");c.textContent="Escalating to next challenge round. Please wait...",n.appendChild(p),n.appendChild(c),setTimeout(()=>{u(r.nextRound)},2e3)}}).catch(r=>console.error(r))}function m(){fetch("/challenge?sitekey="+t).then(d=>d.json()).then(d=>{i=d.challengeToken,u(1)}).catch(d=>console.error(d))}}window===window.parent?Z():ee()});te();})();
package/package.json ADDED
@@ -0,0 +1,21 @@
1
+ {
2
+ "name": "@mwahaj36/robotcheck",
3
+ "version": "1.0.0",
4
+ "description": "Reverse CAPTCHA. bans robots instead of verifying humans",
5
+ "main": "dist/widget.js",
6
+ "files": [
7
+ "dist/"
8
+ ],
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1",
11
+ "build":"esbuild src/index.js --bundle --minify --outfile=dist/widget.js",
12
+ "dev":"esbuild src/index.js --bundle --watch --outfile=dist/widget.js"
13
+ },
14
+ "keywords": [],
15
+ "author": "",
16
+ "license": "ISC",
17
+ "type": "commonjs",
18
+ "devDependencies": {
19
+ "esbuild": "^0.28.0"
20
+ }
21
+ }