appscms-tools-theme 5.1.0 → 5.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,82 +1,158 @@
1
+ ---
2
+ ---
1
3
  const profileButton = document.getElementById("profileButton");
2
4
  const userModal = document.getElementById("userModal");
3
5
  let isModalOpen = false;
4
6
 
5
- profileButton.addEventListener("click", () => {
6
- if (isModalOpen) {
7
- userModal.style.display = "none";
8
- isModalOpen = false;
9
- } else {
10
- userModal.style.display = "block";
11
- isModalOpen = true;
12
- }
13
- });
7
+ if (profileButton && userModal) {
8
+ profileButton.addEventListener("click", () => {
9
+ if (isModalOpen) {
10
+ userModal.style.display = "none";
11
+ isModalOpen = false;
12
+ } else {
13
+ userModal.style.display = "block";
14
+ isModalOpen = true;
15
+ }
16
+ });
17
+
18
+ // Close modal when clicking outside
19
+ document.addEventListener("click", (event) => {
20
+ if (
21
+ profileButton &&
22
+ userModal &&
23
+ !profileButton.contains(event.target) &&
24
+ !userModal.contains(event.target)
25
+ ) {
26
+ userModal.style.display = "none";
27
+ isModalOpen = false;
28
+ }
29
+ });
30
+ }
14
31
 
15
- // Close modal when clicking outside
16
- document.addEventListener("click", (event) => {
17
- if (
18
- !profileButton.contains(event.target) &&
19
- !userModal.contains(event.target)
20
- ) {
21
- userModal.style.display = "none";
22
- isModalOpen = false;
23
- }
24
- });
25
32
  // Get the modal elements
26
- const modal = document.getElementById("sideModal");
27
- const modalOverlay = document.getElementById("modalOverlay");
33
+ const sideModal = document.getElementById("sideModal");
34
+ const modalOverlayy = document.getElementById("modalOverlay");
28
35
  const openModalBtn = document.querySelector(".open-modal-btn");
29
36
  const closeModalBtn = document.querySelector(".close-modal-btn");
30
37
 
31
38
  // Function to open the modal
32
39
  function openModal() {
33
- modalOverlay.style.display = "block";
34
- // Slight delay for the overlay to appear before the modal slides in
35
- setTimeout(() => {
36
- modal.style.right = "0";
37
- }, 50);
40
+ if (modalOverlayy && sideModal) {
41
+ modalOverlayy.style.display = "block";
42
+ // Slight delay for the overlay to appear before the modal slides in
43
+ setTimeout(() => {
44
+ sideModal.style.right = "0";
45
+ }, 50);
46
+ }
38
47
  }
39
48
 
40
49
  // Function to close the modal
41
50
  function closeModal() {
42
- modal.style.right = "-90%";
43
- // Wait for the animation to complete before hiding the overlay
44
- setTimeout(() => {
45
- modalOverlay.style.display = "none";
46
- }, 300);
51
+ if (sideModal && modalOverlayy) {
52
+ sideModal.style.right = "-90%";
53
+ // Wait for the animation to complete before hiding the overlay
54
+ setTimeout(() => {
55
+ modalOverlayy.style.display = "none";
56
+ }, 300);
57
+ }
47
58
  }
48
59
 
49
60
  // Event listeners
50
- openModalBtn.addEventListener("click", openModal);
51
- closeModalBtn.addEventListener("click", closeModal);
52
- modalOverlay.addEventListener("click", closeModal);
61
+ if (openModalBtn) {
62
+ openModalBtn.addEventListener("click", openModal);
63
+ }
64
+
65
+ if (closeModalBtn) {
66
+ closeModalBtn.addEventListener("click", closeModal);
67
+ }
68
+
69
+ if (modalOverlayy) {
70
+ modalOverlayy.addEventListener("click", closeModal);
71
+ }
53
72
 
54
73
  // Prevent closing when clicking inside the modal
55
- modal.addEventListener("click", function (event) {
56
- event.stopPropagation();
57
- });
58
- if (window.location.pathname === "/profile") {
74
+ if (sideModal) {
75
+ sideModal.addEventListener("click", function (event) {
76
+ event.stopPropagation();
77
+ });
78
+ }
79
+
80
+ if (
81
+ window.location.pathname === "/profile" &&
82
+ document.querySelector(".login-button")
83
+ ) {
59
84
  document.querySelector(".login-button").addEventListener("click", openModal);
60
85
  }
61
86
 
62
- // Firebase configuration - Replace with your own Firebase config
87
+ // Firebase configuration
88
+ let firebaseConfig;
89
+
90
+ async function loadFirebaseConfig() {
91
+ try {
92
+ // Try to get config from Netlify function
93
+ const hostname = window.location.hostname;
94
+ const port = window.location.port;
95
+
96
+ let baseUrl = "";
97
+
98
+ // Development environment detection
99
+ if (hostname === "localhost" || hostname === "127.0.0.1") {
100
+ // When running locally, we need to specify which port the Netlify Functions are running on
101
+ // Default Netlify CLI functions port is 8888, but could be 9000 or custom
102
+ baseUrl = "http://localhost:9000"; // Adjust this if your Netlify Functions are on a different port
103
+ }
104
+
105
+ // Make the request to the Netlify function with credentials included
106
+
107
+ const response = await fetch(
108
+ `http://localhost:9000/.netlify/functions/get-firebase-config`
109
+ );
110
+
111
+ if (response.ok) {
112
+ firebaseConfig = await response.json();
113
+
114
+ // Check if we got all required config fields
115
+ if (
116
+ firebaseConfig.apiKey &&
117
+ firebaseConfig.authDomain &&
118
+ firebaseConfig.projectId
119
+ ) {
120
+ // Initialize Firebase with the config
121
+ if (typeof firebase !== "undefined") {
122
+ initializeFirebase();
123
+ } else {
124
+ console.error("Firebase SDK not loaded");
125
+ }
126
+ } else {
127
+ console.error("Incomplete Firebase configuration received");
128
+ }
129
+ } else {
130
+ console.error("Failed to load Firebase config:", response.status);
131
+ }
132
+ } catch (error) {
133
+ console.log(error);
134
+ console.error("Error loading Firebase config:", error);
135
+ }
136
+ }
137
+
138
+ function initializeFirebase() {
139
+ if (!firebase.apps.length) {
140
+ firebase.initializeApp(firebaseConfig);
63
141
 
64
- // Initialize Firebase
65
- firebase.initializeApp(firebaseConfig);
66
- const auth = firebase.auth();
142
+ setupAuthListeners();
143
+ }
144
+ }
145
+
146
+ function setupAuthListeners() {
147
+ const auth = firebase.auth();
67
148
 
68
- // Check for redirect result immediately when page loads
69
- document.addEventListener("DOMContentLoaded", function () {
70
- console.log("Checking for auth redirect...");
71
149
  auth
72
150
  .getRedirectResult()
73
151
  .then((result) => {
74
152
  if (result && result.user) {
75
- console.log("Redirect authentication successful:", result.user);
76
153
  // Twitter or other redirect login was successful
77
154
  // Auth state observer will handle the UI update
78
155
  } else if (result) {
79
- console.log("Redirect completed but no user");
80
156
  }
81
157
  })
82
158
  .catch((error) => {
@@ -85,269 +161,388 @@ document.addEventListener("DOMContentLoaded", function () {
85
161
  alert(`Authentication error: ${error.message}`);
86
162
  }
87
163
  });
88
- });
89
164
 
90
- // DOM Elements
91
- const loginForm = document.getElementById("loginForm");
92
- const signupForm = document.getElementById("signupForm");
93
- const forgotPasswordForm = document.getElementById("forgotPasswordForm");
94
- const authContainer = document.getElementById("authContainer");
95
- const userAvatar = document.getElementById("userAvatar");
96
- const profileUserAvatar = document.querySelector(".profile-user-avatar");
97
-
98
- // Switch between login and signup
99
- document.getElementById("showSignup").addEventListener("click", (e) => {
100
- e.preventDefault();
101
- loginForm.style.display = "none";
102
- signupForm.style.display = "block";
103
- forgotPasswordForm.style.display = "none";
104
- });
105
-
106
- document.getElementById("showLogin").addEventListener("click", (e) => {
107
- e.preventDefault();
108
- signupForm.style.display = "none";
109
- loginForm.style.display = "block";
110
- forgotPasswordForm.style.display = "none";
111
- });
165
+ // DOM Elements
166
+ const loginForm = document.getElementById("loginForm");
167
+ const signupForm = document.getElementById("signupForm");
168
+ const forgotPasswordForm = document.getElementById("forgotPasswordForm");
169
+ const userAvatar = document.getElementById("userAvatar");
170
+ const profileUserAvatar = document.querySelector(".profile-user-avatar");
171
+
172
+ // Switch between login and signup
173
+ const showSignupBtn = document.getElementById("showSignup");
174
+ if (showSignupBtn) {
175
+ showSignupBtn.addEventListener("click", (e) => {
176
+ e.preventDefault();
177
+ if (loginForm) loginForm.style.display = "none";
178
+ if (signupForm) signupForm.style.display = "block";
179
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
180
+ });
181
+ }
112
182
 
113
- // Show forgot password form
114
- document.getElementById("forgotPassword").addEventListener("click", (e) => {
115
- e.preventDefault();
116
- loginForm.style.display = "none";
117
- forgotPasswordForm.style.display = "block";
118
- });
183
+ const showLoginBtn = document.getElementById("showLogin");
184
+ if (showLoginBtn) {
185
+ showLoginBtn.addEventListener("click", (e) => {
186
+ e.preventDefault();
187
+ if (signupForm) signupForm.style.display = "none";
188
+ if (loginForm) loginForm.style.display = "block";
189
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
190
+ });
191
+ }
119
192
 
120
- // Back to login from forgot password
121
- document.getElementById("backToLogin").addEventListener("click", () => {
122
- forgotPasswordForm.style.display = "none";
123
- loginForm.style.display = "block";
124
- document.getElementById("resetSuccess").style.display = "none";
125
- });
193
+ // Show forgot password form
194
+ const forgotPasswordBtn = document.getElementById("forgotPassword");
195
+ if (forgotPasswordBtn) {
196
+ forgotPasswordBtn.addEventListener("click", (e) => {
197
+ e.preventDefault();
198
+ if (loginForm) loginForm.style.display = "none";
199
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "block";
200
+ });
201
+ }
126
202
 
127
- // Handle reset password form submission
128
- // Handle reset password form submission
129
- // Handle reset password form submission
130
- // Handle reset password form submission
131
- document.getElementById("resetPasswordForm").addEventListener("submit", (e) => {
132
- e.preventDefault();
133
- const email = document.getElementById("resetEmail").value;
203
+ // Back to login from forgot password
204
+ const backToLoginBtn = document.getElementById("backToLogin");
205
+ if (backToLoginBtn) {
206
+ backToLoginBtn.addEventListener("click", () => {
207
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
208
+ if (loginForm) loginForm.style.display = "block";
209
+ const resetSuccess = document.getElementById("resetSuccess");
210
+ if (resetSuccess) resetSuccess.style.display = "none";
211
+ });
212
+ }
134
213
 
135
- // This is the correct way to set up redirects - Firebase will handle adding the continueUrl internally
136
- const actionCodeSettings = {
137
- url: "https://pdftoolkit-develop.netlify.app/",
138
- handleCodeInApp: false,
139
- };
214
+ // Handle reset password form submission
215
+ const resetPasswordForm = document.getElementById("resetPasswordForm");
216
+ if (resetPasswordForm) {
217
+ resetPasswordForm.addEventListener("submit", (e) => {
218
+ e.preventDefault();
219
+ const resetEmail = document.getElementById("resetEmail");
220
+ if (!resetEmail) return;
221
+
222
+ const email = resetEmail.value;
223
+
224
+ // This is the correct way to set up redirects - Firebase will handle adding the continueUrl internally
225
+ const actionCodeSettings = {
226
+ url: "https://pdftoolkit-develop.netlify.app/",
227
+ handleCodeInApp: false,
228
+ };
229
+
230
+ auth
231
+ .sendPasswordResetEmail(email, actionCodeSettings)
232
+ .then(() => {
233
+ // Show success message
234
+ const resetSuccess = document.getElementById("resetSuccess");
235
+ if (resetSuccess) resetSuccess.style.display = "block";
236
+ resetPasswordForm.reset();
237
+ })
238
+ .catch((error) => {
239
+ alert(`Error: ${error.message}`);
240
+ });
241
+ });
242
+ }
140
243
 
141
- auth
142
- .sendPasswordResetEmail(email, actionCodeSettings)
143
- .then(() => {
144
- // Show success message
145
- document.getElementById("resetSuccess").style.display = "block";
146
- document.getElementById("resetPasswordForm").reset();
147
- })
148
- .catch((error) => {
149
- alert(`Error: ${error.message}`);
244
+ // Toggle password visibility
245
+ const toggleLoginPassword = document.getElementById("toggleLoginPassword");
246
+ if (toggleLoginPassword) {
247
+ toggleLoginPassword.addEventListener("click", () => {
248
+ const passwordInput = document.getElementById("loginPassword");
249
+ if (passwordInput) {
250
+ passwordInput.type =
251
+ passwordInput.type === "password" ? "text" : "password";
252
+ }
150
253
  });
151
- });
254
+ }
152
255
 
153
- // Toggle password visibility
154
- document.getElementById("toggleLoginPassword").addEventListener("click", () => {
155
- const passwordInput = document.getElementById("loginPassword");
156
- passwordInput.type = passwordInput.type === "password" ? "text" : "password";
157
- });
256
+ const toggleSignupPassword = document.getElementById("toggleSignupPassword");
257
+ if (toggleSignupPassword) {
258
+ toggleSignupPassword.addEventListener("click", () => {
259
+ const passwordInput = document.getElementById("signupPassword");
260
+ if (passwordInput) {
261
+ passwordInput.type =
262
+ passwordInput.type === "password" ? "text" : "password";
263
+ }
264
+ });
265
+ }
158
266
 
159
- document
160
- .getElementById("toggleSignupPassword")
161
- .addEventListener("click", () => {
162
- const passwordInput = document.getElementById("signupPassword");
163
- passwordInput.type =
164
- passwordInput.type === "password" ? "text" : "password";
165
- });
267
+ // Email/Password Login
268
+ const emailLoginForm = document.getElementById("emailLoginForm");
269
+ if (emailLoginForm) {
270
+ emailLoginForm.addEventListener("submit", (e) => {
271
+ e.preventDefault();
272
+ const loginEmail = document.getElementById("loginEmail");
273
+ const loginPassword = document.getElementById("loginPassword");
274
+ if (!loginEmail || !loginPassword) return;
275
+
276
+ const email = loginEmail.value;
277
+ const password = loginPassword.value;
278
+
279
+ auth
280
+ .signInWithEmailAndPassword(email, password)
281
+ .then((userCredential) => {
282
+ // Signed in
283
+ const user = userCredential.user;
284
+ })
285
+ .catch((error) => {
286
+ alert(`Login error: ${error.message}`);
287
+ });
288
+ });
289
+ }
166
290
 
167
- // Email/Password Login
168
- document.getElementById("emailLoginForm").addEventListener("submit", (e) => {
169
- e.preventDefault();
170
- const email = document.getElementById("loginEmail").value;
171
- const password = document.getElementById("loginPassword").value;
291
+ // Email/Password Signup
292
+ const emailSignupForm = document.getElementById("emailSignupForm");
293
+ if (emailSignupForm) {
294
+ emailSignupForm.addEventListener("submit", (e) => {
295
+ e.preventDefault();
296
+ const signupEmail = document.getElementById("signupEmail");
297
+ const signupPassword = document.getElementById("signupPassword");
298
+ if (!signupEmail || !signupPassword) return;
299
+
300
+ const email = signupEmail.value;
301
+ const password = signupPassword.value;
302
+
303
+ auth
304
+ .createUserWithEmailAndPassword(email, password)
305
+ .then((userCredential) => {
306
+ // Signed up
307
+ const user = userCredential.user;
308
+ })
309
+ .catch((error) => {
310
+ alert(`Signup error: ${error.message}`);
311
+ });
312
+ });
313
+ }
172
314
 
173
- auth
174
- .signInWithEmailAndPassword(email, password)
175
- .then((userCredential) => {
176
- // Signed in
177
- const user = userCredential.user;
178
- console.log("User logged in:", user);
179
- })
180
- .catch((error) => {
181
- alert(`Login error: ${error.message}`);
315
+ // Google Login
316
+ const googleLoginBtn = document.getElementById("googleLogin");
317
+ if (googleLoginBtn) {
318
+ googleLoginBtn.addEventListener("click", () => {
319
+ const provider = new firebase.auth.GoogleAuthProvider();
320
+ auth
321
+ .signInWithPopup(provider)
322
+ .then((result) => {})
323
+ .catch((error) => {
324
+ alert(`Google login error: ${error.message}`);
325
+ });
182
326
  });
183
- });
327
+ }
184
328
 
185
- // Email/Password Signup
186
- document.getElementById("emailSignupForm").addEventListener("submit", (e) => {
187
- e.preventDefault();
188
- const email = document.getElementById("signupEmail").value;
189
- const password = document.getElementById("signupPassword").value;
329
+ const googleSignupBtn = document.getElementById("googleSignup");
330
+ if (googleSignupBtn) {
331
+ googleSignupBtn.addEventListener("click", () => {
332
+ const provider = new firebase.auth.GoogleAuthProvider();
333
+ auth
334
+ .signInWithPopup(provider)
335
+ .then((result) => {})
336
+ .catch((error) => {
337
+ alert(`Google signup error: ${error.message}`);
338
+ });
339
+ });
340
+ }
190
341
 
191
- auth
192
- .createUserWithEmailAndPassword(email, password)
193
- .then((userCredential) => {
194
- // Signed up
195
- const user = userCredential.user;
196
- console.log("User created:", user);
197
- })
198
- .catch((error) => {
199
- alert(`Signup error: ${error.message}`);
342
+ // Facebook Login
343
+ const facebookLoginBtn = document.getElementById("facebookLogin");
344
+ if (facebookLoginBtn) {
345
+ facebookLoginBtn.addEventListener("click", () => {
346
+ const provider = new firebase.auth.FacebookAuthProvider();
347
+ provider.addScope("email");
348
+
349
+ // Try popup instead of redirect for Facebook
350
+ auth
351
+ .signInWithPopup(provider)
352
+ .then((result) => {})
353
+ .catch((error) => {
354
+ console.error("Facebook login error:", error);
355
+ alert(`Facebook login error: ${error.message}`);
356
+ });
200
357
  });
201
- });
358
+ }
202
359
 
203
- // Google Login
204
- document.getElementById("googleLogin").addEventListener("click", () => {
205
- const provider = new firebase.auth.GoogleAuthProvider();
206
- auth
207
- .signInWithPopup(provider)
208
- .then((result) => {
209
- console.log("Google login successful");
210
- })
211
- .catch((error) => {
212
- alert(`Google login error: ${error.message}`);
360
+ // Twitter Login - Try using popup method first
361
+ const twitterLoginBtn = document.getElementById("twitterLogin");
362
+ if (twitterLoginBtn) {
363
+ twitterLoginBtn.addEventListener("click", () => {
364
+ const provider = new firebase.auth.TwitterAuthProvider();
365
+
366
+ try {
367
+ // Try popup method first as it provides better error feedback
368
+ auth
369
+ .signInWithPopup(provider)
370
+ .then((result) => {})
371
+ .catch((error) => {
372
+ console.error("Twitter popup error:", error);
373
+
374
+ // If popup fails, fallback to redirect
375
+ if (
376
+ error.code === "auth/popup-blocked" ||
377
+ error.code === "auth/popup-closed-by-user"
378
+ ) {
379
+ auth.signInWithRedirect(provider).catch((redirectError) => {
380
+ console.error("Twitter redirect error:", redirectError);
381
+ alert(`Twitter login error: ${redirectError.message}`);
382
+ });
383
+ } else {
384
+ alert(`Twitter login error: ${error.message}`);
385
+ }
386
+ });
387
+ } catch (e) {
388
+ console.error("Exception during Twitter login:", e);
389
+ }
213
390
  });
214
- });
391
+ }
215
392
 
216
- document.getElementById("googleSignup").addEventListener("click", () => {
217
- const provider = new firebase.auth.GoogleAuthProvider();
218
- auth
219
- .signInWithPopup(provider)
220
- .then((result) => {
221
- console.log(result);
222
- console.log("Google signup successful");
223
- })
224
- .catch((error) => {
225
- alert(`Google signup error: ${error.message}`);
393
+ // Logout
394
+ const logoutBtn = document.getElementById("logoutBtn");
395
+ if (logoutBtn) {
396
+ logoutBtn.addEventListener("click", () => {
397
+ auth
398
+ .signOut()
399
+ .then(() => {
400
+ const userProfileHeader = document.querySelector(
401
+ ".user-profile-header"
402
+ );
403
+ if (userProfileHeader) userProfileHeader.style.display = "none";
404
+ window.location.reload();
405
+ })
406
+ .catch((error) => {
407
+ alert(`Logout error: ${error.message}`);
408
+ });
226
409
  });
227
- });
410
+ }
228
411
 
229
- // Facebook Login
230
- document.getElementById("facebookLogin").addEventListener("click", () => {
231
- const provider = new firebase.auth.FacebookAuthProvider();
232
- provider.addScope("email");
412
+ // Auth state observer
413
+ auth.onAuthStateChanged((user) => {
414
+ if (user) {
415
+ const email = user.email || "No email available";
416
+ const loggedInUserEmail = document.querySelector(".logged-in-user-email");
417
+ if (loggedInUserEmail) loggedInUserEmail.textContent = email;
418
+
419
+ let displayName =
420
+ user.displayName || (user.email ? user.email.split("@")[0] : "User");
421
+
422
+ // Special handling for Twitter users who might not have email
423
+ if (
424
+ user.providerData[0].providerId === "twitter.com" &&
425
+ !user.displayName
426
+ ) {
427
+ displayName = user.providerData[0].uid;
428
+ }
233
429
 
234
- // Try popup instead of redirect for Facebook
235
- auth
236
- .signInWithPopup(provider)
237
- .then((result) => {
238
- console.log("Facebook login successful");
239
- })
240
- .catch((error) => {
241
- console.error("Facebook login error:", error);
242
- alert(`Facebook login error: ${error.message}`);
243
- });
244
- });
430
+ if (sideModal) {
431
+ sideModal.style.display = "none";
432
+ sideModal.style.right = "-90%";
433
+ }
245
434
 
246
- // Twitter Login - Try using popup method first
247
- document.getElementById("twitterLogin").addEventListener("click", () => {
248
- console.log("Starting Twitter login...");
249
- const provider = new firebase.auth.TwitterAuthProvider();
435
+ if (modalOverlayy) {
436
+ modalOverlayy.style.display = "none";
437
+ }
250
438
 
251
- try {
252
- // Try popup method first as it provides better error feedback
253
- auth
254
- .signInWithPopup(provider)
255
- .then((result) => {
256
- console.log("Twitter login successful via popup");
257
- })
258
- .catch((error) => {
259
- console.error("Twitter popup error:", error);
260
-
261
- // If popup fails, fallback to redirect
262
- if (
263
- error.code === "auth/popup-blocked" ||
264
- error.code === "auth/popup-closed-by-user"
265
- ) {
266
- console.log("Popup blocked, trying redirect instead");
267
- auth.signInWithRedirect(provider).catch((redirectError) => {
268
- console.error("Twitter redirect error:", redirectError);
269
- alert(`Twitter login error: ${redirectError.message}`);
270
- });
271
- } else {
272
- alert(`Twitter login error: ${error.message}`);
273
- }
274
- });
275
- } catch (e) {
276
- console.error("Exception during Twitter login:", e);
277
- }
278
- });
439
+ const loggedInUsername = document.querySelector(".logged-in-username");
440
+ if (loggedInUsername) loggedInUsername.textContent = displayName;
279
441
 
280
- // Logout
281
- document.getElementById("logoutBtn").addEventListener("click", () => {
282
- auth
283
- .signOut()
284
- .then(() => {
285
- document.querySelector(".user-profile-header").style.display = "none";
286
- window.location.reload();
287
- console.log("User signed out");
288
- })
289
- .catch((error) => {
290
- alert(`Logout error: ${error.message}`);
291
- });
292
- });
442
+ const loginModalButton = document.querySelector(".login-modal-button");
443
+ if (loginModalButton) loginModalButton.style.display = "none";
293
444
 
294
- // Auth state observer
295
- auth.onAuthStateChanged((user) => {
296
- console.log(
297
- "Auth state changed:",
298
- user ? "User logged in" : "User logged out"
299
- );
445
+ // Set initials for avatar
446
+ const initials = displayName
447
+ .split(" ")
448
+ .map((n) => n[0])
449
+ .join("")
450
+ .toUpperCase()
451
+ .substring(0, 2);
300
452
 
301
- if (user) {
302
- console.log(user);
453
+ if (profileButton) profileButton.textContent = initials;
454
+ if (profileUserAvatar) profileUserAvatar.textContent = initials;
303
455
 
304
- const email = user.email || "No email available";
305
- document.querySelector(".logged-in-user-email").textContent = email;
306
- let displayName =
307
- user.displayName || (user.email ? user.email.split("@")[0] : "User");
456
+ const userProfileHeader = document.querySelector(".user-profile-header");
457
+ if (userProfileHeader) userProfileHeader.style.display = "block";
308
458
 
309
- // Special handling for Twitter users who might not have email
310
- if (
311
- user.providerData[0].providerId === "twitter.com" &&
312
- !user.displayName
313
- ) {
314
- displayName = user.providerData[0].uid;
459
+ if (userAvatar) {
460
+ userAvatar.textContent = initials;
461
+ userAvatar.style.display = "flex";
462
+ }
463
+
464
+ if (window.location.pathname === "/profile") {
465
+ const userProfileSection = document.querySelector(
466
+ ".user-profile-section"
467
+ );
468
+ if (userProfileSection) userProfileSection.style.display = "flex";
469
+
470
+ const profileLoginContainer = document.querySelector(
471
+ ".profile-login-container"
472
+ );
473
+ if (profileLoginContainer) profileLoginContainer.style.display = "none";
474
+
475
+ const avatarLarge = document.querySelector(".avatar-large");
476
+ if (avatarLarge) avatarLarge.textContent = initials;
477
+
478
+ const userEmailInput = document.querySelector("#user-email-input");
479
+ if (userEmailInput) userEmailInput.value = email;
480
+
481
+ const usernameInput = document.querySelector(".username-input");
482
+ if (usernameInput) usernameInput.value = displayName;
483
+ }
484
+ } else {
485
+ if (userAvatar) userAvatar.style.display = "none";
486
+ if (loginForm) loginForm.style.display = "block";
487
+ if (signupForm) signupForm.style.display = "none";
488
+ if (forgotPasswordForm) forgotPasswordForm.style.display = "none";
315
489
  }
490
+ });
491
+ const OPERATION_LIMIT = "{{ site.OPERATION_LIMIT }}"; // Set based on site config
492
+ const STORAGE_KEY = "user_operations";
316
493
 
317
- console.log("Provider:", user.providerData[0].providerId);
318
- console.log("Display name:", displayName);
319
- modal.style.display = "none";
320
- modal.style.right = "-90%";
321
- modalOverlay.style.display = "none";
322
- document.querySelector(".logged-in-username").textContent = displayName;
323
- document.querySelector(".login-modal-button").style.display = "none";
324
-
325
- // Set initials for avatar
326
- const initials = displayName
327
- .split(" ")
328
- .map((n) => n[0])
329
- .join("")
330
- .toUpperCase()
331
- .substring(0, 2);
332
- document.getElementById("profileButton").textContent = initials;
333
- profileUserAvatar.textContent = initials;
334
- document.querySelector(".user-profile-header").style.display = "block";
335
-
336
- userAvatar.textContent = initials;
337
- userAvatar.style.display = "flex";
338
- if (window.location.pathname === "/profile") {
339
- document.querySelector(".user-profile-section").style.display = "flex";
340
- document.querySelector(".profile-login-container").style.display = "none";
341
- document.querySelector(".avatar-large").textContent = initials;
342
- document.querySelector("#user-email-input").value = email;
343
- document.querySelector(".username-input").value = displayName;
344
-
345
- console.log("You are on the profile page.");
494
+ function getOperationCount() {
495
+ const storedCount = localStorage.getItem(STORAGE_KEY);
496
+ return storedCount ? parseInt(storedCount, 10) : 0;
497
+ }
498
+
499
+ function incrementOperationCount() {
500
+ let currentCount = getOperationCount();
501
+
502
+ if (currentCount >= OPERATION_LIMIT) {
503
+ showSignupPopup();
504
+ return false; // Prevent further uploads
346
505
  }
347
- } else {
348
- userAvatar.style.display = "none";
349
- loginForm.style.display = "block";
350
- signupForm.style.display = "none";
351
- forgotPasswordForm.style.display = "none";
352
- }
506
+
507
+ localStorage.setItem(STORAGE_KEY, currentCount + 1);
508
+ return true;
509
+ }
510
+
511
+ function showSignupPopup() {
512
+ auth.onAuthStateChanged((user) => {
513
+ if (user) {
514
+ console.log(user);
515
+ }
516
+ else{
517
+ openModal()
518
+ document.querySelector('.close-modal-btn').style.display="none"
519
+ }
520
+ })
521
+
522
+ }
523
+
524
+ function hideSignupPopup() {
525
+ closeModal()
526
+ }
527
+
528
+
529
+
530
+ // Attach event listener to all file inputs
531
+ document.querySelectorAll("input[type='file']").forEach(input => {
532
+ input.addEventListener("change", function () {
533
+ if (incrementOperationCount()) {
534
+ console.log("File uploaded in:", this);
535
+ } else {
536
+ this.value = ""; // Reset the input field
537
+ }
538
+ });
353
539
  });
540
+ }
541
+
542
+ // Initialize the app
543
+ if (document.readyState === "loading") {
544
+ document.addEventListener("DOMContentLoaded", loadFirebaseConfig);
545
+ } else {
546
+ loadFirebaseConfig();
547
+ }
548
+