-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
960 lines (843 loc) · 37.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
<!DOCTYPE html>
<html>
<head>
<title>Enhanced EMDR Therapy App</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Fonts & Icons -->
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>
:root {
--primary-color: #007ACC;
--secondary-color: #2D2D2D;
--text-color: #FFFFFF;
--background-color: #1E1E1E;
--shadow-color: rgba(0, 0, 0, 0.7);
--panel-background: rgba(30, 30, 30, 0.95);
--accent-color: #00BCD4;
}
body {
color: var(--text-color);
background-color: var(--background-color);
overflow: hidden;
font-family: 'Roboto', sans-serif;
line-height: 1.6;
margin: 0;
padding: 0;
}
#scene-container {
width: 100vw;
height: 100vh;
position: relative;
}
.main-controls {
position: absolute;
top: 10px;
left: 10px;
display: flex;
flex-direction: row;
gap: 10px;
z-index: 999;
}
.icon-button {
width: 40px;
height: 40px;
background: rgba(0, 0, 0, 0.7);
color: white;
border: none;
cursor: pointer;
font-size: 24px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 6px;
position: relative;
}
.icon-button:hover {
background: rgba(0,0,0,0.9);
}
.tooltip .tooltip-text {
visibility: hidden;
background-color: var(--secondary-color);
color: var(--text-color);
text-align: center;
padding: 6px 10px;
border-radius: 4px;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
transform: translateX(-50%);
opacity: 0;
transition: opacity 0.3s;
font-size: 12px;
white-space: nowrap;
}
.tooltip:hover .tooltip-text {
visibility: visible;
opacity: 1;
}
.settings-panel,
.questions-panel {
display: none;
position: absolute;
top: 60px;
left: 50%;
transform: translateX(-50%);
width: 90%;
background: var(--panel-background);
border-radius: 12px;
padding: 20px;
box-shadow: 0 8px 30px rgba(0,0,0,0.5);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.2);
animation: fadeIn 0.3s ease-out;
z-index: 999;
max-height: 70vh;
overflow-y: auto;
overflow-x: hidden;
}
/* Make questions panel slightly wider */
.questions-panel {
max-width: 650px;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.settings-panel h2,
.questions-panel h2 {
margin-bottom: 10px;
font-weight: 500;
}
.settings-section {
margin-bottom: 20px;
}
.settings-section h3 {
margin-bottom: 10px;
font-size: 1.1em;
}
.control-group {
margin-bottom: 10px;
font-size: 14px;
display: flex;
flex-direction: column;
}
.control-group label {
margin-bottom: 5px;
}
.slider-container {
display: flex;
align-items: center;
}
.slider {
-webkit-appearance: none;
width: 100%;
height: 6px;
border-radius: 3px;
background: var(--secondary-color);
outline: none;
transition: all 0.3s ease;
}
.slider::-webkit-slider-thumb {
-webkit-appearance: none;
width: 20px;
height: 20px;
border-radius: 50%;
background: var(--primary-color);
cursor: pointer;
transition: all 0.3s ease;
}
.slider::-webkit-slider-thumb:hover {
background: var(--accent-color);
}
.slider-value {
margin-left: 10px;
font-size: 13px;
}
.enhanced-select,
input[type="color"] {
padding: 5px;
background-color: var(--secondary-color);
color: var(--text-color);
border: 1px solid #555;
border-radius: 4px;
font-size: 13px;
}
select.enhanced-select {
width: 100%;
}
.color-controls {
display: flex;
gap: 20px;
}
.color-preset-btn,
.gradient-preset-btn {
margin-left: 10px;
padding: 5px 10px;
background: var(--secondary-color);
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 12px;
}
.color-preset-btn:hover,
.gradient-preset-btn:hover {
background: var(--accent-color);
}
.session-controls {
position: absolute;
bottom: 10px;
right: 10px;
display: flex;
gap: 10px;
z-index: 999;
}
.btn {
padding: 10px 20px;
border: none;
border-radius: 6px;
font-weight: 500;
cursor: pointer;
transition: all 0.3s ease;
display: inline-flex;
align-items: center;
justify-content: center;
box-shadow: 0 2px 8px var(--shadow-color);
font-size: 14px;
}
.btn-primary {
background-color: var(--primary-color);
color: var(--text-color);
}
.btn-primary:hover {
background-color: #0088E4;
}
.btn-secondary {
background-color: #555;
color: #fff;
}
.btn-secondary:hover {
background-color: #666;
}
.btn-danger {
background-color: #F44336;
color: #fff;
}
.btn-danger:hover {
background-color: #D32F2F;
}
/* Fade unobtrusive timer without progress bar */
.session-timer {
display: none;
position: absolute;
top: 20px;
right: 20px;
font-size: 14px;
font-weight: 500;
color: #ffffff;
opacity: 0.6;
z-index:999;
}
.questions-panel .question {
margin-bottom: 20px;
font-size: 14px;
}
.questions-panel .question label {
margin-bottom: 5px;
display: block;
}
.questions-panel textarea {
width: 100%;
resize: vertical;
padding: 10px;
background-color: var(--secondary-color);
color: var(--text-color);
border: 1px solid #555;
border-radius: 4px;
font-family: inherit;
font-size: 14px;
}
.questions-panel input[type="range"] {
width: 100%;
}
.questions-panel .range-value {
text-align: right;
font-size: 13px;
}
</style>
</head>
<body>
<div id="scene-container"></div>
<div class="main-controls">
<button id="settingsButton" class="icon-button tooltip" title="Settings">
<span class="material-icons">settings</span>
<span class="tooltip-text">Adjust session settings</span>
</button>
<button id="questionsButton" class="icon-button tooltip" title="Therapeutic Guide">
<span class="material-icons">psychology</span>
<span class="tooltip-text">Open therapeutic guidance</span>
</button>
<button id="saveButton" class="icon-button tooltip" title="Save Q&A">
<span class="material-icons">save</span>
<span class="tooltip-text">Save Q&A and Ratings</span>
</button>
<button id="fullscreenButton" class="icon-button tooltip" title="Toggle Fullscreen">
<span class="material-icons">fullscreen</span>
<span class="tooltip-text">Toggle Fullscreen</span>
</button>
</div>
<div class="session-timer" id="sessionTimer">
<span id="timerDisplay">00:00</span>
</div>
<div class="settings-panel" id="settingsPanel">
<h2>Session Settings</h2>
<div class="question" style="font-style: italic; font-size: 12px; margin-bottom: 10px;">
The smoothness of the ball depends mainly on your computer's screen refresh rate.
</div>
<div class="settings-section">
<h3>Visual Settings</h3>
<div class="control-group">
<label for="textureSelect">Ball Texture</label>
<select id="textureSelect" class="enhanced-select">
<option value="solid" selected>Solid</option>
<option value="wireframe">Wireframe</option>
</select>
</div>
<div class="control-group">
<label for="ballSizeSlider">Ball Size</label>
<div class="slider-container">
<input type="range" id="ballSizeSlider" class="slider" min="0.1" max="2" step="0.1" value="0.5">
<span class="slider-value" id="ballSizeValue">0.5</span>
</div>
</div>
<div class="control-group">
<label for="speedSlider">Movement Speed</label>
<div class="slider-container">
<input type="range" id="speedSlider" class="slider" min="0.1" max="5" step="0.1" value="1.2">
<span class="slider-value" id="speedValue">1.2</span>
</div>
</div>
<div class="color-controls">
<div class="control-group">
<label for="ballColor">Ball Color</label>
<input type="color" id="ballColor" value="#ff0000">
<button class="color-preset-btn" data-color="#ff0000">Red</button>
<button class="color-preset-btn" data-color="#00ff00">Green</button>
<button class="color-preset-btn" data-color="#0000ff">Blue</button>
</div>
<div class="control-group">
<label for="bgColor">Background</label>
<input type="color" id="bgColor" value="#000000">
<button class="gradient-preset-btn" data-gradient="dark">Dark Gradient</button>
<button class="gradient-preset-btn" data-gradient="calm">Calm Gradient</button>
</div>
</div>
<!-- Comment out effectSelect as requested -->
<!--
<div class="control-group">
<label for="effectSelect">Visual Effects</label>
<select id="effectSelect" class="enhanced-select" multiple>
<option value="glow">Glow Effect</option>
<option value="trail">Motion Trail</option>
<option value="particles">Particle System</option>
<option value="shadows">Enhanced Shadows</option>
</select>
</div>
-->
</div>
<div class="settings-section">
<h3>Audio Settings</h3>
<!-- Frequency slider and invert panning checkbox as requested -->
<div class="control-group">
<label for="soundTypeSelect">Primary Sound</label>
<select id="soundTypeSelect" class="enhanced-select">
<option value="sine">Sine Wave</option>
<option value="square">Square Wave</option>
<option value="sawtooth">Sawtooth</option>
<option value="triangle">Triangle</option>
</select>
</div>
<div class="control-group">
<label for="frequencyControl">Frequency (Hz)</label>
<div class="slider-container">
<input type="range" id="frequencyControl" class="slider" min="20" max="2000" step="1" value="220">
<span class="slider-value" id="frequencyValue">220 Hz</span>
</div>
</div>
<div class="control-group">
<label class="checkbox-label">
<input type="checkbox" id="invertPanning"> Invert Sound Panning
</label>
</div>
<div class="control-group">
<label for="mainVolumeSlider">Volume</label>
<div class="slider-container">
<input type="range" id="mainVolumeSlider" class="slider" min="0" max="1" step="0.01" value="0.3">
<span class="slider-value" id="mainVolumeValue">30%</span>
</div>
</div>
</div>
</div>
<div class="questions-panel" id="questionsPanel">
<h2>Therapeutic Guidance</h2>
<div class="question" style="font-style: italic; font-size: 11px; margin-bottom: 10px;">
Note 1: This app is ideally used after learning about EMDR from any course, even online courses.
</div>
<div class="question" style="font-style: italic; font-size: 11px; margin-bottom: 30px;">
Note 2: If you do not feel any emotion about the target issue, this might indicate dissociation.
Consider seeking professional guidance to help safely unfreeze your emotions.
</div>
<div class="question">
<label for="question1">1. How are you feeling today?</label>
<textarea id="question1" rows="3"></textarea>
</div>
<div class="question">
<label for="question2">2. What issues are prompting today's session?</label>
<textarea id="question2" rows="3"></textarea>
</div>
<div class="question">
<label>3. Detailing your Target:</label>
<div style="padding-left:20px;">
<div class="question">
<label for="question3a">- What images, sounds, or smells are triggered when thinking about the target issue?</label>
<textarea id="question3a" rows="3"></textarea>
</div>
<div class="question">
<label for="question3b">- What do you recall about the issue?</label>
<textarea id="question3b" rows="3"></textarea>
</div>
<div class="question">
<label for="question3c">- What feelings or emotions come up?</label>
<textarea id="question3c" rows="3"></textarea>
</div>
<div class="question">
<label for="question3d">- Most disturbing moment about it?</label>
<textarea id="question3d" rows="3"></textarea>
</div>
<div class="question">
<label for="question3e">- When thinking about the issue, what physical sensations do you feel? Where do you feel them?</label>
<textarea id="question3e" rows="3"></textarea>
</div>
</div>
</div>
<div class="question">
<label for="question4">4. Combine these into a single description of your Target issue:</label>
<textarea id="question4" rows="3"></textarea>
</div>
<div class="question">
<label for="question5">5. Write any negative beliefs about yourself regarding this.</label>
<textarea id="question5" rows="3"></textarea>
</div>
<div class="question">
<label for="question6">6. Now write positive beliefs you can really believe about yourself regarding this.</label>
<textarea id="question6" rows="3"></textarea>
</div>
<div class="question">
<label for="question7">7. Current Emotional Distress Rating (1-10)?</label>
<input type="range" id="question7" min="1" max="10" step="1" value="1">
<div class="range-value">Rating: <span id="question7Value">1</span></div>
</div>
<div class="question">
<label>8. Take 10-40 minutes to do EMDR on the target, then return here.</label>
</div>
<div class="question">
<label for="question9">9. Post-EMDR Distress Rating (1-10)?</label>
<input type="range" id="question9" min="1" max="10" step="1" value="1">
<div class="range-value">Rating: <span id="question9Value">1</span></div>
</div>
<div class="question">
<label>10. You can continue doing EMDR as needed until you feel at ease.</label>
</div>
</div>
<div class="session-controls">
<button id="startButton" class="btn btn-primary">
<span class="material-icons">play_arrow</span>
Start
</button>
<!-- Remove pause button as requested -->
<!-- <button id="pauseButton" ... >Pause</button> -->
<button id="endButton" class="btn btn-danger" style="display: none;">
<span class="material-icons">stop</span>
End
</button>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>
<script>
class EMDRApp {
constructor() {
this.scene = null;
this.camera = null;
this.renderer = null;
this.ball = null;
this.direction = 0.1;
this.audioContext = null;
this.oscillator = null;
this.gainNode = null;
this.panner = null;
this.isSessionActive = false;
this.sessionTimer = null;
this.animationFrameId = null;
this.isPanelOpen = false;
this.isFullScreen = false;
this.settings = {
visual: {
ballSize: 0.5,
speed: 1.2,
texture: 'solid',
ballColor: '#ff0000',
backgroundColor: '#000000',
isGradient: false,
gradientType: '',
// effects: [] // commented out since no effects now
},
audio: {
mainVolume: 0.3,
primarySound: 'sine',
frequency: 220,
invertPanning: false
}
};
this.init();
this.setupEventListeners();
}
init() {
this.initThreeJS();
this.applySettings();
this.renderScene();
}
initThreeJS() {
this.scene = new THREE.Scene();
this.camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
this.camera.position.z = 5;
this.renderer = new THREE.WebGLRenderer({ antialias: true, alpha: true });
this.renderer.setSize(window.innerWidth, window.innerHeight);
document.getElementById('scene-container').appendChild(this.renderer.domElement);
const ambientLight = new THREE.AmbientLight(0xffffff, 0.8);
this.scene.add(ambientLight);
const directionalLight = new THREE.DirectionalLight(0xffffff, 0.8);
directionalLight.position.set(5,5,5);
this.scene.add(directionalLight);
this.createBall();
}
createBall() {
if (this.ball) this.scene.remove(this.ball);
const geometry = new THREE.SphereGeometry(1,32,32);
let mat;
if (this.settings.visual.texture === 'wireframe') {
mat = new THREE.MeshBasicMaterial({ color: this.settings.visual.ballColor, wireframe:true });
} else {
mat = new THREE.MeshBasicMaterial({ color: this.settings.visual.ballColor });
}
this.ball = new THREE.Mesh(geometry, mat);
this.ball.scale.set(this.settings.visual.ballSize,this.settings.visual.ballSize,this.settings.visual.ballSize);
this.scene.add(this.ball);
}
applySettings() {
// If pure black and no gradient chosen, just solid black background
if (!this.settings.visual.isGradient) {
this.renderer.setClearAlpha(1);
this.scene.background = new THREE.Color(this.settings.visual.backgroundColor);
document.body.style.background = this.settings.visual.backgroundColor;
} else {
// Gradient chosen
this.renderer.setClearAlpha(0);
this.scene.background = null;
if (this.settings.visual.gradientType === 'dark') {
document.body.style.background = "linear-gradient(to bottom, #000000, #1E1E1E)";
} else if (this.settings.visual.gradientType === 'calm') {
document.body.style.background = "linear-gradient(to bottom, #001f3f, #1E1E1E)";
}
}
this.createBall();
this.renderScene();
}
renderScene() {
this.renderer.render(this.scene, this.camera);
}
startSession() {
if (this.isSessionActive) return;
this.isSessionActive = true;
this.sessionStartTime = Date.now();
this.closeAllPanels();
this.startAudioChain();
this.startTimer();
this.updateSessionUI(true);
this.animate();
}
startAudioChain() {
this.audioContext = new (window.AudioContext || window.webkitAudioContext)();
this.oscillator = this.audioContext.createOscillator();
this.gainNode = this.audioContext.createGain();
this.panner = this.audioContext.createStereoPanner();
this.oscillator.type = this.settings.audio.primarySound;
this.oscillator.frequency.value = this.settings.audio.frequency;
this.gainNode.gain.value = this.settings.audio.mainVolume;
this.oscillator.connect(this.gainNode);
this.gainNode.connect(this.panner);
this.panner.connect(this.audioContext.destination);
this.oscillator.start();
}
animate() {
if (!this.isSessionActive) return;
this.animationFrameId = requestAnimationFrame(() => this.animate());
if (this.isPanelOpen) {
// Panels open, do not move the ball
this.renderScene();
return;
}
this.ball.position.x += this.direction * this.settings.visual.speed;
if (this.ball.position.x > 6.5 || this.ball.position.x < -6.5) {
this.direction *= -1;
}
let panValue = 2 * (this.ball.position.x / 6.5);
if (this.settings.audio.invertPanning) panValue *= -1;
this.panner.pan.value = Math.max(-1, Math.min(1, panValue));
const positionFactor = Math.abs(this.ball.position.x / 6.5);
const volume = this.settings.audio.mainVolume * (0.2 + 0.8 * positionFactor);
this.gainNode.gain.value = volume;
this.oscillator.frequency.value = this.settings.audio.frequency;
this.renderScene();
}
startTimer() {
document.getElementById('sessionTimer').style.display = 'block';
this.sessionTimer = setInterval(() => {
const elapsed = Date.now() - this.sessionStartTime;
const minutes = Math.floor(elapsed / 60000);
const seconds = Math.floor((elapsed % 60000) / 1000);
document.getElementById('timerDisplay').textContent =
`${minutes.toString().padStart(2,'0')}:${seconds.toString().padStart(2,'0')}`;
}, 1000);
}
endSession() {
if (!this.isSessionActive) return;
this.isSessionActive = false;
if (this.sessionTimer) clearInterval(this.sessionTimer);
if (this.animationFrameId) cancelAnimationFrame(this.animationFrameId);
if (this.oscillator) {
try { this.oscillator.stop(); } catch(e){}
this.oscillator.disconnect();
this.oscillator = null;
}
if (this.audioContext) {
this.audioContext.close();
this.audioContext = null;
}
this.ball.position.set(0,0,0);
this.updateSessionUI(false);
this.saveSessionData();
this.renderScene();
}
updateSessionUI(running) {
const startBtn = document.getElementById('startButton');
const endBtn = document.getElementById('endButton');
const sessionTimer = document.getElementById('sessionTimer');
if (running) {
startBtn.style.display = 'none';
endBtn.style.display = 'inline-block';
sessionTimer.style.display = 'block';
} else {
startBtn.style.display = 'inline-block';
endBtn.style.display = 'none';
sessionTimer.style.display = 'none';
}
}
saveSessionData() {
const sessionData = {
date: new Date().toISOString(),
duration: Date.now() - this.sessionStartTime,
settings: { ...this.settings }
};
let sessions = JSON.parse(localStorage.getItem('emdrSessions') || '[]');
sessions.push(sessionData);
localStorage.setItem('emdrSessions', JSON.stringify(sessions));
}
saveQA() {
const questions = [
{id:'question1', label:'How are you feeling today?'},
{id:'question2', label:'Issues prompting the session?'},
{id:'question3a', label:'Images, sounds, smells triggered?'},
{id:'question3b', label:'Recall of traumatic event?'},
{id:'question3c', label:'Feelings or emotions?'},
{id:'question3d', label:'Most disturbing moment?'},
{id:'question3e', label:'Physical sensations?'},
{id:'question4', label:'Combined description of Target:'},
{id:'question5', label:'Negative beliefs?'},
{id:'question6', label:'Positive beliefs?'},
];
const q7 = document.getElementById('question7').value;
const q9 = document.getElementById('question9').value;
let text = "EMDR Session Q&A\n\n";
questions.forEach(q => {
const val = document.getElementById(q.id).value;
text += q.label + "\n" + val + "\n\n";
});
text += "Initial Distress Rating: " + q7 + "\n\n";
text += "Post-EMDR Distress Rating: " + q9 + "\n\n";
const blob = new Blob([text], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'EMDR_Session_QA.txt';
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
}
handleKeyPress(e) {
if (e.code === 'Escape') {
if (this.isPanelOpen) {
this.closeAllPanels();
e.preventDefault(); // Attempt to prevent fullscreen exit
}
// If no panel is open, do nothing (try to prevent default)
else {
e.preventDefault(); // Attempt to prevent fullscreen exit by the browser
}
} else if (e.code === 'Space') {
// Space toggles start/stop if no panel is open
if (!this.isPanelOpen) {
if (this.isSessionActive) {
this.endSession();
} else {
this.startSession();
}
}
e.preventDefault();
}
}
closeAllPanels() {
document.getElementById('settingsPanel').style.display = 'none';
document.getElementById('questionsPanel').style.display = 'none';
this.isPanelOpen = false;
}
applyAndSaveSettings() {
this.applySettings();
this.saveSettings();
}
saveSettings() {
localStorage.setItem('emdrSettings', JSON.stringify(this.settings));
}
setupEventListeners() {
window.addEventListener('resize', () => this.onWindowResize());
document.getElementById('startButton').addEventListener('click', () => this.startSession());
document.getElementById('endButton').addEventListener('click', () => this.endSession());
document.getElementById('settingsButton').addEventListener('click', () => {
const sp = document.getElementById('settingsPanel');
const qp = document.getElementById('questionsPanel');
qp.style.display = 'none';
sp.style.display = (sp.style.display === 'block')?'none':'block';
this.isPanelOpen = (sp.style.display === 'block');
});
document.getElementById('questionsButton').addEventListener('click', () => {
const sp = document.getElementById('settingsPanel');
const qp = document.getElementById('questionsPanel');
sp.style.display = 'none';
qp.style.display = (qp.style.display === 'block')?'none':'block';
this.isPanelOpen = (qp.style.display === 'block');
});
document.getElementById('saveButton').addEventListener('click', () => this.saveQA());
// Fullscreen button
document.getElementById('fullscreenButton').addEventListener('click', () => {
if (!this.isFullScreen) {
document.documentElement.requestFullscreen().catch(err => console.log(err));
} else {
if (document.fullscreenElement) {
document.exitFullscreen().catch(err => console.log(err));
}
}
});
document.addEventListener('fullscreenchange', () => {
this.isFullScreen = !!document.fullscreenElement;
const fsIcon = document.getElementById('fullscreenButton').querySelector('.material-icons');
fsIcon.textContent = this.isFullScreen ? 'fullscreen_exit' : 'fullscreen';
});
const applyInstant = () => {
this.applySettings();
this.saveSettings();
};
document.getElementById('textureSelect').addEventListener('change', (e) => {
this.settings.visual.texture = e.target.value;
applyInstant();
});
document.getElementById('ballSizeSlider').addEventListener('input', (e) => {
this.settings.visual.ballSize = parseFloat(e.target.value);
document.getElementById('ballSizeValue').textContent = e.target.value;
applyInstant();
});
document.getElementById('speedSlider').addEventListener('input', (e) => {
this.settings.visual.speed = parseFloat(e.target.value);
document.getElementById('speedValue').textContent = e.target.value;
applyInstant();
});
document.getElementById('ballColor').addEventListener('change', (e) => {
this.settings.visual.ballColor = e.target.value;
// If user picks black background and no gradient chosen, no gradient applied
applyInstant();
});
document.querySelectorAll('.color-preset-btn').forEach(btn => {
btn.addEventListener('click', () => {
const color = btn.getAttribute('data-color');
this.settings.visual.ballColor = color;
document.getElementById('ballColor').value = color;
applyInstant();
});
});
document.getElementById('bgColor').addEventListener('change', (e) => {
this.settings.visual.backgroundColor = e.target.value;
this.settings.visual.isGradient = false;
applyInstant();
});
document.querySelectorAll('.gradient-preset-btn').forEach(btn => {
btn.addEventListener('click', () => {
const gradient = btn.getAttribute('data-gradient');
this.settings.visual.isGradient = true;
this.settings.visual.gradientType = gradient;
applyInstant();
});
});
// Removed effects from the menu, so no effectSelect listener
document.getElementById('soundTypeSelect').addEventListener('change', (e) => {
this.settings.audio.primarySound = e.target.value;
applyInstant();
});
document.getElementById('frequencyControl').addEventListener('input', (e) => {
const freq = parseFloat(e.target.value);
this.settings.audio.frequency = freq;
document.getElementById('frequencyValue').textContent = freq + ' Hz';
applyInstant();
});
document.getElementById('invertPanning').addEventListener('change', (e) => {
this.settings.audio.invertPanning = e.target.checked;
applyInstant();
});
document.getElementById('mainVolumeSlider').addEventListener('input', (e) => {
this.settings.audio.mainVolume = parseFloat(e.target.value);
document.getElementById('mainVolumeValue').textContent = (this.settings.audio.mainVolume * 100).toFixed(0) + '%';
applyInstant();
});
document.getElementById('question7').addEventListener('input', (e) => {
document.getElementById('question7Value').textContent = e.target.value;
});
document.getElementById('question9').addEventListener('input', (e) => {
document.getElementById('question9Value').textContent = e.target.value;
});
document.addEventListener('keydown', (e) => this.handleKeyPress(e));
}
onWindowResize() {
this.camera.aspect = window.innerWidth / window.innerHeight;
this.camera.updateProjectionMatrix();
this.renderer.setSize(window.innerWidth, window.innerHeight);
}
}
document.addEventListener('DOMContentLoaded', () => {
try {
window.emdrApp = new EMDRApp();
} catch (error) {
console.error('Failed to initialize EMDR application:', error);
}
});
</script>
</body>
</html>