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.
- checksums.yaml +4 -4
- data/_includes/.DS_Store +0 -0
- data/_includes/appscms/.DS_Store +0 -0
- data/_includes/appscms/extras/ratings.html +196 -24
- data/_includes/appscms/scripts/script.html +2 -1
- data/assets/.DS_Store +0 -0
- data/assets/css/appscms-theme.css +267 -3
- data/assets/js/appscms-login.js +476 -281
- data/assets/js/userUsageCount.js +0 -0
- metadata +3 -3
- data/assets/js/appscms-auth.js.liquid +0 -9
data/assets/js/appscms-login.js
CHANGED
@@ -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
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
27
|
-
const
|
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
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
51
|
-
|
52
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
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
|
-
|
65
|
-
|
66
|
-
|
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
|
95
|
-
const
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
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
|
-
//
|
121
|
-
document.getElementById("
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|
-
//
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
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
|
-
//
|
136
|
-
const
|
137
|
-
|
138
|
-
|
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
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
document.getElementById("
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
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
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
-
|
160
|
-
.getElementById("
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
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
|
168
|
-
document.getElementById("
|
169
|
-
|
170
|
-
|
171
|
-
|
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
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
const
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
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
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
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
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
const
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
-
//
|
204
|
-
document.getElementById("
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
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
|
-
|
217
|
-
const
|
218
|
-
|
219
|
-
.
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
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
|
-
//
|
230
|
-
|
231
|
-
|
232
|
-
|
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
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
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
|
-
|
247
|
-
|
248
|
-
|
249
|
-
const provider = new firebase.auth.TwitterAuthProvider();
|
435
|
+
if (modalOverlayy) {
|
436
|
+
modalOverlayy.style.display = "none";
|
437
|
+
}
|
250
438
|
|
251
|
-
|
252
|
-
|
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
|
-
|
281
|
-
|
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
|
-
//
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
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
|
-
|
302
|
-
|
453
|
+
if (profileButton) profileButton.textContent = initials;
|
454
|
+
if (profileUserAvatar) profileUserAvatar.textContent = initials;
|
303
455
|
|
304
|
-
|
305
|
-
|
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
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
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
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
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
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
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
|
+
|