File size: 9,251 Bytes
6a9eac6 4f7a003 6a9eac6 4f7a003 6a9eac6 4f7a003 6a9eac6 d0145f4 6a9eac6 d0145f4 6a9eac6 d0145f4 6a9eac6 d0145f4 6a9eac6 04baf1c 6a9eac6 4f7a003 2ee296b 6a9eac6 2ee296b 6a9eac6 114b4e0 4f7a003 | 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 |
// Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyDEXAMPLEEXAMPLEEXAMPLEEXAMPLE",
authDomain: "your-app.firebaseapp.com",
projectId: "your-app",
storageBucket: "your-app.appspot.com",
messagingSenderId: "1234567890",
appId: "1:1234567890:web:abcdef1234567890"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const auth = firebase.auth();
// Dark mode toggle functionality
document.addEventListener('DOMContentLoaded', function() {
// Check for dark mode preference
if (localStorage.getItem('darkMode') === 'true' ||
(!localStorage.getItem('darkMode') && window.matchMedia('(prefers-color-scheme: dark)').matches)) {
document.documentElement.classList.add('dark');
}
// Initialize tooltips
const tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.map(function (tooltipTriggerEl) {
return new bootstrap.Tooltip(tooltipTriggerEl);
});
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
// Handle auth state changes
auth.onAuthStateChanged(user => {
if (user) {
console.log('User logged in:', user);
// Update UI for logged-in user
document.querySelectorAll('.auth-buttons').forEach(el => {
el.innerHTML = `
<div class="flex items-center gap-2">
<img src="${user.photoURL || 'http://static.photos/people/40x40/1'}"
class="w-8 h-8 rounded-full" alt="Profile">
<button onclick="logout()" class="signup-btn">Logout</button>
</div>
`;
});
} else {
console.log('User logged out');
// Update UI for logged-out user
}
});
});
// Auth functions
async function loginWithGoogle() {
try {
const provider = new firebase.auth.GoogleAuthProvider();
await auth.signInWithPopup(provider);
} catch (error) {
const modal = document.querySelector('login-modal');
if (modal) modal.showErrorMessage(error.message || 'Google login failed');
}
}
async function loginWithMicrosoft() {
try {
const provider = new firebase.auth.OAuthProvider('microsoft.com');
provider.setCustomParameters({ prompt: 'select_account' });
await auth.signInWithPopup(provider);
} catch (error) {
const modal = document.querySelector('login-modal');
if (modal) modal.showErrorMessage(error.message || 'Microsoft login failed');
}
}
async function loginWithApple() {
try {
const provider = new firebase.auth.OAuthProvider('apple.com');
provider.addScope('email');
provider.addScope('name');
await auth.signInWithPopup(provider);
} catch (error) {
const modal = document.querySelector('login-modal');
if (modal) modal.showErrorMessage(error.message || 'Apple login failed');
}
}
async function loginWithEmail(email, password) {
return auth.signInWithEmailAndPassword(email, password);
}
async function signupWithEmail(name, email, password) {
const userCredential = await auth.createUserWithEmailAndPassword(email, password);
await userCredential.user.updateProfile({ displayName: name });
return userCredential;
}
function logout() {
auth.signOut()
.then(() => {
console.log('User logged out');
})
.catch(error => {
console.error('Logout error:', error);
});
}
// Flashcard deck options dropdown functionality
document.addEventListener('DOMContentLoaded', function() {
// Close dropdowns when clicking outside
document.addEventListener('click', function(e) {
if (!e.target.closest('.deck-options-btn')) {
document.querySelectorAll('.options-dropdown').forEach(dropdown => {
dropdown.classList.add('hidden');
});
}
});
// Toggle dropdowns
document.querySelectorAll('.deck-options-btn').forEach(btn => {
btn.addEventListener('click', function(e) {
e.stopPropagation();
const dropdown = this.nextElementSibling;
document.querySelectorAll('.options-dropdown').forEach(d => {
if (d !== dropdown) d.classList.add('hidden');
});
dropdown.classList.toggle('hidden');
});
});
});
// Example function for flashcard generation
function generateFlashcards(sourceType, content) {
console.log(`Generating flashcards from ${sourceType}: ${content}`);
// In a real app, this would call your backend/AI service
return new Promise((resolve) => {
setTimeout(() => {
const sampleFlashcards = [
{ front: "What is photosynthesis?", back: "The process by which green plants use sunlight to synthesize foods from carbon dioxide and water." },
{ front: "What are the reactants of photosynthesis?", back: "Carbon dioxide, water, and sunlight." },
{ front: "What are the products of photosynthesis?", back: "Glucose and oxygen." }
];
resolve(sampleFlashcards);
}, 1000);
});
}
// Show login modal with optional tab
function showLoginModal(tab = 'login') {
const modal = document.querySelector('login-modal');
if (modal) {
modal.open(tab);
}
}
// Quiz generation functions
function generateQuizFromFlashcards(deckId, difficulty, questionCount) {
// Implementation would call backend API
console.log(`Generating quiz from deck ${deckId} (${difficulty}, ${questionCount} questions)`);
return new Promise(resolve => {
setTimeout(() => {
resolve({
id: 'quiz-' + Date.now(),
deckId,
difficulty,
questions: Array(questionCount).fill().map((_, i) => ({
id: 'q' + i,
question: `Sample question ${i+1} about ${deckId}`,
options: ['Option 1', 'Option 2', 'Option 3', 'Option 4'],
answer: Math.floor(Math.random() * 4)
}))
});
}, 1000);
});
}
function generateQuizFromTopic(topic, difficulty, questionCount) {
// Implementation would call backend API
console.log(`Generating quiz about ${topic} (${difficulty}, ${questionCount} questions)`);
return new Promise(resolve => {
setTimeout(() => {
resolve({
id: 'quiz-' + Date.now(),
topic,
difficulty,
questions: Array(questionCount).fill().map((_, i) => ({
id: 'q' + i,
question: `Sample question ${i+1} about ${topic}`,
options: ['Option 1', 'Option 2', 'Option 3', 'Option 4'],
answer: Math.floor(Math.random() * 4)
}))
});
}, 1000);
});
}
// Note management functions
function createNewNote(title, content, topic, tags = [], generateFlashcards = false) {
console.log(`Creating new note: ${title} (${topic})`);
if (generateFlashcards) {
console.log(`Also generating flashcards for note`);
}
// Implementation would call backend API
return new Promise(resolve => {
setTimeout(() => {
resolve({
id: 'note-' + Date.now(),
title,
content,
topic,
tags,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
});
}, 800);
});
}
// Example function for quiz generation
function generateQuiz(topic) {
console.log(`Generating quiz about ${topic}`);
// In a real app, this would call your backend/AI service
return new Promise((resolve) => {
setTimeout(() => {
const sampleQuiz = {
title: `Quiz about ${topic}`,
questions: [
{
question: "What is the main purpose of photosynthesis?",
options: [
"To produce oxygen",
"To create glucose for energy",
"To absorb sunlight",
"All of the above"
],
answer: 3
},
{
question: "Which organelle performs photosynthesis?",
options: [
"Mitochondria",
"Nucleus",
"Chloroplast",
"Ribosome"
],
answer: 2
}
]
};
resolve(sampleQuiz);
}, 1000);
});
} |