-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
278 lines (235 loc) · 8.29 KB
/
Copy pathscript.js
File metadata and controls
278 lines (235 loc) · 8.29 KB
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
// RecallForge - Flashcard App with 3D Elements
// Main JavaScript functionality
// Sample flashcards for demonstration
const flashcards = [
{ front: "What is the capital of France?", back: "Paris" },
{ front: "What is the capital of Japan?", back: "Tokyo" },
{ front: "What is the capital of Brazil?", back: "Brasília" },
{ front: "What is the capital of Australia?", back: "Canberra" },
{ front: "What is the capital of Egypt?", back: "Cairo" }
];
// Initialize variables for tracking stats
let currentCardIndex = 0;
// Note: reviewed, remembered, and forgotten variables are already defined in the HTML
// Initialize the app when the DOM is fully loaded
document.addEventListener('DOMContentLoaded', () => {
// Initialize the flashcard
updateFlashcard();
// Set up event listeners
setupEventListeners();
// Initialize the 3D elements
initialize3DElements();
});
// Update the flashcard with current content
function updateFlashcard() {
const flashcard = document.querySelector('.flashcard');
const front = flashcard.querySelector('.front');
const back = flashcard.querySelector('.back');
front.textContent = flashcards[currentCardIndex].front;
back.textContent = flashcards[currentCardIndex].back;
// Reset the flipped state
flashcard.classList.remove('flipped');
}
// Move to the next flashcard
function nextCard() {
currentCardIndex = (currentCardIndex + 1) % flashcards.length;
updateFlashcard();
}
// Update the stats display - using the global variables from HTML
function updateStats() {
document.getElementById("reviewed").innerText = reviewed;
document.getElementById("remembered").innerText = remembered;
document.getElementById("forgotten").innerText = forgotten;
}
// Set up event listeners for the app
function setupEventListeners() {
// Flashcard click to flip
const flashcard = document.querySelector('.flashcard');
flashcard.addEventListener('click', () => {
flashcard.classList.toggle('flipped');
});
// FAQ toggles
document.querySelectorAll('.faq-item').forEach(item => {
item.addEventListener('click', () => {
item.classList.toggle('open');
const toggle = item.querySelector('.toggle');
toggle.textContent = item.classList.contains('open') ? '-' : '+';
});
});
// Settings form changes
document.getElementById('theme-dark')?.addEventListener('change', () => applyTheme('dark'));
document.getElementById('theme-light')?.addEventListener('change', () => applyTheme('light'));
document.getElementById('theme-auto')?.addEventListener('change', () => applyTheme('auto'));
// Enhanced navigation system
setupNavigation();
}
// Set up the navigation system
function setupNavigation() {
const sections = ['decks', 'stats', 'settings', 'help'];
const mainContent = document.querySelector('.content');
const pageTransition = document.querySelector('.page-transition');
const navLinks = document.querySelectorAll('nav a');
sections.forEach(section => {
document.getElementById(`nav-${section}`).addEventListener('click', (e) => {
e.preventDefault();
// Add active class to clicked nav item
navLinks.forEach(link => link.classList.remove('active'));
e.target.classList.add('active');
// Show transition screen
pageTransition.classList.add('active');
// Fade the main content
mainContent.classList.add('faded');
setTimeout(() => {
// Hide all sections and 3D elements
sections.forEach(s => {
const sectionElement = document.getElementById(`section-${s}`);
sectionElement.style.display = 'none';
sectionElement.classList.remove('active');
document.getElementById(`${s}-3d`).style.opacity = 0;
});
// After a slight delay, show the selected section
setTimeout(() => {
// Show selected section and 3D background
const selectedSection = document.getElementById(`section-${section}`);
selectedSection.style.display = 'block';
// Force reflow to enable transition
selectedSection.offsetHeight;
selectedSection.classList.add('active');
document.getElementById(`${section}-3d`).style.opacity = 1;
// Hide transition screen
pageTransition.classList.remove('active');
// Un-fade the main content with reduced opacity
mainContent.classList.remove('faded');
// Scroll to top smoothly
window.scrollTo({ top: 0, behavior: 'smooth' });
}, 300);
}, 500);
});
});
}
// Apply theme changes
function applyTheme(theme) {
const root = document.documentElement;
if (theme === 'light') {
root.style.setProperty('--bg-color', '#f5f5f5');
root.style.setProperty('--text-color', '#333');
document.body.classList.add('light-mode');
} else {
root.style.setProperty('--bg-color', '#000');
root.style.setProperty('--text-color', '#e7e7e7');
document.body.classList.remove('light-mode');
}
}
// Initialize and manage 3D elements
function initialize3DElements() {
// Get all 3D viewers
const viewers = document.querySelectorAll('spline-viewer');
// Make sure the main robot 3D is visible
const mainRobot = document.querySelector('.robot-3d');
if (mainRobot) {
mainRobot.style.opacity = '1';
}
// Add CSS for flashcard flipping if not already in the HTML
addFlashcardStyles();
}
// Add CSS for flashcard flipping
function addFlashcardStyles() {
// Check if styles already exist
if (!document.getElementById('flashcard-styles')) {
const style = document.createElement('style');
style.id = 'flashcard-styles';
style.textContent = `
.flashcard-box {
perspective: 1000px;
width: 100%;
max-width: 500px;
height: 300px;
margin: 2rem 0;
}
.flashcard {
width: 100%;
height: 100%;
position: relative;
transition: transform 0.6s;
transform-style: preserve-3d;
cursor: pointer;
}
.flashcard.flipped {
transform: rotateY(180deg);
}
.front, .back {
position: absolute;
width: 100%;
height: 100%;
backface-visibility: hidden;
display: flex;
align-items: center;
justify-content: center;
padding: 2rem;
border-radius: 10px;
background: #1a1a1a;
border: 1px solid #333;
color: white;
font-size: 1.5rem;
text-align: center;
}
.back {
transform: rotateY(180deg);
background: #2a2a2a;
}
.buttons {
display: flex;
gap: 1rem;
margin-top: 1rem;
justify-content: center;
}
.buttons button {
cursor: pointer;
border: none;
border-radius: 50px;
padding: 0.7rem 1.5rem;
font-weight: 600;
transition: all 0.3s ease;
}
.stats {
text-align: center;
margin-top: 1rem;
color: #aaa;
}
`;
document.head.appendChild(style);
}
}
// Show a notification message
function showNotification(message) {
// Create notification element if it doesn't exist
let notification = document.querySelector('.notification');
if (!notification) {
notification = document.createElement('div');
notification.className = 'notification';
document.body.appendChild(notification);
// Add styles
notification.style.position = 'fixed';
notification.style.bottom = '20px';
notification.style.right = '20px';
notification.style.backgroundColor = '#9f79ff';
notification.style.color = 'white';
notification.style.padding = '10px 20px';
notification.style.borderRadius = '5px';
notification.style.zIndex = '1000';
notification.style.opacity = '0';
notification.style.transform = 'translateY(20px)';
notification.style.transition = 'opacity 0.3s ease, transform 0.3s ease';
}
// Set message and show
notification.textContent = message;
setTimeout(() => {
notification.style.opacity = '1';
notification.style.transform = 'translateY(0)';
}, 10);
// Hide after 3 seconds
setTimeout(() => {
notification.style.opacity = '0';
notification.style.transform = 'translateY(20px)';
}, 3000);
}