| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <!DOCTYPE html>
- <html><head><meta charset="UTF-8"><title>Algorithm Test</title></head>
- <body>
- <pre id="out"></pre>
- <script>
- const out = document.getElementById('out');
- function log(s) { out.textContent += s + '\n'; }
- // ============ Extract and test the core algorithm ============
- fetch('/eye-demo/index.html').then(r=>r.text()).then(html => {
- const match = html.match(/<script>\(function \(\) \{([\s\S]+)\}\)\(\);<\/script>/);
- if (!match) { log('FAIL: no script'); return; }
-
- try {
- new Function(match[1]);
- log('PASS: JS syntax valid');
- } catch(e) {
- log('FAIL: JS syntax error: ' + e.message);
- return;
- }
- // Now run the actual page in an iframe to check runtime
- log('\n--- Runtime test (iframe) ---');
-
- const iframe = document.createElement('iframe');
- iframe.style.width = '0';
- iframe.style.height = '0';
- iframe.style.border = 'none';
- document.body.appendChild(iframe);
-
- const iframeDoc = iframe.contentDocument;
- iframeDoc.open();
- iframeDoc.write(html);
- iframeDoc.close();
-
- // Wait a moment for IIFE to execute
- setTimeout(() => {
- try {
- const win = iframe.contentWindow;
-
- // Check that the IIFE didn't throw
- log('PASS: IIFE executed without throwing');
-
- // Check localStorage
- const calData = localStorage.getItem('eye-tracking-calibration');
- if (calData) {
- log('INFO: Found existing calibration data: ' + calData.substring(0, 100) + '...');
- } else {
- log('INFO: No calibration data in localStorage (expected on first run)');
- }
-
- // Check if stage canvas exists
- const stage = iframeDoc.getElementById('stage');
- log('Stage canvas: ' + (stage ? 'OK (' + stage.width + 'x' + stage.height + ')' : 'MISSING'));
-
- // Check calibration overlay
- const calOverlay = iframeDoc.getElementById('calibration-overlay');
- log('Calibration overlay: ' + (calOverlay ? 'exists' : 'MISSING'));
- if (calOverlay) {
- log(' has show class: ' + calOverlay.classList.contains('show'));
- }
-
- // Check status text
- const statusText = iframeDoc.getElementById('status-text');
- log('Status text: ' + (statusText ? '"' + statusText.textContent + '"' : 'MISSING'));
-
- // Check cal status
- const calStatusText = iframeDoc.getElementById('cal-status-text');
- log('Cal status: ' + (calStatusText ? '"' + calStatusText.textContent + '"' : 'MISSING'));
-
- // Check recalibrate button
- const recalBtn = iframeDoc.getElementById('recalibrate-btn');
- log('Recalibrate btn: ' + (recalBtn ? 'exists (disabled=' + recalBtn.disabled + ')' : 'MISSING'));
-
- // Check debug panel
- const dbgStage = iframeDoc.getElementById('dbg-stage');
- log('dbg-stage element: ' + (dbgStage ? 'exists' : 'MISSING (bug: JS looks for debug-stage but HTML id is dbg-stage)'));
-
- log('\n--- All runtime checks done ---');
-
- } catch(e) {
- log('FAIL: Runtime error: ' + e.message);
- log('Stack: ' + e.stack);
- }
-
- // Clean up
- document.body.removeChild(iframe);
- }, 2000);
-
- }).catch(e => log('Fetch error: ' + e.message));
- </script>
- </body>
- </html>
|