flyingff2083/parallel_self
0
1/**2 * Consent Page Logic3 */4 5document.addEventListener('DOMContentLoaded', () => {6 log('Consent page loaded');7 8 // Fetch system configuration9 fetchSystemConfig();10 11 // Button handlers12 document.getElementById('agree-btn').addEventListener('click', handleAgree);13 document.getElementById('decline-btn').addEventListener('click', handleDecline);14});15 16async function fetchSystemConfig() {17 try {18 const response = await fetch(`${CONFIG.API_URL}/health`);19 const data = await response.json();20 21 log('System config:', data);22 23 // Display mode24 document.getElementById('mode-display').textContent = 25 data.mode === 'gentle' ? 'Gentle Mode' : 'Research Mode';26 27 // Fetch support resources28 const supportResponse = await fetch(`${CONFIG.API_URL}/safety/support-resources`);29 const supportData = await supportResponse.json();30 31 if (supportData.success) {32 document.getElementById('emergency-email').textContent = 33 supportData.resources.emergency.email;34 document.getElementById('researcher-email').textContent = 35 supportData.resources.researcher.email;36 }37 } catch (err) {38 error('Failed to fetch system config:', err);39 }40}41 42async function handleAgree() {43 log('User agreed to consent');44 45 try {46 // Create session47 const response = await fetch(`${CONFIG.API_URL}/session/start`, {48 method: 'POST',49 headers: {50 'Content-Type': 'application/json'51 }52 });53 54 const data = await response.json();55 56 if (data.success) {57 log('Session created:', data.sessionId);58 59 // Save session ID60 localStorage.setItem(CONFIG.SESSION_STORAGE_KEY, data.sessionId);61 62 // Record consent63 await fetch(`${CONFIG.API_URL}/session/${data.sessionId}/consent`, {64 method: 'POST',65 headers: {66 'Content-Type': 'application/json'67 },68 body: JSON.stringify({ consented: true })69 });70 71 // Redirect to main page72 window.location.href = 'index.html';73 } else {74 alert('Failed to create session, please try again.');75 }76 } catch (err) {77 error('Failed to create session:', err);78 alert('Failed to connect to server, please check if the backend is running.');79 }80}81 82function handleDecline() {83 log('User declined consent');84 85 if (confirm('Are you sure you want to exit?')) {86 alert('Thank you for your time. If you have any questions, please contact the research team.');87 window.close();88 }89}90 