@moneybar.online/moneybar 5.0.0 → 5.0.1

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.
Files changed (3) hide show
  1. package/package.json +1 -2
  2. package/src/index.ts +0 -3428
  3. package/src/types.ts +0 -180
package/src/index.ts DELETED
@@ -1,3428 +0,0 @@
1
- import { MoneyBarConfig, DownloadStatus, MoneyBarEvents, UserContext } from './types.js';
2
- import { createClient } from '@supabase/supabase-js';
3
-
4
- /**
5
- * MoneyBar - The navbar of monetization
6
- *
7
- * Fix the 3 money-blocking stages that stop revenue:
8
- * 1. Forced sign-ins before value → Value-first trials
9
- * 2. Silent drop-offs → Exit feedback capture
10
- * 3. Broken payment flows → Seamless Google Auth + payments
11
- *
12
- * Features:
13
- * - Server-side usage tracking (incognito-proof)
14
- * - Google OAuth authentication
15
- * - Payment integration with DodoPayments
16
- * - User feedback collection
17
- * - Automatic UI management (paywall, auth, status)
18
- * - User context for personalization
19
- *
20
- * @example Simple Usage (Recommended):
21
- * ```javascript
22
- * import { MoneyBar } from '@moneybar.online/moneybar';
23
- *
24
- * const moneyBar = new MoneyBar({
25
- * appId: 'my-pdf-app',
26
- * freeAttemptLimit: 3,
27
- * supabase: { url: 'https://xyz.supabase.co', anonKey: 'anon_key' },
28
- * payment: { productId: 'prod_xyz' }
29
- * });
30
- *
31
- * // Single button - handles all monetization automatically
32
- * moneyBar.attachToButton('#action-btn', (userContext) => {
33
- * // Your action logic here - with user context for personalization
34
- * if (userContext.isPremium) {
35
- * generatePremiumPDF();
36
- * } else {
37
- * generateBasicPDF();
38
- * }
39
- * });
40
- * ```
41
- *
42
- * @example Multiple Buttons:
43
- * ```javascript
44
- * moneyBar.attachToButtons({
45
- * buttons: [
46
- * {
47
- * selector: '#free-btn',
48
- * downloadCallback: (ctx) => downloadFreeTemplate(ctx),
49
- * isPremium: false
50
- * },
51
- * {
52
- * selector: '#premium-btn',
53
- * downloadCallback: (ctx) => downloadPremiumTemplate(ctx),
54
- * isPremium: true
55
- * }
56
- * ]
57
- * });
58
- * ```
59
- */
60
- export class MoneyBar {
61
- private config: MoneyBarConfig;
62
- private supabase: any;
63
- private currentUser: any = null;
64
- private userFingerprint: string | null = null;
65
- private eventListeners: Map<keyof MoneyBarEvents, Function[]> = new Map();
66
- private supabaseConnectionFailed: boolean = false;
67
- private paymentConnectionFailed: boolean = false;
68
- private securityKeyFailed: boolean = false; // Track security key validation failures
69
- private isLoadingStatus: boolean = false; // Track if we're currently loading status from backend
70
- private cachedStatus: DownloadStatus | null = null;
71
- private statusCacheTime: number = 0;
72
- private readonly STATUS_CACHE_DURATION = 5000; // 5 seconds cache
73
- private initializationPromise: Promise<DownloadStatus> | null = null;
74
- private cachedPremiumStatus: boolean | null = null;
75
- private premiumStatusCacheTime: number = 0;
76
-
77
- private mergeConfigs(config?: MoneyBarConfig): MoneyBarConfig {
78
- // Try to get config from window.APP_CONFIG
79
- const windowConfig = typeof window !== 'undefined' ? (window as any).APP_CONFIG : null;
80
-
81
- if (!config && !windowConfig) {
82
- throw new Error('MoneyBar: No configuration provided. Either pass config to constructor or set window.APP_CONFIG');
83
- }
84
-
85
- // If no constructor config provided, use window config entirely
86
- if (!config) {
87
- return windowConfig as MoneyBarConfig;
88
- }
89
-
90
- // If no window config, use constructor config entirely
91
- if (!windowConfig) {
92
- return config;
93
- }
94
-
95
- // Merge configs: constructor config takes precedence over window config
96
- return {
97
- ...windowConfig,
98
- ...config
99
- } as MoneyBarConfig;
100
- }
101
-
102
- constructor(config?: MoneyBarConfig) {
103
- // Auto-load from window.APP_CONFIG if no config provided, or merge configs
104
- this.config = this.mergeConfigs(config);
105
- if (this.config.options?.debug) {
106
- // console.log('🔍 DEBUG: MoneyBar constructor - full config:', JSON.stringify(config, null, 2));
107
- // console.log('🔍 DEBUG: Email config present:', !!config.email);
108
- }
109
- this.validateConfig();
110
- this.initializeSupabase();
111
- this.initializePayment();
112
- this.initializeFingerprint();
113
- this.setupAuthListener();
114
- this.checkPaymentStatus();
115
- }
116
-
117
- /**
118
- * Main method to handle download attempts
119
- * Call this from your download button's click handler
120
- */
121
- public async handleDownload(): Promise<void> {
122
- try {
123
- // Security check: if security key validation failed
124
- if (this.securityKeyFailed) {
125
- this.showError(
126
- 'Invalid Security Key',
127
- 'Your security key is invalid, expired, or not found. Please check your MoneyBar configuration and ensure you have a valid security_key.'
128
- );
129
- return;
130
- }
131
-
132
- // Security check: if Supabase connection failed, disable downloads to prevent localStorage bypass
133
- if (this.supabaseConnectionFailed) {
134
- this.config.callbacks?.onError?.(new Error('Server connection required for download verification. Please check your configuration.'));
135
- return;
136
- }
137
-
138
- // Security check: if payment configuration is invalid, disable downloads
139
- if (this.config.payment && this.paymentConnectionFailed) {
140
- this.config.callbacks?.onError?.(new Error('Payment configuration error. Please contact support.'));
141
- return;
142
- }
143
-
144
- // Check if user is premium first (if authenticated)
145
- if (this.currentUser) {
146
- const isPremium = await this.checkPremiumStatus(this.currentUser.email);
147
- if (isPremium) {
148
- this.config.callbacks?.onPremiumDownload();
149
- return;
150
- }
151
- }
152
-
153
- // Check usage limits (works for both authenticated and anonymous users)
154
- const status = await this.getDownloadStatus();
155
-
156
- if (status.currentCount >= status.limit) {
157
- // Limit reached - show paywall/limit message
158
- this.config.callbacks?.onLimitReached(status.currentCount, status.limit);
159
- return;
160
- }
161
-
162
- // Increment counter and proceed with action
163
- await this.incrementDownloadCount();
164
- this.config.callbacks?.onDownloadAllowed();
165
-
166
- // Invalidate cache since count changed
167
- this.cachedStatus = null;
168
-
169
- // Check if limit reached after increment
170
- const newStatus = await this.getDownloadStatus();
171
- this.emit('countChanged', { count: newStatus.currentCount, limit: newStatus.limit });
172
-
173
- if (newStatus.currentCount >= newStatus.limit) {
174
- // Show paywall for next time
175
- setTimeout(() => {
176
- this.config.callbacks?.onLimitReached(newStatus.currentCount, newStatus.limit);
177
- }, 100);
178
- }
179
-
180
- } catch (error) {
181
- this.handleError(error as Error);
182
- }
183
- }
184
-
185
- /**
186
- * Get current download status for the user
187
- */
188
- public async getDownloadStatus(forceRefresh: boolean = false): Promise<DownloadStatus> {
189
- // console.log(`🔍 [INIT] getDownloadStatus called (forceRefresh: ${forceRefresh}) at ${new Date().toISOString()}`);
190
-
191
- // Check if we can use cached status
192
- const cacheAge = this.cachedStatus ? Date.now() - this.statusCacheTime : -1;
193
- const canUseCache = !forceRefresh && this.cachedStatus && cacheAge < this.STATUS_CACHE_DURATION;
194
-
195
- if (canUseCache) {
196
- // console.log(`🔍 [INIT] Using cached status (age: ${cacheAge}ms)`);
197
- return this.cachedStatus!;
198
- }
199
-
200
- // If there's already an initialization in progress and it's not forced refresh, wait for it
201
- if (!forceRefresh && this.initializationPromise) {
202
- // console.log(`🔍 [INIT] Waiting for existing initialization promise`);
203
- return await this.initializationPromise;
204
- }
205
-
206
- // console.log(`🔍 [INIT] Starting new status fetch (cache age: ${cacheAge}ms)`);
207
-
208
- // Create the initialization promise
209
- this.initializationPromise = this.fetchFreshStatus(forceRefresh);
210
-
211
- try {
212
- const result = await this.initializationPromise;
213
- // console.log(`🔍 [INIT] Status fetch completed successfully`);
214
- return result;
215
- } finally {
216
- // Clear the promise after completion
217
- this.initializationPromise = null;
218
- }
219
- }
220
-
221
- private async fetchFreshStatus(forceRefresh: boolean): Promise<DownloadStatus> {
222
- try {
223
- let count = 0;
224
- let isPremium = false;
225
-
226
- // Only call API if we really need fresh data
227
- if (forceRefresh || !this.cachedStatus) {
228
- // Get download count only if we don't have it cached
229
- count = await this.getDownloadCount();
230
-
231
- // CRITICAL: Check if security key validation failed
232
- // Don't proceed with normal status if there's a security error
233
- if (this.securityKeyFailed) {
234
- // Return a minimal error status
235
- return {
236
- currentCount: 0,
237
- limit: this.config.freeAttemptLimit,
238
- isPremium: false,
239
- isAuthenticated: false,
240
- remaining: 0
241
- };
242
- }
243
- } else {
244
- // Use cached count if available to avoid unnecessary API call
245
- count = this.cachedStatus.currentCount;
246
- }
247
-
248
- // Check premium status only for authenticated users, and only when needed
249
- if (this.currentUser) {
250
- const premiumCacheValid = this.cachedPremiumStatus !== null && (Date.now() - this.premiumStatusCacheTime) < this.STATUS_CACHE_DURATION;
251
-
252
- if (forceRefresh || !premiumCacheValid) {
253
- isPremium = await this.checkPremiumStatus(this.currentUser.email);
254
- // Update cache
255
- this.cachedPremiumStatus = isPremium;
256
- this.premiumStatusCacheTime = Date.now();
257
- } else {
258
- // Use cached premium status to avoid unnecessary API call
259
- isPremium = this.cachedPremiumStatus!; // We know it's not null because premiumCacheValid is true
260
- console.log(`🔍 [CACHE] Using cached premium status from getDownloadStatus: ${isPremium}`);
261
- }
262
- } else {
263
- // Unauthenticated users cannot be premium
264
- isPremium = false;
265
- }
266
-
267
- const status: DownloadStatus = {
268
- currentCount: count,
269
- limit: this.config.freeAttemptLimit,
270
- isPremium,
271
- isAuthenticated: !!this.currentUser,
272
- remaining: Math.max(0, this.config.freeAttemptLimit - count)
273
- };
274
-
275
- // Cache the status
276
- this.cachedStatus = status;
277
- this.statusCacheTime = Date.now();
278
-
279
- return status;
280
- } catch (error) {
281
- this.handleError(error as Error);
282
- // Return safe defaults on error
283
- const errorStatus: DownloadStatus = {
284
- currentCount: 0,
285
- limit: this.config.freeAttemptLimit,
286
- isPremium: false,
287
- isAuthenticated: false,
288
- remaining: this.config.freeAttemptLimit
289
- };
290
-
291
- // Cache error status for short time to avoid repeated failures
292
- this.cachedStatus = errorStatus;
293
- this.statusCacheTime = Date.now();
294
-
295
- return errorStatus;
296
- }
297
- }
298
-
299
- /**
300
- * Creates a UserContext object with current user information
301
- */
302
- private async getUserContext(): Promise<UserContext> {
303
- const status = await this.getDownloadStatus();
304
-
305
- return {
306
- isPremium: status.isPremium,
307
- isAuthenticated: status.isAuthenticated,
308
- email: this.currentUser?.email,
309
- name: this.currentUser?.user_metadata?.full_name || this.currentUser?.user_metadata?.name,
310
- currentCount: status.currentCount,
311
- remaining: status.remaining,
312
- limit: status.limit,
313
- user: this.currentUser
314
- };
315
- }
316
-
317
- /**
318
- * Manually trigger Google sign-in
319
- */
320
- public async signIn(): Promise<void> {
321
- try {
322
- const { error } = await this.supabase.auth.signInWithOAuth({
323
- provider: 'google',
324
- options: {
325
- redirectTo: `${window.location.origin}${window.location.pathname}`
326
- }
327
- });
328
- if (error) throw error;
329
- } catch (error) {
330
- this.handleError(error as Error);
331
- }
332
- }
333
-
334
- /**
335
- * Sign out current user
336
- */
337
- public async signOut(): Promise<void> {
338
- try {
339
- await this.supabase.auth.signOut();
340
- this.currentUser = null;
341
- this.emit('authChanged', { user: null, isPremium: false });
342
- } catch (error) {
343
- this.handleError(error as Error);
344
- }
345
- }
346
-
347
- /**
348
- * Create payment for premium upgrade
349
- */
350
- public async createPayment(): Promise<{ checkout_url: string } | null> {
351
- if (!this.currentUser) {
352
- throw new Error('User must be signed in to create payment');
353
- }
354
-
355
- if (!this.config.payment) {
356
- throw new Error('Payment configuration not provided');
357
- }
358
-
359
- const payment = this.config.payment?.find(p => p.provider === 'dodo');
360
- if (!payment) {
361
- throw new Error('No dodo payment provider configured');
362
- }
363
-
364
- const requestBody = {
365
- email: this.currentUser.email,
366
- product_id: payment.productId,
367
- mode: payment.mode || 'test',
368
- app_id: this.config.appId,
369
- return_url: `${window.location.origin}${window.location.pathname}?payment=success`
370
- };
371
-
372
- console.log(`🔥 [PAYMENT API] createPayment called for provider: ${payment.provider}, email: ${this.currentUser.email} | Time: ${new Date().toISOString()}`);
373
-
374
- try {
375
- // Route to appropriate payment API based on provider
376
- let response;
377
- if (payment.provider === 'dodo') {
378
- response = await fetch(`${this.config.supabase.url}/functions/v1/create-payment`, {
379
- method: 'POST',
380
- headers: {
381
- 'Content-Type': 'application/json',
382
- 'Authorization': `Bearer ${this.config.supabase.anonKey}`
383
- },
384
- body: JSON.stringify(requestBody)
385
- });
386
- } else {
387
- throw new Error(`Payment provider '${payment.provider}' is not yet supported`);
388
- }
389
- console.log(`🔥 [PAYMENT API] createPayment response for ${payment.provider}: ${response.status}`);
390
-
391
- if (this.config.options?.debug) {
392
- //console.log('🔍 DEBUG: createPayment response status:', response.status);
393
- }
394
-
395
- if (!response.ok) {
396
- const errorText = await response.text();
397
- if (this.config.options?.debug) {
398
- console.error('🔍 DEBUG: createPayment error response:', errorText);
399
- }
400
-
401
- let errorData;
402
- try {
403
- errorData = JSON.parse(errorText);
404
- } catch {
405
- errorData = { error: errorText };
406
- }
407
-
408
- // Check if this is a product ID error (invalid config)
409
- if (errorText.includes('404') || errorText.includes('could not be found')) {
410
- this.paymentConnectionFailed = true;
411
- if (this.config.options?.debug) {
412
- console.warn('Invalid payment product ID detected, disabling downloads');
413
- }
414
- // Update UI to show disabled state
415
- this.updateStatusDisplays();
416
- }
417
-
418
- throw new Error(errorData.error || 'Payment creation failed');
419
- }
420
-
421
- const result = await response.json();
422
- if (this.config.options?.debug) {
423
- //console.log('🔍 DEBUG: createPayment success response:', result);
424
- }
425
-
426
- return result;
427
- } catch (error) {
428
- this.handleError(error as Error);
429
- return null;
430
- }
431
- }
432
-
433
- /**
434
- * Simplified API: Attach download limiting to a single button
435
- * Handles all UI logic automatically (paywall, auth, payment flow)
436
- */
437
- public attachToButton(selector: string, downloadCallback: (() => void) | ((userContext: UserContext) => void)): void {
438
- //console.log('🎨 [THEME DEBUG] attachToButton called');
439
- //console.log('🎨 [THEME DEBUG] Full config:', JSON.stringify(this.config, null, 2));
440
-
441
- const button = document.querySelector(selector) as HTMLButtonElement;
442
- if (!button) {
443
- throw new Error(`Button not found: ${selector}`);
444
- }
445
-
446
- // Store original button text (for potential future use)
447
- // const originalText = button.textContent || 'Download';
448
-
449
- // Create and inject UI elements
450
- this.injectBaseStyles();
451
- this.createTitleBar(); // Always create title bar first
452
- this.createPaywallModal();
453
- this.createSuccessModal();
454
- this.createAuthUI();
455
- this.createStatusDisplay();
456
-
457
- // Set up button click handler
458
- // Mark button as attached by LeadFast
459
- button.setAttribute('data-leadfast-attached', 'true');
460
-
461
- button.onclick = async (e) => {
462
- e.preventDefault();
463
- await this.handleButtonClick(downloadCallback);
464
- };
465
-
466
- // Update UI based on auth state
467
- this.setupUIUpdates();
468
- }
469
-
470
- /**
471
- * Simplified API: Attach download limiting to multiple buttons
472
- * Each button can have different download callbacks and premium status
473
- */
474
- public attachToButtons(config: {
475
- buttons: Array<{
476
- selector: string;
477
- downloadCallback: (() => void) | ((userContext: UserContext) => void);
478
- isPremium?: boolean;
479
- premiumLabel?: string;
480
- }>;
481
- }): void {
482
- this.injectBaseStyles();
483
- this.createTitleBar(); // Always create title bar first
484
- this.createPaywallModal();
485
- this.createSuccessModal();
486
- this.createAuthUI();
487
-
488
- config.buttons.forEach(buttonConfig => {
489
- const button = document.querySelector(buttonConfig.selector) as HTMLButtonElement;
490
- if (!button) {
491
- console.warn(`Button not found: ${buttonConfig.selector}`);
492
- return;
493
- }
494
-
495
- // Store original text for potential future use
496
- // const originalText = button.textContent || 'Download';
497
-
498
- // Set up click handler - all buttons use the same logic now
499
- // Mark button as attached by LeadFast
500
- button.setAttribute('data-leadfast-attached', 'true');
501
-
502
- button.onclick = async (e) => {
503
- e.preventDefault();
504
- await this.handleButtonClick(buttonConfig.downloadCallback);
505
- };
506
-
507
- this.setupUIUpdates();
508
- });
509
-
510
- // Add global status display
511
- this.createGlobalStatusDisplay();
512
- }
513
-
514
- private async handleButtonClick(downloadCallback: (() => void) | ((userContext: UserContext) => void)): Promise<void> {
515
- // Prevent rapid clicks/race conditions
516
- const button = document.querySelector('[data-leadfast-attached="true"]') as HTMLButtonElement;
517
- if (button && button.disabled) {
518
- console.log('⚠️ Button click ignored - operation already in progress');
519
- return;
520
- }
521
-
522
- if (button) {
523
- button.disabled = true;
524
- button.style.opacity = '0.6';
525
- }
526
-
527
- try {
528
- await this.handleButtonClickInternal(downloadCallback);
529
- } finally {
530
- // Re-enable button
531
- if (button) {
532
- button.disabled = false;
533
- button.style.opacity = '1';
534
- }
535
- }
536
- }
537
-
538
- private async handleButtonClickInternal(downloadCallback: (() => void) | ((userContext: UserContext) => void)): Promise<void> {
539
- // const clickTime = Date.now();
540
- // console.log(`🕐 [TIMING] Button click started at: ${new Date(clickTime).toISOString()}`);
541
-
542
- // Security check: if Supabase connection failed, disable downloads to prevent localStorage bypass
543
- if (this.supabaseConnectionFailed) {
544
- // console.log(`🕐 [TIMING] Connection failed check: ${Date.now() - clickTime}ms`);
545
- this.showConnectionError();
546
- return;
547
- }
548
-
549
- // Security check: if payment configuration is invalid, disable downloads
550
- if (this.config.payment && this.paymentConnectionFailed) {
551
- // console.log(`🕐 [TIMING] Payment config failed check: ${Date.now() - clickTime}ms`);
552
- this.showPaymentConfigError();
553
- return;
554
- }
555
-
556
- // Check cache status
557
- const cacheValid = this.cachedStatus && (Date.now() - this.statusCacheTime) < this.STATUS_CACHE_DURATION;
558
- // console.log(`🕐 [CACHE] Cache valid: ${cacheValid}, age: ${this.cachedStatus ? Date.now() - this.statusCacheTime : 'no cache'}ms`);
559
- // console.log(`🕐 [CACHE] Cached status:`, this.cachedStatus);
560
-
561
- // const statusStartTime = Date.now();
562
- // Use cached status if available (since it's already displayed in title bar)
563
- const status = cacheValid
564
- ? this.cachedStatus!
565
- : await this.getDownloadStatus();
566
- // console.log(`🕐 [TIMING] Status check completed: ${Date.now() - statusStartTime}ms (total: ${Date.now() - clickTime}ms)`);
567
- // console.log(`🕐 [STATUS] Final status:`, status);
568
-
569
- // Check if user is premium first (quick check from cached status)
570
- if (status.isPremium) {
571
- // console.log(`🕐 [TIMING] Premium user - callback executed: ${Date.now() - clickTime}ms`);
572
- // Get user context for premium users too
573
- const userContext = await this.getUserContext();
574
-
575
- // Check if callback expects user context parameter
576
- if (downloadCallback.length > 0) {
577
- // Callback expects user context parameter
578
- (downloadCallback as (userContext: UserContext) => void)(userContext);
579
- } else {
580
- // Legacy callback with no parameters
581
- (downloadCallback as () => void)();
582
- }
583
- return;
584
- }
585
-
586
- // Quick limit check from cached status - show paywall immediately if needed
587
- if (status.currentCount >= status.limit) {
588
- // console.log(`🕐 [TIMING] Limit reached (${status.currentCount}/${status.limit}) - showing paywall: ${Date.now() - clickTime}ms`);
589
- // Limit reached - show paywall instantly (no additional API calls)
590
- // const paywallStartTime = Date.now();
591
- this.showPaywallInstant(status);
592
- // console.log(`🕐 [TIMING] Paywall shown: ${Date.now() - paywallStartTime}ms (total: ${Date.now() - clickTime}ms)`);
593
- return;
594
- }
595
-
596
- // console.log(`🕐 [TIMING] Limit not reached (${status.currentCount}/${status.limit}) - proceeding with action`);
597
- // Allow action and increment counter
598
- // const incrementStartTime = Date.now();
599
- // Execute user's function first - only increment count if it succeeds
600
- try {
601
- // Check if callback expects user context parameter
602
- if (downloadCallback.length > 0) {
603
- // Get user context BEFORE increment for callback
604
- const userContext = await this.getUserContext();
605
-
606
- // For non-premium users, simulate the increment so user context matches UI
607
- if (!userContext.isPremium) {
608
- userContext.currentCount += 1;
609
- userContext.remaining = Math.max(0, userContext.limit - userContext.currentCount);
610
- }
611
-
612
- // Callback expects user context parameter
613
- (downloadCallback as (userContext: UserContext) => void)(userContext);
614
- } else {
615
- // Legacy callback with no parameters
616
- (downloadCallback as () => void)();
617
- }
618
-
619
- // Double-check limit before increment (race condition protection)
620
- const freshStatus = await this.getDownloadStatus(true); // Force refresh
621
- if (freshStatus.currentCount >= freshStatus.limit) {
622
- console.warn(`⚠️ Limit reached during execution (${freshStatus.currentCount}/${freshStatus.limit}) - canceling increment`);
623
- // User reached limit while their function was executing
624
- alert('⚠️ You reached the limit while this action was processing. No attempt was counted.');
625
- return;
626
- }
627
-
628
- // Only increment count after successful execution - with limit check
629
- const newCount = await this.incrementDownloadCount();
630
-
631
- // Double-check: if server returned count exceeding limit, something went wrong
632
- if (newCount > this.config.freeAttemptLimit) {
633
- console.error(`⚠️ Server returned count (${newCount}) exceeding limit (${this.config.freeAttemptLimit})`);
634
- // Don't update UI with invalid state
635
- return;
636
- }
637
- // console.log(`🕐 [TIMING] Count incremented: ${Date.now() - incrementStartTime}ms`);
638
-
639
- // Show success message only if explicitly enabled in config
640
- if (this.config.successMessage?.enabled === true) {
641
- const title = this.config.successMessage?.title || 'Action Completed!';
642
- const message = this.config.successMessage?.message || 'Your action completed successfully!';
643
- this.showSuccess(title, message);
644
- }
645
- } catch (error) {
646
- console.error('User function failed:', error);
647
- // Don't increment count on error - user shouldn't lose an attempt
648
- alert('Action failed. Please check the console for details. No attempt was counted.');
649
- return; // Exit early, don't update UI
650
- }
651
-
652
- // Update UI with fresh status (invalidate cache since count changed)
653
- // console.log(`🕐 [CACHE] Invalidating cache due to count change (was: ${this.cachedStatus ? 'cached' : 'null'})`);
654
- this.cachedStatus = null;
655
- this.updateStatusDisplays();
656
- // console.log(`🕐 [TIMING] Button click completed: ${Date.now() - clickTime}ms`);
657
- }
658
-
659
-
660
- private injectBaseStyles(): void {
661
- //console.log('🎨 [THEME DEBUG] injectBaseStyles called');
662
- if (document.getElementById('lead-fast-styles')) {
663
- //console.log('🎨 [THEME DEBUG] Styles already injected, skipping');
664
- return;
665
- }
666
-
667
- // Inject DaisyUI CDN if theme is specified
668
- if (this.config.theme?.name) {
669
- //console.log('🎨 [THEME DEBUG] Theme specified, calling injectDaisyUI');
670
- this.injectDaisyUI();
671
- } else {
672
- //console.log('🎨 [THEME DEBUG] No theme specified in config');
673
- }
674
-
675
- const styles = document.createElement('style');
676
- styles.id = 'lead-fast-styles';
677
- const primaryColor = this.config.theme?.primaryColor || '#3182ce';
678
-
679
- styles.textContent = `
680
- /* User Profile Card - Top Right */
681
- .lead-fast-profile {
682
- position: fixed;
683
- top: 20px;
684
- left: 50%;
685
- transform: translateX(-50%);
686
- z-index: 1000;
687
- font-family: system-ui, -apple-system, sans-serif;
688
- width: 90%;
689
- max-width: 1200px;
690
- }
691
-
692
- .lead-fast-title-bar {
693
- background: rgba(250, 247, 245, 0.9) !important;
694
- border: 1px solid rgba(231, 226, 223, 0.6) !important;
695
- color: #291334 !important;
696
- border-radius: 16px;
697
- padding: 12px 24px;
698
- box-shadow: 0 8px 32px rgb(0 0 0 / 0.1), 0 2px 8px rgb(0 0 0 / 0.05);
699
- backdrop-filter: blur(20px);
700
- display: flex;
701
- align-items: center;
702
- justify-content: space-between;
703
- min-height: 60px;
704
- font-family: system-ui, -apple-system, sans-serif;
705
- }
706
-
707
- /* Theme variations for floating title bar */
708
- [data-theme="bumblebee"] .lead-fast-title-bar {
709
- background: rgba(255, 248, 220, 0.9) !important;
710
- border-color: rgba(254, 215, 170, 0.6) !important;
711
- color: #1c1917 !important;
712
- }
713
-
714
- [data-theme="garden"] .lead-fast-title-bar {
715
- background: rgba(240, 253, 244, 0.9) !important;
716
- border-color: rgba(134, 239, 172, 0.6) !important;
717
- color: #14532d !important;
718
- }
719
-
720
- [data-theme="emerald"] .lead-fast-title-bar {
721
- background: rgba(236, 253, 245, 0.9) !important;
722
- border-color: rgba(167, 243, 208, 0.6) !important;
723
- color: #065f46 !important;
724
- }
725
-
726
- [data-theme="corporate"] .lead-fast-title-bar {
727
- background: rgba(248, 250, 252, 0.9) !important;
728
- border-color: rgba(226, 232, 240, 0.6) !important;
729
- color: #1e293b !important;
730
- }
731
-
732
- [data-theme="dark"] .lead-fast-title-bar {
733
- background: rgba(31, 41, 55, 0.9) !important;
734
- border-color: rgba(55, 65, 81, 0.6) !important;
735
- color: #f9fafb !important;
736
- }
737
-
738
- [data-theme="cyberpunk"] .lead-fast-title-bar {
739
- background: rgba(0, 20, 36, 0.9) !important;
740
- border-color: rgba(7, 89, 133, 0.6) !important;
741
- color: #0ea5e9 !important;
742
- box-shadow: 0 8px 32px rgba(14, 165, 233, 0.2), 0 2px 8px rgba(14, 165, 233, 0.1);
743
- }
744
-
745
- [data-theme="valentine"] .lead-fast-title-bar {
746
- background: rgba(233, 30, 122, 0.15) !important;
747
- border-color: rgba(233, 30, 122, 0.6) !important;
748
- color: #831843 !important;
749
- }
750
-
751
- [data-theme="synthwave"] .lead-fast-title-bar {
752
- background: rgba(32, 20, 64, 0.9) !important;
753
- border-color: rgba(186, 85, 211, 0.6) !important;
754
- color: #ff00ff !important;
755
- box-shadow: 0 8px 32px rgba(255, 0, 255, 0.2), 0 2px 8px rgba(255, 0, 255, 0.1);
756
- }
757
-
758
- [data-theme="dracula"] .lead-fast-title-bar {
759
- background: rgba(40, 42, 54, 0.9) !important;
760
- border-color: rgba(98, 114, 164, 0.6) !important;
761
- color: #f8f8f2 !important;
762
- }
763
-
764
- [data-theme="halloween"] .lead-fast-title-bar {
765
- background: rgba(26, 26, 26, 0.9) !important;
766
- border-color: rgba(255, 165, 0, 0.6) !important;
767
- color: #ff6600 !important;
768
- }
769
-
770
- [data-theme="forest"] .lead-fast-title-bar {
771
- background: rgba(23, 46, 23, 0.9) !important;
772
- border-color: rgba(34, 197, 94, 0.6) !important;
773
- color: #22c55e !important;
774
- }
775
-
776
- [data-theme="luxury"] .lead-fast-title-bar {
777
- background: rgba(9, 9, 11, 0.9) !important;
778
- border-color: rgba(212, 175, 55, 0.6) !important;
779
- color: #d4af37 !important;
780
- }
781
-
782
- [data-theme="night"] .lead-fast-title-bar {
783
- background: rgba(15, 23, 42, 0.9) !important;
784
- border-color: rgba(30, 58, 138, 0.6) !important;
785
- color: #60a5fa !important;
786
- }
787
-
788
- [data-theme="light"] .lead-fast-title-bar {
789
- background: rgba(255, 255, 255, 0.9) !important;
790
- border-color: rgba(229, 231, 235, 0.6) !important;
791
- color: #1f2937 !important;
792
- }
793
-
794
- [data-theme="cupcake"] .lead-fast-title-bar {
795
- background: rgba(250, 235, 215, 0.9) !important;
796
- border-color: rgba(219, 185, 156, 0.6) !important;
797
- color: #8b4513 !important;
798
- }
799
-
800
- [data-theme="retro"] .lead-fast-title-bar {
801
- background: rgba(212, 165, 116, 0.9) !important;
802
- border-color: rgba(185, 144, 102, 0.6) !important;
803
- color: #5d4037 !important;
804
- }
805
-
806
- [data-theme="aqua"] .lead-fast-title-bar {
807
- background: rgba(240, 253, 250, 0.9) !important;
808
- border-color: rgba(125, 211, 252, 0.6) !important;
809
- color: #155e75 !important;
810
- }
811
-
812
- [data-theme="lofi"] .lead-fast-title-bar {
813
- background: rgba(248, 248, 248, 0.9) !important;
814
- border-color: rgba(68, 68, 68, 0.6) !important;
815
- color: #1a1a1a !important;
816
- }
817
-
818
- [data-theme="pastel"] .lead-fast-title-bar {
819
- background: rgba(254, 251, 255, 0.9) !important;
820
- border-color: rgba(209, 196, 233, 0.6) !important;
821
- color: #7c3aed !important;
822
- }
823
-
824
- [data-theme="fantasy"] .lead-fast-title-bar {
825
- background: rgba(255, 247, 237, 0.9) !important;
826
- border-color: rgba(249, 168, 212, 0.6) !important;
827
- color: #be185d !important;
828
- }
829
-
830
- [data-theme="wireframe"] .lead-fast-title-bar {
831
- background: rgba(223, 223, 223, 0.9) !important;
832
- border-color: rgba(0, 0, 0, 0.3) !important;
833
- color: #000000 !important;
834
- }
835
-
836
- [data-theme="black"] .lead-fast-title-bar {
837
- background: rgba(0, 0, 0, 0.9) !important;
838
- border-color: rgba(55, 55, 55, 0.6) !important;
839
- color: #ffffff !important;
840
- }
841
-
842
- [data-theme="cmyk"] .lead-fast-title-bar {
843
- background: rgba(0, 255, 255, 0.9) !important;
844
- border-color: rgba(255, 0, 255, 0.6) !important;
845
- color: #000000 !important;
846
- }
847
-
848
- [data-theme="autumn"] .lead-fast-title-bar {
849
- background: rgba(139, 69, 19, 0.9) !important;
850
- border-color: rgba(255, 140, 0, 0.6) !important;
851
- color: #ff8c00 !important;
852
- }
853
-
854
- [data-theme="business"] .lead-fast-title-bar {
855
- background: rgba(29, 78, 216, 0.9) !important;
856
- border-color: rgba(59, 130, 246, 0.6) !important;
857
- color: #3b82f6 !important;
858
- }
859
-
860
- [data-theme="acid"] .lead-fast-title-bar {
861
- background: rgba(255, 255, 0, 0.9) !important;
862
- border-color: rgba(255, 0, 255, 0.6) !important;
863
- color: #000000 !important;
864
- }
865
-
866
- [data-theme="lemonade"] .lead-fast-title-bar {
867
- background: rgba(255, 255, 224, 0.9) !important;
868
- border-color: rgba(34, 197, 94, 0.6) !important;
869
- color: #15803d !important;
870
- }
871
-
872
- [data-theme="coffee"] .lead-fast-title-bar {
873
- background: rgba(101, 67, 33, 0.9) !important;
874
- border-color: rgba(160, 82, 45, 0.6) !important;
875
- color: #d2b48c !important;
876
- }
877
-
878
- [data-theme="winter"] .lead-fast-title-bar {
879
- background: rgba(248, 250, 252, 0.9) !important;
880
- border-color: rgba(59, 130, 246, 0.6) !important;
881
- color: #1e40af !important;
882
- }
883
-
884
- .lead-fast-title-section {
885
- display: flex;
886
- align-items: center;
887
- gap: 16px;
888
- }
889
-
890
- .lead-fast-logo {
891
- font-size: 20px;
892
- font-weight: 700;
893
- display: flex;
894
- align-items: center;
895
- gap: 8px;
896
- color: inherit;
897
- text-decoration: none;
898
- }
899
-
900
- .lead-fast-logo img {
901
- width: 32px;
902
- height: 32px;
903
- border-radius: 6px;
904
- }
905
-
906
- .lead-fast-nav {
907
- display: flex;
908
- align-items: center;
909
- gap: 32px;
910
- margin-left: 24px;
911
- }
912
-
913
- .lead-fast-nav-link {
914
- color: inherit;
915
- text-decoration: none;
916
- font-weight: 500;
917
- font-size: 14px;
918
- opacity: 0.8;
919
- transition: all 0.2s;
920
- }
921
-
922
- .lead-fast-nav-link:hover {
923
- opacity: 1;
924
- text-decoration: none;
925
- }
926
-
927
- .lead-fast-user-section {
928
- display: flex;
929
- align-items: center;
930
- gap: 12px;
931
- }
932
-
933
- .lead-fast-avatar {
934
- width: 36px;
935
- height: 36px;
936
- border-radius: 50%;
937
- background: linear-gradient(135deg, ${primaryColor}, #4f46e5);
938
- display: flex;
939
- align-items: center;
940
- justify-content: center;
941
- color: white;
942
- font-weight: 600;
943
- font-size: 14px;
944
- }
945
-
946
- .lead-fast-user-info {
947
- display: flex;
948
- flex-direction: column;
949
- align-items: flex-start;
950
- gap: 2px;
951
- }
952
-
953
- .lead-fast-user-email {
954
- color: inherit !important;
955
- font-size: 13px;
956
- font-weight: 500;
957
- line-height: 1;
958
- }
959
-
960
- .lead-fast-user-status {
961
- display: flex;
962
- align-items: center;
963
- gap: 6px;
964
- }
965
-
966
- .lead-fast-badge {
967
- padding: 2px 6px;
968
- border-radius: 12px;
969
- font-size: 10px;
970
- font-weight: 600;
971
- text-transform: uppercase;
972
- letter-spacing: 0.025em;
973
- line-height: 1;
974
- }
975
-
976
- .lead-fast-badge.premium {
977
- background: #10b981 !important;
978
- color: #ffffff !important;
979
- }
980
-
981
- .lead-fast-badge.free {
982
- background: #65c3c8 !important;
983
- color: #291334 !important;
984
- }
985
-
986
- [data-theme="dark"] .lead-fast-badge.premium {
987
- background: #059669 !important;
988
- color: #ffffff !important;
989
- }
990
-
991
- [data-theme="dark"] .lead-fast-badge.free {
992
- background: #374151 !important;
993
- color: #f9fafb !important;
994
- }
995
-
996
- .lead-fast-count {
997
- font-size: 10px;
998
- color: inherit !important;
999
- opacity: 0.7;
1000
- line-height: 1;
1001
- }
1002
-
1003
- .lead-fast-signout {
1004
- background: rgba(0, 0, 0, 0.1) !important;
1005
- border: none;
1006
- color: inherit !important;
1007
- cursor: pointer;
1008
- padding: 6px 12px;
1009
- border-radius: 8px;
1010
- transition: all 0.2s;
1011
- font-size: 11px;
1012
- font-weight: 500;
1013
- margin-left: 8px;
1014
- }
1015
-
1016
- [data-theme="dark"] .lead-fast-signout {
1017
- background: rgba(255, 255, 255, 0.1) !important;
1018
- }
1019
-
1020
- [data-theme="cyberpunk"] .lead-fast-signout {
1021
- background: rgba(14, 165, 233, 0.2) !important;
1022
- }
1023
-
1024
- .lead-fast-signout:hover {
1025
- background: rgba(0, 0, 0, 0.2) !important;
1026
- transform: translateY(-1px);
1027
- }
1028
-
1029
- [data-theme="dark"] .lead-fast-signout:hover {
1030
- background: rgba(255, 255, 255, 0.2) !important;
1031
- }
1032
-
1033
- [data-theme="cyberpunk"] .lead-fast-signout:hover {
1034
- background: rgba(14, 165, 233, 0.3) !important;
1035
- }
1036
-
1037
- .lead-fast-branding {
1038
- position: absolute;
1039
- bottom: -20px;
1040
- left: 24px;
1041
- font-size: 9px;
1042
- color: inherit !important;
1043
- opacity: 0.4;
1044
- font-weight: 500;
1045
- letter-spacing: 0.05em;
1046
- text-transform: lowercase;
1047
- background: rgba(255, 255, 255, 0.8);
1048
- padding: 2px 6px;
1049
- border-radius: 4px;
1050
- backdrop-filter: blur(8px);
1051
- }
1052
-
1053
- [data-theme="dark"] .lead-fast-branding {
1054
- background: rgba(0, 0, 0, 0.6);
1055
- }
1056
-
1057
- [data-theme="cyberpunk"] .lead-fast-branding {
1058
- background: rgba(0, 20, 36, 0.8);
1059
- }
1060
-
1061
- /* Modal Theming */
1062
- .download-limiter-modal {
1063
- display: none;
1064
- position: fixed;
1065
- top: 0;
1066
- left: 0;
1067
- width: 100%;
1068
- height: 100%;
1069
- background: rgba(0,0,0,0.5);
1070
- z-index: 9999;
1071
- align-items: center;
1072
- justify-content: center;
1073
- }
1074
- .download-limiter-modal.show { display: flex; }
1075
-
1076
- .download-limiter-content {
1077
- background: #faf7f5 !important;
1078
- color: #291334 !important;
1079
- padding: 2rem;
1080
- border-radius: 12px;
1081
- max-width: 400px;
1082
- text-align: center;
1083
- box-shadow: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
1084
- border: 1px solid #e7e2df !important;
1085
- font-family: system-ui, -apple-system, sans-serif;
1086
- }
1087
-
1088
- [data-theme="dark"] .download-limiter-content {
1089
- background: #1f2937 !important;
1090
- color: #f9fafb !important;
1091
- border-color: #374151 !important;
1092
- }
1093
-
1094
- [data-theme="cyberpunk"] .download-limiter-content {
1095
- background: #001424 !important;
1096
- color: #0ea5e9 !important;
1097
- border-color: #075985 !important;
1098
- }
1099
-
1100
- [data-theme="valentine"] .download-limiter-content {
1101
- background: rgba(233, 30, 122, 0.05) !important;
1102
- color: #831843 !important;
1103
- border-color: #e91e7a !important;
1104
- }
1105
-
1106
- [data-theme="bumblebee"] .download-limiter-content {
1107
- background: rgba(255, 248, 220, 0.95) !important;
1108
- color: #1c1917 !important;
1109
- border-color: rgba(254, 215, 170, 0.8) !important;
1110
- }
1111
-
1112
- [data-theme="garden"] .download-limiter-content {
1113
- background: rgba(240, 253, 244, 0.95) !important;
1114
- color: #14532d !important;
1115
- border-color: rgba(134, 239, 172, 0.8) !important;
1116
- }
1117
-
1118
- [data-theme="emerald"] .download-limiter-content {
1119
- background: rgba(236, 253, 245, 0.95) !important;
1120
- color: #065f46 !important;
1121
- border-color: rgba(167, 243, 208, 0.8) !important;
1122
- }
1123
-
1124
- [data-theme="corporate"] .download-limiter-content {
1125
- background: rgba(248, 250, 252, 0.95) !important;
1126
- color: #1e293b !important;
1127
- border-color: rgba(226, 232, 240, 0.8) !important;
1128
- }
1129
-
1130
- [data-theme="forest"] .download-limiter-content {
1131
- background: rgba(23, 46, 23, 0.95) !important;
1132
- color: #22c55e !important;
1133
- border-color: rgba(34, 197, 94, 0.8) !important;
1134
- }
1135
-
1136
- [data-theme="halloween"] .download-limiter-content {
1137
- background: rgba(26, 26, 26, 0.95) !important;
1138
- color: #ff6500 !important;
1139
- border-color: rgba(255, 165, 0, 0.3) !important;
1140
- }
1141
-
1142
- [data-theme="synthwave"] .download-limiter-content {
1143
- background: rgba(32, 20, 64, 0.95) !important;
1144
- color: #ba55d3 !important;
1145
- border-color: rgba(186, 85, 211, 0.3) !important;
1146
- }
1147
-
1148
- [data-theme="dracula"] .download-limiter-content {
1149
- background: rgba(40, 42, 54, 0.95) !important;
1150
- color: #f8f8f2 !important;
1151
- border-color: rgba(98, 114, 164, 0.3) !important;
1152
- }
1153
-
1154
- [data-theme="luxury"] .download-limiter-content {
1155
- background: rgba(9, 9, 11, 0.95) !important;
1156
- color: #d4af37 !important;
1157
- border-color: rgba(212, 175, 55, 0.3) !important;
1158
- }
1159
-
1160
- [data-theme="night"] .download-limiter-content {
1161
- background: rgba(15, 23, 42, 0.95) !important;
1162
- color: #1e40af !important;
1163
- border-color: rgba(30, 58, 138, 0.3) !important;
1164
- }
1165
-
1166
- [data-theme="light"] .download-limiter-content {
1167
- background: rgba(255, 255, 255, 0.95) !important;
1168
- color: #1f2937 !important;
1169
- border-color: rgba(229, 231, 235, 0.8) !important;
1170
- }
1171
-
1172
- [data-theme="cupcake"] .download-limiter-content {
1173
- background: rgba(250, 235, 215, 0.95) !important;
1174
- color: #8b4513 !important;
1175
- border-color: rgba(219, 185, 156, 0.8) !important;
1176
- }
1177
-
1178
- [data-theme="retro"] .download-limiter-content {
1179
- background: rgba(212, 165, 116, 0.95) !important;
1180
- color: #5d4037 !important;
1181
- border-color: rgba(185, 144, 102, 0.8) !important;
1182
- }
1183
-
1184
- [data-theme="aqua"] .download-limiter-content {
1185
- background: rgba(240, 253, 250, 0.95) !important;
1186
- color: #155e75 !important;
1187
- border-color: rgba(125, 211, 252, 0.8) !important;
1188
- }
1189
-
1190
- [data-theme="lofi"] .download-limiter-content {
1191
- background: rgba(248, 248, 248, 0.95) !important;
1192
- color: #1a1a1a !important;
1193
- border-color: rgba(68, 68, 68, 0.8) !important;
1194
- }
1195
-
1196
- [data-theme="pastel"] .download-limiter-content {
1197
- background: rgba(254, 251, 255, 0.95) !important;
1198
- color: #7c3aed !important;
1199
- border-color: rgba(209, 196, 233, 0.8) !important;
1200
- }
1201
-
1202
- [data-theme="fantasy"] .download-limiter-content {
1203
- background: rgba(255, 247, 237, 0.95) !important;
1204
- color: #be185d !important;
1205
- border-color: rgba(249, 168, 212, 0.8) !important;
1206
- }
1207
-
1208
- [data-theme="wireframe"] .download-limiter-content {
1209
- background: rgba(255, 255, 255, 0.95) !important;
1210
- color: #000000 !important;
1211
- border-color: rgba(0, 0, 0, 0.3) !important;
1212
- }
1213
-
1214
- [data-theme="black"] .download-limiter-content {
1215
- background: rgba(0, 0, 0, 0.95) !important;
1216
- color: #ffffff !important;
1217
- border-color: rgba(55, 55, 55, 0.8) !important;
1218
- }
1219
-
1220
- [data-theme="cmyk"] .download-limiter-content {
1221
- background: rgba(0, 255, 255, 0.95) !important;
1222
- color: #000000 !important;
1223
- border-color: rgba(255, 0, 255, 0.8) !important;
1224
- }
1225
-
1226
- [data-theme="autumn"] .download-limiter-content {
1227
- background: rgba(139, 69, 19, 0.95) !important;
1228
- color: #ff8c00 !important;
1229
- border-color: rgba(255, 140, 0, 0.8) !important;
1230
- }
1231
-
1232
- [data-theme="business"] .download-limiter-content {
1233
- background: rgba(29, 78, 216, 0.95) !important;
1234
- color: #3b82f6 !important;
1235
- border-color: rgba(59, 130, 246, 0.8) !important;
1236
- }
1237
-
1238
- [data-theme="acid"] .download-limiter-content {
1239
- background: rgba(255, 255, 0, 0.95) !important;
1240
- color: #000000 !important;
1241
- border-color: rgba(255, 0, 255, 0.8) !important;
1242
- }
1243
-
1244
- [data-theme="lemonade"] .download-limiter-content {
1245
- background: rgba(255, 255, 224, 0.95) !important;
1246
- color: #15803d !important;
1247
- border-color: rgba(34, 197, 94, 0.8) !important;
1248
- }
1249
-
1250
- [data-theme="coffee"] .download-limiter-content {
1251
- background: rgba(101, 67, 33, 0.95) !important;
1252
- color: #d2b48c !important;
1253
- border-color: rgba(160, 82, 45, 0.8) !important;
1254
- }
1255
-
1256
- [data-theme="winter"] .download-limiter-content {
1257
- background: rgba(248, 250, 252, 0.95) !important;
1258
- color: #1e40af !important;
1259
- border-color: rgba(59, 130, 246, 0.8) !important;
1260
- }
1261
-
1262
- .download-limiter-content h2 {
1263
- color: inherit !important;
1264
- margin: 0 0 1rem 0;
1265
- font-size: 1.5rem;
1266
- font-weight: 600;
1267
- }
1268
- .download-limiter-content p {
1269
- color: inherit !important;
1270
- margin: 0 0 1.5rem 0;
1271
- line-height: 1.6;
1272
- }
1273
- .download-limiter-signin-btn {
1274
- display: inline-flex;
1275
- align-items: center;
1276
- gap: 8px;
1277
- background: #65c3c8 !important;
1278
- color: #291334 !important;
1279
- border: none;
1280
- padding: 12px 20px;
1281
- border-radius: 8px;
1282
- font-size: 14px;
1283
- font-weight: 500;
1284
- cursor: pointer;
1285
- text-decoration: none;
1286
- transition: all 0.2s;
1287
- box-shadow: 0 2px 4px rgba(0,0,0,0.1);
1288
- }
1289
-
1290
- [data-theme="dark"] .download-limiter-signin-btn {
1291
- background: #3b82f6 !important;
1292
- color: #ffffff !important;
1293
- }
1294
-
1295
- [data-theme="cyberpunk"] .download-limiter-signin-btn {
1296
- background: #f59e0b !important;
1297
- color: #000000 !important;
1298
- }
1299
-
1300
- [data-theme="valentine"] .download-limiter-signin-btn {
1301
- background: #e91e7a !important;
1302
- color: #ffffff !important;
1303
- }
1304
-
1305
- [data-theme="bumblebee"] .download-limiter-signin-btn {
1306
- background: #fbbf24 !important;
1307
- color: #1c1917 !important;
1308
- }
1309
-
1310
- [data-theme="garden"] .download-limiter-signin-btn {
1311
- background: #22c55e !important;
1312
- color: #ffffff !important;
1313
- }
1314
-
1315
- [data-theme="emerald"] .download-limiter-signin-btn {
1316
- background: #10b981 !important;
1317
- color: #ffffff !important;
1318
- }
1319
-
1320
- [data-theme="corporate"] .download-limiter-signin-btn {
1321
- background: #3b82f6 !important;
1322
- color: #ffffff !important;
1323
- }
1324
-
1325
- [data-theme="forest"] .download-limiter-signin-btn {
1326
- background: #22c55e !important;
1327
- color: #1a1a1a !important;
1328
- }
1329
-
1330
- [data-theme="halloween"] .download-limiter-signin-btn {
1331
- background: #ff6500 !important;
1332
- color: #1a1a1a !important;
1333
- }
1334
-
1335
- [data-theme="synthwave"] .download-limiter-signin-btn {
1336
- background: #ba55d3 !important;
1337
- color: #201040 !important;
1338
- }
1339
-
1340
- [data-theme="dracula"] .download-limiter-signin-btn {
1341
- background: #8be9fd !important;
1342
- color: #282a36 !important;
1343
- }
1344
-
1345
- [data-theme="luxury"] .download-limiter-signin-btn {
1346
- background: #d4af37 !important;
1347
- color: #09090b !important;
1348
- }
1349
-
1350
- [data-theme="night"] .download-limiter-signin-btn {
1351
- background: #1e40af !important;
1352
- color: #ffffff !important;
1353
- }
1354
-
1355
- [data-theme="light"] .download-limiter-signin-btn {
1356
- background: #3b82f6 !important;
1357
- color: #ffffff !important;
1358
- }
1359
-
1360
- [data-theme="cupcake"] .download-limiter-signin-btn {
1361
- background: #8b4513 !important;
1362
- color: #ffffff !important;
1363
- }
1364
-
1365
- [data-theme="retro"] .download-limiter-signin-btn {
1366
- background: #d4a574 !important;
1367
- color: #ffffff !important;
1368
- }
1369
-
1370
- [data-theme="aqua"] .download-limiter-signin-btn {
1371
- background: #0891b2 !important;
1372
- color: #ffffff !important;
1373
- }
1374
-
1375
- [data-theme="lofi"] .download-limiter-signin-btn {
1376
- background: #1a1a1a !important;
1377
- color: #ffffff !important;
1378
- }
1379
-
1380
- [data-theme="pastel"] .download-limiter-signin-btn {
1381
- background: #7c3aed !important;
1382
- color: #ffffff !important;
1383
- }
1384
-
1385
- [data-theme="fantasy"] .download-limiter-signin-btn {
1386
- background: #be185d !important;
1387
- color: #ffffff !important;
1388
- }
1389
-
1390
- [data-theme="wireframe"] .download-limiter-signin-btn {
1391
- background: #dfdfdf !important;
1392
- color: #000000 !important;
1393
- border: 1px solid #000000 !important;
1394
- }
1395
-
1396
- [data-theme="black"] .download-limiter-signin-btn {
1397
- background: #ffffff !important;
1398
- color: #000000 !important;
1399
- }
1400
-
1401
- [data-theme="cmyk"] .download-limiter-signin-btn {
1402
- background: #ff00ff !important;
1403
- color: #000000 !important;
1404
- }
1405
-
1406
- [data-theme="autumn"] .download-limiter-signin-btn {
1407
- background: #ff8c00 !important;
1408
- color: #ffffff !important;
1409
- }
1410
-
1411
- [data-theme="business"] .download-limiter-signin-btn {
1412
- background: #3b82f6 !important;
1413
- color: #ffffff !important;
1414
- }
1415
-
1416
- [data-theme="acid"] .download-limiter-signin-btn {
1417
- background: #ff00ff !important;
1418
- color: #000000 !important;
1419
- }
1420
-
1421
- [data-theme="lemonade"] .download-limiter-signin-btn {
1422
- background: #22c55e !important;
1423
- color: #ffffff !important;
1424
- }
1425
-
1426
- [data-theme="coffee"] .download-limiter-signin-btn {
1427
- background: #a0522d !important;
1428
- color: #ffffff !important;
1429
- }
1430
-
1431
- [data-theme="winter"] .download-limiter-signin-btn {
1432
- background: #3b82f6 !important;
1433
- color: #ffffff !important;
1434
- }
1435
-
1436
- .download-limiter-signin-btn:hover {
1437
- opacity: 0.9;
1438
- transform: translateY(-1px);
1439
- box-shadow: 0 4px 8px rgba(0,0,0,0.15);
1440
- }
1441
-
1442
- /* Upgrade Button Styles for All Themes */
1443
- [data-theme="dark"] .upgrade-btn {
1444
- background: #3b82f6 !important;
1445
- color: #ffffff !important;
1446
- }
1447
-
1448
- [data-theme="cyberpunk"] .upgrade-btn {
1449
- background: #ff073a !important;
1450
- color: #ffffff !important;
1451
- }
1452
-
1453
- [data-theme="valentine"] .upgrade-btn {
1454
- background: #e91e7a !important;
1455
- color: #ffffff !important;
1456
- }
1457
-
1458
- [data-theme="bumblebee"] .upgrade-btn {
1459
- background: #f59e0b !important;
1460
- color: #ffffff !important;
1461
- }
1462
-
1463
- [data-theme="garden"] .upgrade-btn {
1464
- background: #10b981 !important;
1465
- color: #ffffff !important;
1466
- }
1467
-
1468
- [data-theme="emerald"] .upgrade-btn {
1469
- background: #10b981 !important;
1470
- color: #ffffff !important;
1471
- }
1472
-
1473
- [data-theme="corporate"] .upgrade-btn {
1474
- background: #3b82f6 !important;
1475
- color: #ffffff !important;
1476
- }
1477
-
1478
- [data-theme="forest"] .upgrade-btn {
1479
- background: #10b981 !important;
1480
- color: #ffffff !important;
1481
- }
1482
-
1483
- [data-theme="halloween"] .upgrade-btn {
1484
- background: #ff7b00 !important;
1485
- color: #000000 !important;
1486
- }
1487
-
1488
- [data-theme="synthwave"] .upgrade-btn {
1489
- background: #e879f9 !important;
1490
- color: #ffffff !important;
1491
- }
1492
-
1493
- [data-theme="dracula"] .upgrade-btn {
1494
- background: #bd93f9 !important;
1495
- color: #ffffff !important;
1496
- }
1497
-
1498
- [data-theme="luxury"] .upgrade-btn {
1499
- background: #d4af37 !important;
1500
- color: #000000 !important;
1501
- }
1502
-
1503
- [data-theme="night"] .upgrade-btn {
1504
- background: #38bdf8 !important;
1505
- color: #ffffff !important;
1506
- }
1507
-
1508
- [data-theme="light"] .upgrade-btn {
1509
- background: #3b82f6 !important;
1510
- color: #ffffff !important;
1511
- }
1512
-
1513
- [data-theme="cupcake"] .upgrade-btn {
1514
- background: #f472b6 !important;
1515
- color: #ffffff !important;
1516
- }
1517
-
1518
- [data-theme="retro"] .upgrade-btn {
1519
- background: #d4a574 !important;
1520
- color: #ffffff !important;
1521
- }
1522
-
1523
- [data-theme="aqua"] .upgrade-btn {
1524
- background: #06b6d4 !important;
1525
- color: #ffffff !important;
1526
- }
1527
-
1528
- [data-theme="lofi"] .upgrade-btn {
1529
- background: #a3a3a3 !important;
1530
- color: #000000 !important;
1531
- }
1532
-
1533
- [data-theme="pastel"] .upgrade-btn {
1534
- background: #a78bfa !important;
1535
- color: #ffffff !important;
1536
- }
1537
-
1538
- [data-theme="fantasy"] .upgrade-btn {
1539
- background: #f472b6 !important;
1540
- color: #ffffff !important;
1541
- }
1542
-
1543
- [data-theme="wireframe"] .upgrade-btn {
1544
- background: #dfdfdf !important;
1545
- color: #000000 !important;
1546
- border: 1px solid #000000 !important;
1547
- }
1548
-
1549
- [data-theme="black"] .upgrade-btn {
1550
- background: #ffffff !important;
1551
- color: #000000 !important;
1552
- }
1553
-
1554
- [data-theme="cmyk"] .upgrade-btn {
1555
- background: #0891b2 !important;
1556
- color: #ffffff !important;
1557
- }
1558
-
1559
- [data-theme="autumn"] .upgrade-btn {
1560
- background: #d97706 !important;
1561
- color: #ffffff !important;
1562
- }
1563
-
1564
- [data-theme="business"] .upgrade-btn {
1565
- background: #3b82f6 !important;
1566
- color: #ffffff !important;
1567
- }
1568
-
1569
- [data-theme="acid"] .upgrade-btn {
1570
- background: #84cc16 !important;
1571
- color: #000000 !important;
1572
- }
1573
-
1574
- [data-theme="lemonade"] .upgrade-btn {
1575
- background: #22c55e !important;
1576
- color: #ffffff !important;
1577
- }
1578
-
1579
- [data-theme="coffee"] .upgrade-btn {
1580
- background: #a0522d !important;
1581
- color: #ffffff !important;
1582
- }
1583
-
1584
- [data-theme="winter"] .upgrade-btn {
1585
- background: #3b82f6 !important;
1586
- color: #ffffff !important;
1587
- }
1588
-
1589
- /* Cancel Button Styles for All Themes */
1590
- [data-theme="dark"] .cancel-btn {
1591
- background: #4b5563 !important;
1592
- color: #ffffff !important;
1593
- }
1594
-
1595
- [data-theme="cyberpunk"] .cancel-btn {
1596
- background: #7e22ce !important;
1597
- color: #ffffff !important;
1598
- }
1599
-
1600
- [data-theme="valentine"] .cancel-btn {
1601
- background: #c11560 !important;
1602
- color: #ffffff !important;
1603
- }
1604
-
1605
- [data-theme="bumblebee"] .cancel-btn {
1606
- background: #d97706 !important;
1607
- color: #ffffff !important;
1608
- }
1609
-
1610
- [data-theme="garden"] .cancel-btn {
1611
- background: #059669 !important;
1612
- color: #ffffff !important;
1613
- }
1614
-
1615
- [data-theme="emerald"] .cancel-btn {
1616
- background: #059669 !important;
1617
- color: #ffffff !important;
1618
- }
1619
-
1620
- [data-theme="corporate"] .cancel-btn {
1621
- background: #6b7280 !important;
1622
- color: #ffffff !important;
1623
- }
1624
-
1625
- [data-theme="forest"] .cancel-btn {
1626
- background: #059669 !important;
1627
- color: #ffffff !important;
1628
- }
1629
-
1630
- [data-theme="halloween"] .cancel-btn {
1631
- background: #7c3aed !important;
1632
- color: #ffffff !important;
1633
- }
1634
-
1635
- [data-theme="synthwave"] .cancel-btn {
1636
- background: #7e22ce !important;
1637
- color: #ffffff !important;
1638
- }
1639
-
1640
- [data-theme="dracula"] .cancel-btn {
1641
- background: #6272a4 !important;
1642
- color: #ffffff !important;
1643
- }
1644
-
1645
- [data-theme="luxury"] .cancel-btn {
1646
- background: #8b5cf6 !important;
1647
- color: #ffffff !important;
1648
- }
1649
-
1650
- [data-theme="night"] .cancel-btn {
1651
- background: #0284c7 !important;
1652
- color: #ffffff !important;
1653
- }
1654
-
1655
- [data-theme="light"] .cancel-btn {
1656
- background: #6b7280 !important;
1657
- color: #ffffff !important;
1658
- }
1659
-
1660
- [data-theme="cupcake"] .cancel-btn {
1661
- background: #ec4899 !important;
1662
- color: #ffffff !important;
1663
- }
1664
-
1665
- [data-theme="retro"] .cancel-btn {
1666
- background: #b8925c !important;
1667
- color: #ffffff !important;
1668
- }
1669
-
1670
- [data-theme="aqua"] .cancel-btn {
1671
- background: #0891b2 !important;
1672
- color: #ffffff !important;
1673
- }
1674
-
1675
- [data-theme="lofi"] .cancel-btn {
1676
- background: #6b7280 !important;
1677
- color: #ffffff !important;
1678
- }
1679
-
1680
- [data-theme="pastel"] .cancel-btn {
1681
- background: #8b5cf6 !important;
1682
- color: #ffffff !important;
1683
- }
1684
-
1685
- [data-theme="fantasy"] .cancel-btn {
1686
- background: #ec4899 !important;
1687
- color: #ffffff !important;
1688
- }
1689
-
1690
- [data-theme="wireframe"] .cancel-btn {
1691
- background: #f5f5f5 !important;
1692
- color: #000000 !important;
1693
- border: 1px solid #000000 !important;
1694
- }
1695
-
1696
- [data-theme="black"] .cancel-btn {
1697
- background: #6b7280 !important;
1698
- color: #ffffff !important;
1699
- }
1700
-
1701
- [data-theme="cmyk"] .cancel-btn {
1702
- background: #0369a1 !important;
1703
- color: #ffffff !important;
1704
- }
1705
-
1706
- [data-theme="autumn"] .cancel-btn {
1707
- background: #c2410c !important;
1708
- color: #ffffff !important;
1709
- }
1710
-
1711
- [data-theme="business"] .cancel-btn {
1712
- background: #6b7280 !important;
1713
- color: #ffffff !important;
1714
- }
1715
-
1716
- [data-theme="acid"] .cancel-btn {
1717
- background: #65a30d !important;
1718
- color: #ffffff !important;
1719
- }
1720
-
1721
- [data-theme="lemonade"] .cancel-btn {
1722
- background: #16a34a !important;
1723
- color: #ffffff !important;
1724
- }
1725
-
1726
- [data-theme="coffee"] .cancel-btn {
1727
- background: #8b4513 !important;
1728
- color: #ffffff !important;
1729
- }
1730
-
1731
- [data-theme="winter"] .cancel-btn {
1732
- background: #1e40af !important;
1733
- color: #ffffff !important;
1734
- }
1735
-
1736
- /* Success Button Styles for All Themes */
1737
- [data-theme="dark"] .success-btn {
1738
- background: #10b981 !important;
1739
- color: #ffffff !important;
1740
- }
1741
-
1742
- [data-theme="cyberpunk"] .success-btn {
1743
- background: #00ff41 !important;
1744
- color: #000000 !important;
1745
- }
1746
-
1747
- [data-theme="valentine"] .success-btn {
1748
- background: #e91e7a !important;
1749
- color: #ffffff !important;
1750
- }
1751
-
1752
- [data-theme="bumblebee"] .success-btn {
1753
- background: #f59e0b !important;
1754
- color: #ffffff !important;
1755
- }
1756
-
1757
- [data-theme="garden"] .success-btn {
1758
- background: #10b981 !important;
1759
- color: #ffffff !important;
1760
- }
1761
-
1762
- [data-theme="emerald"] .success-btn {
1763
- background: #10b981 !important;
1764
- color: #ffffff !important;
1765
- }
1766
-
1767
- [data-theme="corporate"] .success-btn {
1768
- background: #10b981 !important;
1769
- color: #ffffff !important;
1770
- }
1771
-
1772
- [data-theme="forest"] .success-btn {
1773
- background: #10b981 !important;
1774
- color: #ffffff !important;
1775
- }
1776
-
1777
- [data-theme="halloween"] .success-btn {
1778
- background: #ff7b00 !important;
1779
- color: #000000 !important;
1780
- }
1781
-
1782
- [data-theme="synthwave"] .success-btn {
1783
- background: #00ff41 !important;
1784
- color: #000000 !important;
1785
- }
1786
-
1787
- [data-theme="dracula"] .success-btn {
1788
- background: #50fa7b !important;
1789
- color: #000000 !important;
1790
- }
1791
-
1792
- [data-theme="luxury"] .success-btn {
1793
- background: #d4af37 !important;
1794
- color: #000000 !important;
1795
- }
1796
-
1797
- [data-theme="night"] .success-btn {
1798
- background: #22d3ee !important;
1799
- color: #ffffff !important;
1800
- }
1801
-
1802
- [data-theme="light"] .success-btn {
1803
- background: #10b981 !important;
1804
- color: #ffffff !important;
1805
- }
1806
-
1807
- [data-theme="cupcake"] .success-btn {
1808
- background: #f472b6 !important;
1809
- color: #ffffff !important;
1810
- }
1811
-
1812
- [data-theme="retro"] .success-btn {
1813
- background: #d4a574 !important;
1814
- color: #ffffff !important;
1815
- }
1816
-
1817
- [data-theme="aqua"] .success-btn {
1818
- background: #06b6d4 !important;
1819
- color: #ffffff !important;
1820
- }
1821
-
1822
- [data-theme="lofi"] .success-btn {
1823
- background: #10b981 !important;
1824
- color: #ffffff !important;
1825
- }
1826
-
1827
- [data-theme="pastel"] .success-btn {
1828
- background: #34d399 !important;
1829
- color: #ffffff !important;
1830
- }
1831
-
1832
- [data-theme="fantasy"] .success-btn {
1833
- background: #f472b6 !important;
1834
- color: #ffffff !important;
1835
- }
1836
-
1837
- [data-theme="wireframe"] .success-btn {
1838
- background: #dfdfdf !important;
1839
- color: #000000 !important;
1840
- border: 1px solid #000000 !important;
1841
- }
1842
-
1843
- [data-theme="black"] .success-btn {
1844
- background: #10b981 !important;
1845
- color: #ffffff !important;
1846
- }
1847
-
1848
- [data-theme="cmyk"] .success-btn {
1849
- background: #06b6d4 !important;
1850
- color: #ffffff !important;
1851
- }
1852
-
1853
- [data-theme="autumn"] .success-btn {
1854
- background: #d97706 !important;
1855
- color: #ffffff !important;
1856
- }
1857
-
1858
- [data-theme="business"] .success-btn {
1859
- background: #10b981 !important;
1860
- color: #ffffff !important;
1861
- }
1862
-
1863
- [data-theme="acid"] .success-btn {
1864
- background: #84cc16 !important;
1865
- color: #000000 !important;
1866
- }
1867
-
1868
- [data-theme="lemonade"] .success-btn {
1869
- background: #22c55e !important;
1870
- color: #ffffff !important;
1871
- }
1872
-
1873
- [data-theme="coffee"] .success-btn {
1874
- background: #a0522d !important;
1875
- color: #ffffff !important;
1876
- }
1877
-
1878
- [data-theme="winter"] .success-btn {
1879
- background: #3b82f6 !important;
1880
- color: #ffffff !important;
1881
- }
1882
- .download-limiter-signout-btn {
1883
- background: #dc3545;
1884
- color: white;
1885
- border: none;
1886
- padding: 6px 12px;
1887
- border-radius: 4px;
1888
- font-size: 12px;
1889
- cursor: pointer;
1890
- margin-left: 8px;
1891
- }
1892
- .download-limiter-premium-badge {
1893
- background: linear-gradient(45deg, #f39c12, #e74c3c);
1894
- color: white;
1895
- padding: 2px 6px;
1896
- border-radius: 3px;
1897
- font-size: 10px;
1898
- margin-left: 8px;
1899
- font-weight: bold;
1900
- }
1901
- .download-limiter-btn-premium {
1902
- opacity: 0.7;
1903
- }
1904
- .download-limiter-success-modal {
1905
- display: none;
1906
- position: fixed;
1907
- top: 0;
1908
- left: 0;
1909
- width: 100%;
1910
- height: 100%;
1911
- background: rgba(0,0,0,0.5);
1912
- z-index: 10000;
1913
- align-items: center;
1914
- justify-content: center;
1915
- }
1916
- .download-limiter-success-modal.show { display: flex; }
1917
- .download-limiter-success-content {
1918
- background: white;
1919
- padding: 2rem;
1920
- border-radius: 8px;
1921
- max-width: 400px;
1922
- text-align: center;
1923
- box-shadow: 0 4px 20px rgba(0,0,0,0.15);
1924
- border-left: 4px solid #38a169;
1925
- }
1926
-
1927
- /* Single upgrade flow styles */
1928
- .single-upgrade-container {
1929
- margin: 20px 0;
1930
- text-align: center;
1931
- }
1932
-
1933
- .single-upgrade-content .upgrade-btn {
1934
- background: linear-gradient(135deg, #059669, #0d9488) !important;
1935
- color: white !important;
1936
- border: none !important;
1937
- padding: 16px 32px !important;
1938
- border-radius: 12px !important;
1939
- font-size: 18px !important;
1940
- font-weight: 600 !important;
1941
- cursor: pointer !important;
1942
- transition: all 0.3s ease !important;
1943
- box-shadow: 0 4px 12px rgba(5, 150, 105, 0.3) !important;
1944
- margin-bottom: 16px !important;
1945
- min-width: 200px !important;
1946
- }
1947
-
1948
- .single-upgrade-content .upgrade-btn:hover {
1949
- background: linear-gradient(135deg, #047857, #0f766e) !important;
1950
- transform: translateY(-2px) !important;
1951
- box-shadow: 0 6px 20px rgba(5, 150, 105, 0.4) !important;
1952
- }
1953
-
1954
- .single-upgrade-content .upgrade-description {
1955
- font-size: 14px !important;
1956
- color: #6b7280 !important;
1957
- margin: 12px 0 0 0 !important;
1958
- line-height: 1.5 !important;
1959
- max-width: 300px !important;
1960
- margin-left: auto !important;
1961
- margin-right: auto !important;
1962
- }
1963
-
1964
- /* Anonymous user usage count styles */
1965
- .lead-fast-anonymous-status {
1966
- display: flex;
1967
- align-items: center;
1968
- gap: 12px;
1969
- }
1970
-
1971
- .lead-fast-anonymous-status .lead-fast-count {
1972
- background: rgba(59, 130, 246, 0.1);
1973
- color: #1d4ed8;
1974
- padding: 6px 12px;
1975
- border-radius: 8px;
1976
- font-size: 14px;
1977
- font-weight: 500;
1978
- border: 1px solid rgba(59, 130, 246, 0.2);
1979
- }
1980
-
1981
- /* Loading state styles */
1982
- .lead-fast-loading-status {
1983
- display: flex;
1984
- align-items: center;
1985
- gap: 10px;
1986
- }
1987
-
1988
- .lead-fast-spinner {
1989
- width: 20px;
1990
- height: 20px;
1991
- color: #3b82f6;
1992
- }
1993
-
1994
- .lead-fast-loading-text {
1995
- font-size: 14px;
1996
- color: #6b7280;
1997
- font-weight: 500;
1998
- }
1999
-
2000
- /* Success button theming */
2001
- .download-limiter-btn.success-btn {
2002
- background: #059669 !important;
2003
- color: white !important;
2004
- border: none !important;
2005
- padding: 12px 24px !important;
2006
- border-radius: 8px !important;
2007
- cursor: pointer !important;
2008
- margin-top: 20px !important;
2009
- font-size: 16px !important;
2010
- font-weight: 500 !important;
2011
- transition: all 0.2s ease !important;
2012
- }
2013
-
2014
- .download-limiter-btn.success-btn:hover {
2015
- background: #047857 !important;
2016
- transform: translateY(-1px) !important;
2017
- }
2018
-
2019
- /* Theme-specific success button colors */
2020
- [data-theme="cyberpunk"] .download-limiter-btn.success-btn {
2021
- background: #0ea5e9 !important;
2022
- box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3) !important;
2023
- }
2024
-
2025
- [data-theme="cyberpunk"] .download-limiter-btn.success-btn:hover {
2026
- background: #0284c7 !important;
2027
- }
2028
-
2029
- [data-theme="valentine"] .download-limiter-btn.success-btn {
2030
- background: #be185d !important;
2031
- }
2032
-
2033
- [data-theme="valentine"] .download-limiter-btn.success-btn:hover {
2034
- background: #9d174d !important;
2035
- }
2036
-
2037
- [data-theme="bumblebee"] .download-limiter-btn.success-btn {
2038
- background: #f59e0b !important;
2039
- }
2040
-
2041
- [data-theme="bumblebee"] .download-limiter-btn.success-btn:hover {
2042
- background: #d97706 !important;
2043
- }
2044
-
2045
- [data-theme="garden"] .download-limiter-btn.success-btn {
2046
- background: #16a34a !important;
2047
- }
2048
-
2049
- [data-theme="garden"] .download-limiter-btn.success-btn:hover {
2050
- background: #15803d !important;
2051
- }
2052
-
2053
- /* Google Sign-in button theming */
2054
- .download-limiter-btn.google-signin-btn {
2055
- background: #4285f4 !important;
2056
- color: white !important;
2057
- border: none !important;
2058
- padding: 12px 24px !important;
2059
- border-radius: 8px !important;
2060
- cursor: pointer !important;
2061
- margin-right: 10px !important;
2062
- display: inline-flex !important;
2063
- align-items: center !important;
2064
- gap: 8px !important;
2065
- font-size: 14px !important;
2066
- font-weight: 500 !important;
2067
- transition: all 0.2s ease !important;
2068
- }
2069
-
2070
- .download-limiter-btn.google-signin-btn:hover {
2071
- background: #3367d6 !important;
2072
- transform: translateY(-1px) !important;
2073
- }
2074
-
2075
- /* Upgrade button theming */
2076
- .download-limiter-btn.upgrade-btn {
2077
- background: #059669 !important;
2078
- color: white !important;
2079
- border: none !important;
2080
- padding: 12px 24px !important;
2081
- border-radius: 8px !important;
2082
- cursor: pointer !important;
2083
- margin-right: 10px !important;
2084
- font-size: 16px !important;
2085
- font-weight: 500 !important;
2086
- transition: all 0.2s ease !important;
2087
- }
2088
-
2089
- .download-limiter-btn.upgrade-btn:hover {
2090
- background: #047857 !important;
2091
- transform: translateY(-1px) !important;
2092
- }
2093
-
2094
- /* Theme-specific button colors */
2095
- [data-theme="cyberpunk"] .download-limiter-btn.upgrade-btn {
2096
- background: #0ea5e9 !important;
2097
- box-shadow: 0 4px 12px rgba(14, 165, 233, 0.3) !important;
2098
- }
2099
-
2100
- [data-theme="valentine"] .download-limiter-btn.upgrade-btn {
2101
- background: #be185d !important;
2102
- }
2103
-
2104
- [data-theme="bumblebee"] .download-limiter-btn.upgrade-btn {
2105
- background: #f59e0b !important;
2106
- }
2107
-
2108
- [data-theme="garden"] .download-limiter-btn.upgrade-btn {
2109
- background: #16a34a !important;
2110
- }
2111
-
2112
- /* Cancel button container and styling - positioned at very bottom */
2113
- .download-limiter-cancel-container {
2114
- margin-top: 30px !important;
2115
- padding-top: 20px !important;
2116
- border-top: 1px solid rgba(0, 0, 0, 0.1) !important;
2117
- text-align: center !important;
2118
- position: relative !important;
2119
- bottom: 0 !important;
2120
- }
2121
-
2122
- .download-limiter-btn.cancel-btn {
2123
- background: transparent !important;
2124
- color: #6b7280 !important;
2125
- border: none !important;
2126
- padding: 8px 16px !important;
2127
- border-radius: 6px !important;
2128
- cursor: pointer !important;
2129
- font-size: 13px !important;
2130
- font-weight: 400 !important;
2131
- transition: all 0.2s ease !important;
2132
- text-decoration: underline !important;
2133
- margin: 0 auto !important;
2134
- display: block !important;
2135
- }
2136
-
2137
- .download-limiter-btn.cancel-btn:hover {
2138
- color: #374151 !important;
2139
- background: rgba(107, 114, 128, 0.1) !important;
2140
- text-decoration: none !important;
2141
- }
2142
-
2143
- /* Theme-specific cancel button border */
2144
- [data-theme="dark"] .download-limiter-cancel-container {
2145
- border-top-color: rgba(255, 255, 255, 0.1) !important;
2146
- }
2147
-
2148
- [data-theme="dark"] .download-limiter-btn.cancel-btn {
2149
- color: #9ca3af !important;
2150
- }
2151
-
2152
- [data-theme="dark"] .download-limiter-btn.cancel-btn:hover {
2153
- color: #d1d5db !important;
2154
- background: rgba(156, 163, 175, 0.1) !important;
2155
- }
2156
-
2157
- [data-theme="cyberpunk"] .download-limiter-cancel-container {
2158
- border-top-color: rgba(14, 165, 233, 0.2) !important;
2159
- }
2160
-
2161
- [data-theme="cyberpunk"] .download-limiter-btn.cancel-btn {
2162
- color: #0ea5e9 !important;
2163
- }
2164
-
2165
- [data-theme="cyberpunk"] .download-limiter-btn.cancel-btn:hover {
2166
- color: #38bdf8 !important;
2167
- background: rgba(14, 165, 233, 0.1) !important;
2168
- }
2169
- `;
2170
- document.head.appendChild(styles);
2171
-
2172
- }
2173
-
2174
- private injectDaisyUI(): void {
2175
- //console.log('🎨 [THEME DEBUG] injectDaisyUI called');
2176
- //console.log('🎨 [THEME DEBUG] Theme config:', this.config.theme);
2177
-
2178
- // Check if DaisyUI is already loaded
2179
- const existingLink = document.querySelector('link[href*="daisyui"]');
2180
- if (existingLink) {
2181
- //console.log('🎨 [THEME DEBUG] DaisyUI already exists:', existingLink);
2182
- // Apply theme if DaisyUI already exists
2183
- if (this.config.theme?.name) {
2184
- const themeName = this.config.theme.name.toLowerCase();
2185
- //console.log('🎨 [THEME DEBUG] Setting existing theme:', themeName);
2186
- document.documentElement.setAttribute('data-theme', themeName);
2187
- //console.log('🎨 [THEME DEBUG] Current data-theme attribute:', document.documentElement.getAttribute('data-theme'));
2188
- }
2189
- return;
2190
- }
2191
-
2192
- //console.log('🎨 [THEME DEBUG] No existing DaisyUI found, injecting...');
2193
-
2194
- // Note: Tailwind CSS is not needed as we use custom CSS for all styling
2195
-
2196
- // Apply theme directly using our custom CSS - no external dependencies needed
2197
- if (this.config.theme?.name) {
2198
- const themeName = this.config.theme.name.toLowerCase();
2199
- document.documentElement.setAttribute('data-theme', themeName);
2200
-
2201
- // Update status displays immediately since no CSS loading is needed
2202
- this.updateStatusDisplays();
2203
- }
2204
- }
2205
-
2206
- private createPaywallModal(): void {
2207
- if (document.getElementById('download-limiter-paywall')) return;
2208
-
2209
- const modal = document.createElement('div');
2210
- modal.id = 'download-limiter-paywall';
2211
- modal.className = 'download-limiter-modal';
2212
- modal.innerHTML = `
2213
- <div class="download-limiter-content">
2214
- <h3 id="download-limiter-paywall-title">Usage Limit Reached</h3>
2215
- <p id="download-limiter-paywall-subtitle">You've used all your free attempts. Upgrade to premium for unlimited usage!</p>
2216
-
2217
- <!-- Auth Section (shows when not signed in) -->
2218
- <div id="download-limiter-auth-section" style="margin: 20px 0;">
2219
- <p>Sign in to continue or upgrade to premium</p>
2220
- <button id="download-limiter-signin-btn" class="download-limiter-btn google-signin-btn">
2221
- <svg width="18" height="18" viewBox="0 0 18 18" fill="none">
2222
- <path d="M16.51 8H8.98v3h4.3c-.18 1-.74 1.48-1.6 2.04v2.01h2.6a8.8 8.8 0 0 0 2.38-5.88c0-.57-.05-.66-.15-1.18z" fill="white"/>
2223
- <path d="M8.98 17c2.16 0 3.97-.72 5.3-1.94l-2.6-2.04a4.8 4.8 0 0 1-2.7.75 4.8 4.8 0 0 1-4.52-3.4H1.83v2.07A8 8 0 0 0 8.98 17z" fill="white"/>
2224
- <path d="M4.46 10.37a4.8 4.8 0 0 1-.25-1.37c0-.48.09-.94.25-1.37V5.56H1.83a8 8 0 0 0 0 6.88l2.63-2.07z" fill="white"/>
2225
- <path d="M8.98 3.77c1.32 0 2.5.45 3.44 1.35l2.58-2.58C13.94.64 11.66 0 8.98 0A8 8 0 0 0 1.83 5.56l2.63 2.07c.61-1.8 2.26-3.86 4.52-3.86z" fill="white"/>
2226
- </svg>
2227
- Sign in with Google
2228
- </button>
2229
- </div>
2230
-
2231
- <!-- Payment Section (shows when signed in) -->
2232
- <div id="download-limiter-payment-section" style="margin: 20px 0; display: none;">
2233
- <button id="download-limiter-upgrade-btn" class="download-limiter-btn upgrade-btn">
2234
- Upgrade to Premium
2235
- </button>
2236
- </div>
2237
-
2238
- <div class="download-limiter-cancel-container">
2239
- <button id="download-limiter-close-btn" class="download-limiter-btn cancel-btn">
2240
- Cancel
2241
- </button>
2242
- </div>
2243
- </div>
2244
- `;
2245
- document.body.appendChild(modal);
2246
-
2247
- // Set up event handlers
2248
- modal.querySelector('#download-limiter-signin-btn')!.addEventListener('click', async () => {
2249
- await this.signIn();
2250
- });
2251
-
2252
- modal.querySelector('#download-limiter-upgrade-btn')!.addEventListener('click', async () => {
2253
- const payment = await this.createPayment();
2254
- if (payment?.checkout_url) {
2255
- window.location.href = payment.checkout_url;
2256
- }
2257
- });
2258
-
2259
- modal.querySelector('#download-limiter-close-btn')!.addEventListener('click', () => {
2260
- if (this.config.options?.debug) {
2261
- console.log('🔍 DEBUG: Cancel button clicked');
2262
- console.log('🔍 DEBUG: this.config.feedback:', this.config.feedback);
2263
- console.log('🔍 DEBUG: this.config.email:', this.config.email);
2264
- console.log('🔍 DEBUG: Feedback config exists:', !!(this.config.feedback || this.config.email));
2265
- }
2266
-
2267
- // Show feedback form if feedback config exists, otherwise just close
2268
- if (this.config.feedback || this.config.email) {
2269
- if (this.config.options?.debug) {
2270
- console.log('🔍 DEBUG: Showing feedback form');
2271
- }
2272
- this.showFeedbackForm();
2273
- } else {
2274
- if (this.config.options?.debug) {
2275
- console.log('🔍 DEBUG: No email config, just closing modal');
2276
- }
2277
- modal.classList.remove('show');
2278
- }
2279
- });
2280
-
2281
- // Removed click-outside-to-close behavior to encourage users to use the Cancel button
2282
- // which triggers the feedback form. This improves feedback collection.
2283
- }
2284
-
2285
- private createSuccessModal(): void {
2286
- if (document.getElementById('download-limiter-success')) return;
2287
-
2288
- const modal = document.createElement('div');
2289
- modal.id = 'download-limiter-success';
2290
- modal.className = 'download-limiter-modal'; // Use same modal class as paywall
2291
- modal.innerHTML = `
2292
- <div class="download-limiter-content"> <!-- Use same content class as paywall for theming -->
2293
- <h3 id="download-limiter-success-title">Action Started!</h3>
2294
- <p id="download-limiter-success-message">Your action completed successfully!</p>
2295
- <button id="download-limiter-success-close" class="download-limiter-btn success-btn">
2296
- OK
2297
- </button>
2298
- </div>
2299
- `;
2300
- document.body.appendChild(modal);
2301
-
2302
- // Set up event handlers
2303
- modal.querySelector('#download-limiter-success-close')!.addEventListener('click', () => {
2304
- modal.classList.remove('show');
2305
- });
2306
-
2307
- modal.addEventListener('click', (e) => {
2308
- if (e.target === modal) {
2309
- modal.classList.remove('show');
2310
- }
2311
- });
2312
- }
2313
-
2314
- private showFeedbackForm(): void {
2315
- // const feedbackStartTime = Date.now();
2316
- // console.log(`🕐 [FEEDBACK] showFeedbackForm called: ${new Date(feedbackStartTime).toISOString()}`);
2317
-
2318
- // Hide paywall first
2319
- // const paywallHideStart = Date.now();
2320
- const paywall = document.getElementById('download-limiter-paywall');
2321
- if (paywall) {
2322
- paywall.classList.remove('show');
2323
- // console.log(`🕐 [FEEDBACK] Paywall hidden: ${Date.now() - paywallHideStart}ms`);
2324
- }
2325
-
2326
- // Create or show feedback modal
2327
- // const createFeedbackStart = Date.now();
2328
- this.createFeedbackModal();
2329
- // console.log(`🕐 [FEEDBACK] createFeedbackModal completed: ${Date.now() - createFeedbackStart}ms`);
2330
-
2331
- const modal = document.getElementById('download-limiter-feedback');
2332
- if (modal) {
2333
- modal.classList.add('show');
2334
- // console.log(`🕐 [FEEDBACK] Feedback modal shown: ${Date.now() - feedbackStartTime}ms total`);
2335
- } else {
2336
- // console.log(`🕐 [FEEDBACK] ERROR - Feedback modal not found after ${Date.now() - feedbackStartTime}ms`);
2337
- }
2338
- }
2339
-
2340
- private createFeedbackModal(): void {
2341
- if (document.getElementById('download-limiter-feedback')) {
2342
- if (this.config.options?.debug) {
2343
- console.log('🔍 DEBUG: Feedback modal already exists');
2344
- }
2345
- return;
2346
- }
2347
-
2348
- // Get feedback configuration or fallback to legacy email config
2349
- const feedbackConfig = this.config.feedback || (this.config.email ? {
2350
- form: {
2351
- title: 'Quick Feedback',
2352
- description: 'Why didn\'t you upgrade?',
2353
- option1: 'Not useful for my needs',
2354
- option2: 'Didn\'t find what I was looking for',
2355
- option3: 'Just trying it out'
2356
- },
2357
- email: this.config.email
2358
- } : null);
2359
-
2360
- if (this.config.options?.debug) {
2361
- console.log('🔍 DEBUG: Feedback config:', feedbackConfig);
2362
- console.log('🔍 DEBUG: this.config.feedback:', this.config.feedback);
2363
- console.log('🔍 DEBUG: this.config.email:', this.config.email);
2364
- }
2365
-
2366
- if (!feedbackConfig) {
2367
- if (this.config.options?.debug) {
2368
- console.log('🔍 DEBUG: No feedback config found, not creating modal');
2369
- }
2370
- return;
2371
- }
2372
-
2373
- const modal = document.createElement('div');
2374
- modal.id = 'download-limiter-feedback';
2375
- modal.className = 'download-limiter-modal';
2376
- modal.innerHTML = `
2377
- <div class="download-limiter-content">
2378
- <h3>${feedbackConfig.form.title}</h3>
2379
- <p style="margin-bottom: 20px;">${feedbackConfig.form.description}</p>
2380
-
2381
- <form id="feedback-form" style="text-align: left;">
2382
- <div style="margin-bottom: 15px;">
2383
- <label style="display: block; margin-bottom: 8px;">
2384
- <input type="radio" name="reason" value="option1" style="margin-right: 8px;">
2385
- ${feedbackConfig.form.option1}
2386
- </label>
2387
- <label style="display: block; margin-bottom: 8px;">
2388
- <input type="radio" name="reason" value="option2" style="margin-right: 8px;">
2389
- ${feedbackConfig.form.option2}
2390
- </label>
2391
- <label style="display: block; margin-bottom: 8px;">
2392
- <input type="radio" name="reason" value="option3" style="margin-right: 8px;">
2393
- ${feedbackConfig.form.option3}
2394
- </label>
2395
- </div>
2396
-
2397
- <div style="margin-bottom: 15px;">
2398
- <label for="feedback-details" style="display: block; margin-bottom: 5px;">Tell us more:</label>
2399
- <textarea
2400
- id="feedback-details"
2401
- name="details"
2402
- rows="3"
2403
- style="width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px;"
2404
- placeholder="Your feedback helps us improve..." maxlength="200"></textarea>
2405
- </div>
2406
-
2407
- <div style="margin-bottom: 20px;">
2408
- <label for="feedback-email" style="display: block; margin-bottom: 5px;">
2409
- Email (optional):
2410
- </label>
2411
- <input
2412
- type="email"
2413
- id="feedback-email"
2414
- name="email"
2415
- style="width: 100%; padding: 8px; border: 1px solid #ddd; border-radius: 4px;"
2416
- placeholder="your@email.com">
2417
- <small style="color: #666; display: block; margin-top: 4px;">
2418
- Only if you want us to reach out about what you mentioned above. We don't follow up unless you want us to
2419
- </small>
2420
- </div>
2421
-
2422
-
2423
- <div style="text-align: center;">
2424
- <button type="submit" class="download-limiter-btn success-btn" style="margin-right: 10px;">
2425
- Submit Feedback
2426
- </button>
2427
- <button type="button" id="feedback-skip-btn" class="download-limiter-btn cancel-btn">
2428
- Skip
2429
- </button>
2430
- </div>
2431
- </form>
2432
- </div>
2433
- `;
2434
-
2435
- document.body.appendChild(modal);
2436
-
2437
- if (this.config.options?.debug) {
2438
- console.log('🔍 DEBUG: Feedback modal created and added to DOM');
2439
- }
2440
-
2441
- // Set up event listeners
2442
- const form = modal.querySelector('#feedback-form') as HTMLFormElement;
2443
- form.addEventListener('submit', (e) => {
2444
- e.preventDefault();
2445
- this.submitFeedback(form);
2446
- });
2447
-
2448
- modal.querySelector('#feedback-skip-btn')!.addEventListener('click', () => {
2449
- modal.classList.remove('show');
2450
- });
2451
-
2452
- modal.addEventListener('click', (e) => {
2453
- if (e.target === modal) {
2454
- modal.classList.remove('show');
2455
- }
2456
- });
2457
- }
2458
-
2459
- private async submitFeedback(form: HTMLFormElement): Promise<void> {
2460
- const formData = new FormData(form);
2461
- const reason = formData.get('reason') as string;
2462
- const details = formData.get('details') as string;
2463
- const email = formData.get('email') as string;
2464
-
2465
- if (!reason) {
2466
- alert('Please select a reason');
2467
- return;
2468
- }
2469
-
2470
- const feedbackData = {
2471
- reason,
2472
- details,
2473
- email: email || undefined,
2474
- timestamp: new Date().toISOString(),
2475
- userAgent: navigator.userAgent,
2476
- appId: this.config.appId
2477
- };
2478
-
2479
- try {
2480
- await this.sendFeedbackEmail(feedbackData);
2481
-
2482
- // Close feedback modal
2483
- const modal = document.getElementById('download-limiter-feedback');
2484
- if (modal) {
2485
- modal.classList.remove('show');
2486
- }
2487
-
2488
- // Show thank you message
2489
- alert('Thank you for your feedback!');
2490
- } catch (error) {
2491
- console.error('Failed to send feedback:', error);
2492
- alert('Failed to send feedback. Please try again.');
2493
- }
2494
- }
2495
-
2496
- private async sendFeedbackEmail(feedbackData: any): Promise<void> {
2497
- // Get email config - handle both new array format and legacy format
2498
- let emailConfig;
2499
- if (this.config.feedback?.email) {
2500
- // New array format - use first provider (typically resend)
2501
- if (Array.isArray(this.config.feedback.email)) {
2502
- emailConfig = this.config.feedback.email[0];
2503
- } else {
2504
- // Legacy format fallback
2505
- emailConfig = this.config.feedback.email as any;
2506
- }
2507
- } else if (this.config.email) {
2508
- // Deprecated legacy email config
2509
- emailConfig = {
2510
- provider: 'resend',
2511
- apiKey: (this.config.email as any).resendApiKey,
2512
- fromEmail: (this.config.email as any).fromEmail
2513
- };
2514
- }
2515
-
2516
- if (!emailConfig) {
2517
- throw new Error('Email configuration not available');
2518
- }
2519
-
2520
- const emailBody = `
2521
- New Feedback from ${this.config.appId}
2522
-
2523
- Reason: ${feedbackData.reason}
2524
- Details: ${feedbackData.details}
2525
- User Email: ${feedbackData.email || 'Not provided'}
2526
- Timestamp: ${feedbackData.timestamp}
2527
- User Agent: ${feedbackData.userAgent}
2528
- `.trim();
2529
-
2530
- // Handle different email providers
2531
- let response;
2532
- if (emailConfig.provider === 'resend' || !emailConfig.provider) {
2533
- response = await fetch('https://api.resend.com/emails', {
2534
- method: 'POST',
2535
- headers: {
2536
- 'Content-Type': 'application/json',
2537
- 'Authorization': `Bearer ${emailConfig.apiKey || (emailConfig as any).resendApiKey}`
2538
- },
2539
- body: JSON.stringify({
2540
- from: emailConfig.fromEmail,
2541
- to: [emailConfig.fromEmail], // Send feedback to yourself
2542
- subject: `Feedback from ${this.config.appId}`,
2543
- text: emailBody
2544
- })
2545
- });
2546
- } else {
2547
- throw new Error(`Unsupported email provider: ${emailConfig.provider}`);
2548
- }
2549
-
2550
- if (!response.ok) {
2551
- throw new Error(`Email API error: ${response.status}`);
2552
- }
2553
- }
2554
-
2555
- private createAuthUI(): void {
2556
- if (document.getElementById('lead-fast-profile')) return;
2557
-
2558
- const profileContainer = document.createElement('div');
2559
- profileContainer.id = 'lead-fast-profile';
2560
- profileContainer.className = 'lead-fast-profile';
2561
- document.body.appendChild(profileContainer);
2562
- }
2563
-
2564
- private createStatusDisplay(): void {
2565
- if (document.getElementById('download-limiter-status')) return;
2566
-
2567
- const statusDiv = document.createElement('div');
2568
- statusDiv.id = 'download-limiter-status';
2569
- statusDiv.className = 'download-limiter-status';
2570
- document.body.appendChild(statusDiv);
2571
- }
2572
-
2573
- private createGlobalStatusDisplay(): void {
2574
- this.createStatusDisplay();
2575
- }
2576
-
2577
-
2578
- private showPaywallInstant(status: DownloadStatus): void {
2579
- // const showStartTime = Date.now();
2580
- // console.log(`🕐 [MODAL] showPaywallInstant started: ${new Date(showStartTime).toISOString()}`);
2581
-
2582
- // Ensure modal exists before trying to show it
2583
- // const createStartTime = Date.now();
2584
- this.createPaywallModal();
2585
- // console.log(`🕐 [MODAL] createPaywallModal completed: ${Date.now() - createStartTime}ms`);
2586
-
2587
- const modal = document.getElementById('download-limiter-paywall');
2588
- if (modal) {
2589
- // console.log(`🕐 [MODAL] Modal found in DOM: ${Date.now() - showStartTime}ms`);
2590
-
2591
- // Update paywall title with exact count (no API call needed)
2592
- const titleEl = modal.querySelector('#download-limiter-paywall-title');
2593
- if (titleEl) {
2594
- titleEl.textContent = `You've used ${status.limit} free attempts`;
2595
- // console.log(`🕐 [MODAL] Title updated: ${Date.now() - showStartTime}ms`);
2596
- }
2597
-
2598
- // Show appropriate section based on auth state
2599
- const authSection = modal.querySelector('#download-limiter-auth-section') as HTMLElement;
2600
- const paymentSection = modal.querySelector('#download-limiter-payment-section') as HTMLElement;
2601
-
2602
- if (!this.currentUser) {
2603
- // console.log(`🕐 [MODAL] Setting up anonymous user flow: ${Date.now() - showStartTime}ms`);
2604
- // Anonymous user - show single upgrade flow
2605
- const subtitleEl = modal.querySelector('#download-limiter-paywall-subtitle');
2606
- if (subtitleEl) {
2607
- subtitleEl.textContent = 'Sign in to continue. If you\'re already premium, you\'ll get unlimited access. New users can upgrade after signing in.';
2608
- }
2609
-
2610
- // Hide separate auth/payment sections and show single upgrade button
2611
- authSection.style.display = 'none';
2612
- paymentSection.style.display = 'none';
2613
-
2614
- // Show single upgrade button
2615
- // const upgradeStartTime = Date.now();
2616
- this.showSingleUpgradeFlow(modal);
2617
- // console.log(`🕐 [MODAL] Single upgrade flow setup: ${Date.now() - upgradeStartTime}ms`);
2618
- } else {
2619
- // console.log(`🕐 [MODAL] Setting up signed-in user flow: ${Date.now() - showStartTime}ms`);
2620
- // Existing flow for signed-in users - direct to payment
2621
- authSection.style.display = 'none';
2622
- paymentSection.style.display = 'block';
2623
- }
2624
-
2625
- modal.classList.add('show');
2626
- // console.log(`🕐 [MODAL] Modal shown (classList.add('show')): ${Date.now() - showStartTime}ms`);
2627
- } else {
2628
- // console.log(`🕐 [MODAL] ERROR: Modal not found in DOM after creation: ${Date.now() - showStartTime}ms`);
2629
- }
2630
- }
2631
-
2632
- private async showPaywall(): Promise<void> {
2633
- // Get current status if not cached
2634
- const status = await this.getDownloadStatus();
2635
- this.showPaywallInstant(status);
2636
- }
2637
-
2638
- private showSingleUpgradeFlow(modal: HTMLElement): void {
2639
- // Create single upgrade button that handles both login and payment
2640
- let upgradeContainer = modal.querySelector('.single-upgrade-container') as HTMLElement;
2641
-
2642
- if (!upgradeContainer) {
2643
- upgradeContainer = document.createElement('div');
2644
- upgradeContainer.className = 'single-upgrade-container';
2645
- upgradeContainer.innerHTML = `
2646
- <div class="single-upgrade-content">
2647
- <button class="download-limiter-btn upgrade-btn" id="single-upgrade-btn">
2648
- Continue with Google
2649
- </button>
2650
- <!--<p class="upgrade-description">
2651
- Sign in to restore access. Premium members get unlimited usage immediately.
2652
- </p>-->
2653
- </div>
2654
- `;
2655
- // Insert before the cancel container to keep cancel at the bottom
2656
- const cancelContainer = modal.querySelector('.download-limiter-cancel-container');
2657
- if (cancelContainer) {
2658
- modal.querySelector('.download-limiter-content')?.insertBefore(upgradeContainer, cancelContainer);
2659
- } else {
2660
- modal.querySelector('.download-limiter-content')?.appendChild(upgradeContainer);
2661
- }
2662
- }
2663
-
2664
- upgradeContainer.style.display = 'block';
2665
-
2666
- // Add click handler for single upgrade flow
2667
- const upgradeBtn = modal.querySelector('#single-upgrade-btn');
2668
- if (upgradeBtn) {
2669
- upgradeBtn.replaceWith(upgradeBtn.cloneNode(true)); // Remove existing listeners
2670
- const newUpgradeBtn = modal.querySelector('#single-upgrade-btn');
2671
-
2672
- newUpgradeBtn?.addEventListener('click', async () => {
2673
- try {
2674
- // Step 1: Sign in with Google
2675
- const { error } = await this.supabase.auth.signInWithOAuth({
2676
- provider: 'google',
2677
- options: {
2678
- redirectTo: `${window.location.origin}${window.location.pathname}?upgrade=true`
2679
- }
2680
- });
2681
-
2682
- if (error) {
2683
- console.error('Sign in error:', error);
2684
- this.showError('Sign In Failed', 'Failed to sign in with Google. Please try again.');
2685
- }
2686
- // OAuth will redirect, so no further action needed here
2687
- } catch (error) {
2688
- console.error('Upgrade flow error:', error);
2689
- this.showError('Upgrade Failed', 'Failed to start upgrade process. Please try again.');
2690
- }
2691
- });
2692
- }
2693
- }
2694
-
2695
-
2696
- private showSuccess(title: string, message: string): void {
2697
- const modal = document.getElementById('download-limiter-success');
2698
- if (modal) {
2699
- const titleEl = modal.querySelector('#download-limiter-success-title');
2700
- const messageEl = modal.querySelector('#download-limiter-success-message');
2701
-
2702
- if (titleEl) titleEl.textContent = title;
2703
- if (messageEl) messageEl.textContent = message;
2704
-
2705
- modal.classList.add('show');
2706
-
2707
- // No auto-hide - let user dismiss manually
2708
- }
2709
- }
2710
-
2711
- private showError(title: string, message: string): void {
2712
- // Create a clean error toast instead of alert
2713
- const toast = document.createElement('div');
2714
- toast.style.cssText = `
2715
- position: fixed;
2716
- top: 20px;
2717
- right: 20px;
2718
- background: #fee2e2;
2719
- border: 1px solid #fecaca;
2720
- color: #dc2626;
2721
- padding: 12px 16px;
2722
- border-radius: 8px;
2723
- font-size: 14px;
2724
- font-weight: 500;
2725
- line-height: 1.4;
2726
- max-width: 300px;
2727
- box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
2728
- z-index: 10000;
2729
- font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
2730
- `;
2731
-
2732
- toast.innerHTML = `
2733
- <div style="font-weight: 600; margin-bottom: 4px;">${title}</div>
2734
- <div style="font-size: 13px; opacity: 0.9;">${message}</div>
2735
- `;
2736
-
2737
- document.body.appendChild(toast);
2738
-
2739
- // Auto-remove after 5 seconds
2740
- setTimeout(() => {
2741
- if (toast.parentNode) {
2742
- toast.parentNode.removeChild(toast);
2743
- }
2744
- }, 5000);
2745
-
2746
- // Click to dismiss
2747
- toast.addEventListener('click', () => {
2748
- if (toast.parentNode) {
2749
- toast.parentNode.removeChild(toast);
2750
- }
2751
- });
2752
- }
2753
-
2754
- private showConnectionError(): void {
2755
- this.showError(
2756
- 'Connection Error',
2757
- 'Server connection required for download verification. Please check your configuration and try again.'
2758
- );
2759
- }
2760
-
2761
- private showPaymentConfigError(): void {
2762
- this.showError(
2763
- 'Payment Configuration Error',
2764
- 'Payment system is not properly configured. Please contact support.'
2765
- );
2766
- }
2767
-
2768
- private disableDownloadButtons(errorType: 'connection' | 'payment' | 'security_key'): void {
2769
- // Find all buttons that were attached by the library
2770
- const buttons = document.querySelectorAll('[data-leadfast-attached]');
2771
-
2772
- const errorMessages = {
2773
- connection: 'Download disabled: Server connection required',
2774
- payment: 'Download disabled: Payment configuration error',
2775
- security_key: 'Download disabled: Invalid or missing security key'
2776
- };
2777
-
2778
- const statusMessages = {
2779
- connection: '⚠️ Connection Error - Downloads Disabled',
2780
- payment: '⚠️ Payment Config Error - Downloads Disabled',
2781
- security_key: '🔐 Invalid Security Key - Please Update Configuration'
2782
- };
2783
-
2784
- buttons.forEach(button => {
2785
- const btnElement = button as HTMLButtonElement;
2786
- btnElement.disabled = true;
2787
- btnElement.style.opacity = '0.5';
2788
- btnElement.style.cursor = 'not-allowed';
2789
- btnElement.title = errorMessages[errorType];
2790
- });
2791
-
2792
- // Update user section to show error
2793
- const userSection = document.querySelector('.lead-fast-user-section');
2794
- if (userSection) {
2795
- userSection.innerHTML = `
2796
- <div style="
2797
- color: #ef4444;
2798
- padding: 6px 8px;
2799
- font-size: 12px;
2800
- font-weight: 500;
2801
- line-height: 1.2;
2802
- border-radius: 4px;
2803
- background: rgba(239, 68, 68, 0.05);
2804
- border: 1px solid rgba(239, 68, 68, 0.2);
2805
- max-width: 200px;
2806
- text-align: center;
2807
- ">
2808
- ${statusMessages[errorType]}
2809
- </div>
2810
- `;
2811
- }
2812
- }
2813
-
2814
- private async updateStatusDisplays(): Promise<void> {
2815
- //console.log('🎨 [THEME DEBUG] updateStatusDisplays called');
2816
-
2817
- // Check for security key error first (most specific)
2818
- if (this.securityKeyFailed) {
2819
- this.disableDownloadButtons('security_key');
2820
- return;
2821
- }
2822
-
2823
- // If connection failed, disable all download buttons
2824
- if (this.supabaseConnectionFailed) {
2825
- this.disableDownloadButtons('connection');
2826
- return;
2827
- }
2828
-
2829
- // If payment configuration is invalid, disable all download buttons
2830
- if (this.config.payment && this.paymentConnectionFailed) {
2831
- this.disableDownloadButtons('payment');
2832
- return;
2833
- }
2834
-
2835
- // Show loading state
2836
- this.isLoadingStatus = true;
2837
- this.updateUserSection(null); // Show loading UI
2838
-
2839
- const status = await this.getDownloadStatus();
2840
-
2841
- // Clear loading state
2842
- this.isLoadingStatus = false;
2843
-
2844
- // CRITICAL: Check again AFTER API call - flag may have been set during getDownloadStatus
2845
- if (this.securityKeyFailed) {
2846
- this.disableDownloadButtons('security_key');
2847
- return;
2848
- }
2849
-
2850
- if (this.supabaseConnectionFailed) {
2851
- this.disableDownloadButtons('connection');
2852
- return;
2853
- }
2854
-
2855
- this.updateUserSection(status);
2856
- }
2857
-
2858
- private createTitleBar(): void {
2859
- //console.log('🎨 [THEME DEBUG] Creating title bar');
2860
-
2861
- // Create the profile div if it doesn't exist
2862
- let profileDiv = document.getElementById('lead-fast-profile');
2863
- if (!profileDiv) {
2864
- profileDiv = document.createElement('div');
2865
- profileDiv.id = 'lead-fast-profile';
2866
- profileDiv.className = 'lead-fast-profile';
2867
- document.body.appendChild(profileDiv);
2868
- }
2869
-
2870
- // Get title bar configuration
2871
- const titleConfig = this.config.titleBar || {};
2872
- const title = titleConfig.title || 'My App';
2873
- const titleImage = titleConfig.titleImage;
2874
- const links = titleConfig.links || [];
2875
-
2876
- // Always create title bar with logo and navigation
2877
- profileDiv.innerHTML = `
2878
- <div class="lead-fast-title-bar">
2879
- <div class="lead-fast-title-section">
2880
- <a href="#" class="lead-fast-logo">
2881
- ${titleImage ? `<img src="${titleImage}" alt="${title}">` : ''}
2882
- <span>${title}</span>
2883
- </a>
2884
- <nav class="lead-fast-nav">
2885
- ${links.map(link => `
2886
- <a href="${link.url}" class="lead-fast-nav-link" ${link.target ? `target="${link.target}"` : ''}>
2887
- ${link.text}
2888
- </a>
2889
- `).join('')}
2890
- </nav>
2891
- </div>
2892
-
2893
- <div class="lead-fast-user-section" id="lead-fast-user-section">
2894
- <!-- User section will be populated when logged in -->
2895
- </div>
2896
-
2897
- <!-- <a href="https://www.moneyfast.bar" target="_blank" class="lead-fast-branding" style="text-decoration: none; color: inherit;">moneyfast.bar</a>-->
2898
- </div>
2899
- `;
2900
- }
2901
-
2902
- private updateUserSection(status: DownloadStatus | null): void {
2903
- //console.log('🎨 [THEME DEBUG] updateUserSection called');
2904
- //console.log('🎨 [THEME DEBUG] Current data-theme:', document.documentElement.getAttribute('data-theme'));
2905
-
2906
- const userSection = document.getElementById('lead-fast-user-section');
2907
- if (!userSection) {
2908
- //console.log('🎨 [THEME DEBUG] User section not found!');
2909
- return;
2910
- }
2911
-
2912
- // Show loading state if status is null
2913
- if (status === null || this.isLoadingStatus) {
2914
- userSection.innerHTML = `
2915
- <div class="lead-fast-loading-status">
2916
- <svg class="lead-fast-spinner" viewBox="0 0 24 24">
2917
- <circle cx="12" cy="12" r="10" stroke="currentColor" stroke-width="3" fill="none" stroke-dasharray="31.4 31.4" stroke-linecap="round">
2918
- <animateTransform attributeName="transform" type="rotate" from="0 12 12" to="360 12 12" dur="1s" repeatCount="indefinite"/>
2919
- </circle>
2920
- </svg>
2921
- <span class="lead-fast-loading-text">Loading...</span>
2922
- </div>
2923
- `;
2924
- return;
2925
- }
2926
-
2927
- if (this.currentUser) {
2928
- // User is signed in - show user info
2929
- const userInitial = this.currentUser.email.charAt(0).toUpperCase();
2930
- const userEmail = this.currentUser.email;
2931
- const badgeClass = status.isPremium ? 'premium' : 'free';
2932
- const badgeText = status.isPremium ? 'Premium' : 'Free';
2933
- const countText = status.isPremium ? 'Unlimited' : `${status.currentCount}/${status.limit}`;
2934
-
2935
- //console.log('🎨 [THEME DEBUG] Populating user section');
2936
-
2937
- userSection.innerHTML = `
2938
- <div class="lead-fast-avatar">${userInitial}</div>
2939
- <div class="lead-fast-user-info">
2940
- <div class="lead-fast-user-email">${userEmail}</div>
2941
- <div class="lead-fast-user-status">
2942
- <span class="lead-fast-badge ${badgeClass}">${badgeText}</span>
2943
- <span class="lead-fast-count">${countText}</span>
2944
- </div>
2945
- </div>
2946
- <button class="lead-fast-signout">signout</button>
2947
- `;
2948
-
2949
- // Debug CSS variables after updating user section
2950
- const titleBar = document.querySelector('.lead-fast-title-bar') as HTMLElement;
2951
- if (titleBar) {
2952
- const computedStyle = getComputedStyle(titleBar);
2953
- //console.log('🎨 [THEME DEBUG] Title bar background color:', computedStyle.backgroundColor);
2954
- //console.log('🎨 [THEME DEBUG] Title bar border color:', computedStyle.borderColor);
2955
- }
2956
-
2957
- // Add sign out functionality
2958
- const signoutBtn = userSection.querySelector('.lead-fast-signout');
2959
- if (signoutBtn) {
2960
- signoutBtn.addEventListener('click', () => {
2961
- this.signOut();
2962
- });
2963
- }
2964
- } else {
2965
- // Anonymous user - show usage count
2966
- //console.log('🎨 [THEME DEBUG] Showing anonymous user usage count');
2967
- const countText = `Attempts: ${status.currentCount}/${status.limit}`;
2968
- userSection.innerHTML = `
2969
- <div class="lead-fast-anonymous-status">
2970
- <span class="lead-fast-count">${countText}</span>
2971
- </div>
2972
- `;
2973
- }
2974
- }
2975
-
2976
- private setupUIUpdates(): void {
2977
- // Update UI on auth changes
2978
- this.on('authChanged', async () => {
2979
- // Invalidate cache when auth state changes
2980
- // console.log(`🕐 [CACHE] Invalidating cache due to auth change (was: ${this.cachedStatus ? 'cached' : 'null'})`);
2981
- this.cachedStatus = null;
2982
- this.updateStatusDisplays();
2983
-
2984
- // Update paywall display if it's currently shown
2985
- const modal = document.getElementById('download-limiter-paywall');
2986
- if (modal && modal.classList.contains('show')) {
2987
- this.updatePaywallDisplay();
2988
-
2989
- // Auto-redirect to payment after sign-in from paywall (if not already premium)
2990
- if (this.currentUser && this.config.payment) {
2991
- setTimeout(async () => {
2992
- const isPremium = await this.checkPremiumStatus(this.currentUser.email);
2993
- if (!isPremium) {
2994
- // User is not premium, redirect to payment
2995
- const payment = await this.createPayment();
2996
- if (payment?.checkout_url) {
2997
- window.location.href = payment.checkout_url;
2998
- }
2999
- } else {
3000
- // User is already premium, just close paywall and stay on page
3001
- modal.classList.remove('show');
3002
- }
3003
- }, 1000); // Small delay to let UI update
3004
- }
3005
- }
3006
- });
3007
-
3008
- // Update UI on count changes
3009
- this.on('countChanged', () => {
3010
- this.updateStatusDisplays();
3011
- });
3012
-
3013
- // Initial update
3014
- this.updateStatusDisplays();
3015
- }
3016
-
3017
- private updatePaywallDisplay(): void {
3018
- const modal = document.getElementById('download-limiter-paywall');
3019
- if (!modal) return;
3020
-
3021
- const authSection = modal.querySelector('#download-limiter-auth-section') as HTMLElement;
3022
- const paymentSection = modal.querySelector('#download-limiter-payment-section') as HTMLElement;
3023
-
3024
- if (!this.currentUser) {
3025
- // Not signed in - show auth section
3026
- authSection.style.display = 'block';
3027
- paymentSection.style.display = 'none';
3028
- } else {
3029
- // Signed in - show payment section
3030
- authSection.style.display = 'none';
3031
- paymentSection.style.display = 'block';
3032
- }
3033
- }
3034
-
3035
- /**
3036
- * Event listener management
3037
- */
3038
- public on<K extends keyof MoneyBarEvents>(
3039
- event: K,
3040
- listener: (data: MoneyBarEvents[K]) => void
3041
- ): void {
3042
- if (!this.eventListeners.has(event)) {
3043
- this.eventListeners.set(event, []);
3044
- }
3045
- this.eventListeners.get(event)!.push(listener);
3046
- }
3047
-
3048
- public off<K extends keyof MoneyBarEvents>(
3049
- event: K,
3050
- listener: (data: MoneyBarEvents[K]) => void
3051
- ): void {
3052
- const listeners = this.eventListeners.get(event);
3053
- if (listeners) {
3054
- const index = listeners.indexOf(listener);
3055
- if (index > -1) {
3056
- listeners.splice(index, 1);
3057
- }
3058
- }
3059
- }
3060
-
3061
- private emit<K extends keyof MoneyBarEvents>(
3062
- event: K,
3063
- data: MoneyBarEvents[K]
3064
- ): void {
3065
- const listeners = this.eventListeners.get(event);
3066
- if (listeners) {
3067
- listeners.forEach(listener => {
3068
- try {
3069
- listener(data);
3070
- } catch (error) {
3071
- console.error(`Error in ${event} listener:`, error);
3072
- }
3073
- });
3074
- }
3075
- }
3076
-
3077
- private validateConfig(): void {
3078
- if (!this.config.appId) throw new Error('appId is required');
3079
- if (!this.config.supabase?.url) throw new Error('supabase.url is required');
3080
- if (!this.config.supabase?.anonKey) throw new Error('supabase.anonKey is required');
3081
- if (typeof this.config.freeAttemptLimit !== 'number' || this.config.freeAttemptLimit < 0) {
3082
- throw new Error('freeAttemptLimit must be a non-negative number');
3083
- }
3084
- }
3085
-
3086
- private async initializeSupabase(): Promise<void> {
3087
- try {
3088
- this.supabase = createClient(
3089
- this.config.supabase.url,
3090
- this.config.supabase.anonKey
3091
- );
3092
-
3093
- // Skip connection test - we'll detect connection issues during actual API calls
3094
- this.supabaseConnectionFailed = false;
3095
- } catch (error) {
3096
- console.error('Failed to initialize Supabase:', error);
3097
- this.supabaseConnectionFailed = true;
3098
- }
3099
- }
3100
-
3101
- private async initializePayment(): Promise<void> {
3102
- // Skip if no payment configuration
3103
- if (!this.config.payment) {
3104
- return;
3105
- }
3106
-
3107
- // Validate product ID format
3108
- const payment = this.config.payment?.find(p => p.provider === 'dodo');
3109
- if (!payment) {
3110
- this.paymentConnectionFailed = true;
3111
- if (this.config.options?.debug) {
3112
- console.warn('No dodo payment provider configured');
3113
- }
3114
- return;
3115
- }
3116
- const productId = payment.productId;
3117
- if (!productId || !productId.startsWith('pdt_') || productId.length < 10) {
3118
- this.paymentConnectionFailed = true;
3119
- if (this.config.options?.debug) {
3120
- console.warn('Invalid payment product ID format:', productId);
3121
- }
3122
- return;
3123
- }
3124
-
3125
- // For now, skip payment gateway connectivity test
3126
- // Only validate product ID format (which we already did above)
3127
- // In production, you can add actual DodoPayments API test here
3128
- this.paymentConnectionFailed = false;
3129
- }
3130
-
3131
- private async initializeFingerprint(): Promise<void> {
3132
- try {
3133
- this.userFingerprint = await this.generateFingerprint();
3134
- } catch (error) {
3135
- this.userFingerprint = crypto.randomUUID ? crypto.randomUUID() : String(Date.now());
3136
- if (this.config.options?.debug) {
3137
- console.warn('Fingerprint generation failed, using fallback:', error);
3138
- }
3139
- }
3140
- }
3141
-
3142
- private async generateFingerprint(): Promise<string> {
3143
- const ua = navigator.userAgent || '';
3144
- const tz = Intl.DateTimeFormat().resolvedOptions().timeZone || '';
3145
- const screenSize = `${screen.width}x${screen.height}`;
3146
- const lang = navigator.language || '';
3147
- const raw = `${ua}||${tz}||${screenSize}||${lang}`;
3148
-
3149
- const buf = new TextEncoder().encode(raw);
3150
- const hashBuffer = await crypto.subtle.digest('SHA-256', buf);
3151
- const hashArray = Array.from(new Uint8Array(hashBuffer));
3152
- return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
3153
- }
3154
-
3155
- private async setupAuthListener(): Promise<void> {
3156
- this.supabase.auth.onAuthStateChange(async (event: string, session: any) => {
3157
- const previousUser = this.currentUser;
3158
- this.currentUser = session?.user || null;
3159
-
3160
- let isPremium = false;
3161
- if (this.currentUser) {
3162
- // Only check premium status if user changed or cache is expired
3163
- const userChanged = !previousUser || previousUser.email !== this.currentUser.email;
3164
- const cacheExpired = !this.cachedPremiumStatus || (Date.now() - this.premiumStatusCacheTime) > this.STATUS_CACHE_DURATION;
3165
-
3166
- if (userChanged || cacheExpired) {
3167
- isPremium = await this.checkPremiumStatus(this.currentUser.email);
3168
- // Cache the result
3169
- this.cachedPremiumStatus = isPremium;
3170
- this.premiumStatusCacheTime = Date.now();
3171
- } else {
3172
- // Use cached result
3173
- isPremium = this.cachedPremiumStatus!; // We know it's not null because cacheExpired is false
3174
- console.log(`🔍 [CACHE] Using cached premium status from auth listener: ${isPremium}`);
3175
- }
3176
- } else {
3177
- // Clear cache when user logs out
3178
- this.cachedPremiumStatus = null;
3179
- this.premiumStatusCacheTime = 0;
3180
- }
3181
-
3182
- // Check if user just signed in for upgrade flow
3183
- const urlParams = new URLSearchParams(window.location.search);
3184
- const isUpgradeFlow = urlParams.get('upgrade') === 'true';
3185
-
3186
- if (event === 'SIGNED_IN' && !previousUser && this.currentUser && this.config.payment) {
3187
- // Check if this is an upgrade flow (from anonymous trial)
3188
- if (isUpgradeFlow) {
3189
- if (!isPremium) {
3190
- // User signed in for upgrade - redirect to payment immediately
3191
- const payment = await this.createPayment();
3192
- if (payment?.checkout_url) {
3193
- // Clean URL before redirect
3194
- window.history.replaceState({}, document.title, window.location.pathname);
3195
- window.location.href = payment.checkout_url;
3196
- }
3197
- } else {
3198
- // User is already premium, just clean URL and close modal
3199
- window.history.replaceState({}, document.title, window.location.pathname);
3200
- const modal = document.getElementById('download-limiter-paywall');
3201
- if (modal) {
3202
- modal.classList.remove('show');
3203
- }
3204
- }
3205
- }
3206
- }
3207
-
3208
- this.emit('authChanged', { user: this.currentUser, isPremium });
3209
- });
3210
-
3211
- // Get initial auth state
3212
- const { data: { user } } = await this.supabase.auth.getUser();
3213
- this.currentUser = user;
3214
- }
3215
-
3216
- private async getDownloadCount(): Promise<number> {
3217
- if (!this.userFingerprint) return 0;
3218
-
3219
- try {
3220
- const response = await fetch(`${this.config.supabase.url}/functions/v1/check-download-limit`, {
3221
- method: 'POST',
3222
- headers: {
3223
- 'Content-Type': 'application/json',
3224
- 'Authorization': `Bearer ${this.config.supabase.anonKey}`
3225
- },
3226
- body: JSON.stringify({
3227
- fingerprint: this.userFingerprint,
3228
- security_key: this.config.security_key,
3229
- action: 'check'
3230
- })
3231
- });
3232
-
3233
- if (response.ok) {
3234
- const data = await response.json();
3235
- this.supabaseConnectionFailed = false; // Connection successful
3236
- return data.current_count || 0;
3237
- } else {
3238
- // Handle auth errors (401/403) as connection failures
3239
- if (response.status === 401 || response.status === 403) {
3240
- // Try to get the actual error message from response
3241
- try {
3242
- const errorData = await response.json();
3243
- const errorMsg = errorData.error || errorData.message || 'Authentication failed';
3244
-
3245
- // Check if it's a security key validation error
3246
- if (errorMsg.toLowerCase().includes('security key')) {
3247
- console.error(`❌ Security Key Validation Failed [check-download-limit]: ${errorMsg}`);
3248
- console.error(`💡 Backend Function: check-download-limit`);
3249
- console.error(`💡 Please check your security_key in the MoneyBar configuration`);
3250
- this.securityKeyFailed = true; // Set security key error flag
3251
- this.supabaseConnectionFailed = true; // Also mark connection as failed to disable downloads
3252
- } else {
3253
- console.warn(`Supabase authentication failed [check-download-limit]: ${response.status} - ${errorMsg}`);
3254
- this.supabaseConnectionFailed = true;
3255
- }
3256
- } catch (e) {
3257
- console.warn(`Supabase authentication failed: ${response.status} - Unable to parse error`);
3258
- this.supabaseConnectionFailed = true;
3259
- }
3260
- }
3261
- }
3262
- } catch (error) {
3263
- this.supabaseConnectionFailed = true; // Mark connection as failed
3264
- if (this.config.options?.debug) {
3265
- console.warn('Failed to get server usage count, connection failed:', error);
3266
- }
3267
- }
3268
-
3269
- // Security: Do not fallback to localStorage when server connection fails
3270
- // This prevents users from bypassing limits by manipulating localStorage
3271
- return 0;
3272
- }
3273
-
3274
- private async incrementDownloadCount(): Promise<number> {
3275
- if (!this.userFingerprint) {
3276
- // if (this.config.options?.debug) {
3277
- // console.warn('🔍 DEBUG: No userFingerprint available for incrementDownloadCount');
3278
- // }
3279
- return 0;
3280
- }
3281
-
3282
- const requestBody = {
3283
- fingerprint: this.userFingerprint,
3284
- security_key: this.config.security_key,
3285
- action: 'increment'
3286
- };
3287
-
3288
- try {
3289
- const response = await fetch(`${this.config.supabase.url}/functions/v1/check-download-limit`, {
3290
- method: 'POST',
3291
- headers: {
3292
- 'Content-Type': 'application/json',
3293
- 'Authorization': `Bearer ${this.config.supabase.anonKey}`
3294
- },
3295
- body: JSON.stringify(requestBody)
3296
- });
3297
-
3298
- if (this.config.options?.debug) {
3299
- //console.log('🔍 DEBUG: Response status:', response.status);
3300
- if (!response.ok) {
3301
- const errorText = await response.text();
3302
- console.error('🔍 DEBUG: Error response:', errorText);
3303
- }
3304
- }
3305
-
3306
- if (response.ok) {
3307
- const data = await response.json();
3308
- this.supabaseConnectionFailed = false; // Connection successful
3309
- return data.new_count || 0;
3310
- } else {
3311
- // Handle auth errors (401/403) as connection failures
3312
- if (response.status === 401 || response.status === 403) {
3313
- // Try to get the actual error message from response
3314
- try {
3315
- const errorData = await response.json();
3316
- const errorMsg = errorData.error || errorData.message || 'Authentication failed';
3317
-
3318
- // Check if it's a security key validation error
3319
- if (errorMsg.toLowerCase().includes('security key')) {
3320
- console.error(`❌ Security Key Validation Failed [check-download-limit]: ${errorMsg}`);
3321
- console.error(`💡 Backend Function: check-download-limit`);
3322
- console.error(`💡 Please check your security_key in the MoneyBar configuration`);
3323
- this.securityKeyFailed = true; // Set security key error flag
3324
- this.supabaseConnectionFailed = true; // Also mark connection as failed to disable downloads
3325
- } else {
3326
- console.warn(`Supabase authentication failed [check-download-limit]: ${response.status} - ${errorMsg}`);
3327
- this.supabaseConnectionFailed = true;
3328
- }
3329
- } catch (e) {
3330
- console.warn(`Supabase authentication failed: ${response.status} - Unable to parse error`);
3331
- this.supabaseConnectionFailed = true;
3332
- }
3333
- }
3334
- }
3335
- } catch (error) {
3336
- this.supabaseConnectionFailed = true; // Mark connection as failed
3337
- if (this.config.options?.debug) {
3338
- console.warn('Failed to increment server count, connection failed:', error);
3339
- }
3340
- }
3341
-
3342
- // Security: Do not fallback to localStorage when server connection fails
3343
- // This prevents users from bypassing limits by manipulating localStorage
3344
- return 0;
3345
- }
3346
-
3347
- private async checkPremiumStatus(email: string): Promise<boolean> {
3348
- try {
3349
- const response = await fetch(`${this.config.supabase.url}/functions/v1/check-payment-status`, {
3350
- method: 'POST',
3351
- headers: {
3352
- 'Content-Type': 'application/json',
3353
- 'Authorization': `Bearer ${this.config.supabase.anonKey}`
3354
- },
3355
- body: JSON.stringify({
3356
- email,
3357
- app_id: this.config.appId
3358
- })
3359
- });
3360
-
3361
- if (response.ok) {
3362
- const data = await response.json();
3363
- return data.status === 'completed';
3364
- }
3365
- } catch (error) {
3366
- if (this.config.options?.debug) {
3367
- console.warn('Failed to check premium status:', error);
3368
- }
3369
- }
3370
-
3371
- return false;
3372
- }
3373
-
3374
- private getLocalDownloadCount(): number {
3375
- const key = `download_count_${this.config.appId}`;
3376
- const val = parseInt(localStorage.getItem(key) || '0', 10);
3377
- return isNaN(val) ? 0 : val;
3378
- }
3379
-
3380
- private incrementLocalDownloadCount(): number {
3381
- const key = `download_count_${this.config.appId}`;
3382
- const next = this.getLocalDownloadCount() + 1;
3383
- localStorage.setItem(key, String(next));
3384
- return next;
3385
- }
3386
-
3387
- private handleError(error: Error): void {
3388
- if (this.config.options?.debug) {
3389
- console.error('Lead Fast Error:', error);
3390
- }
3391
-
3392
- if (this.config.callbacks?.onError) {
3393
- this.config.callbacks.onError(error);
3394
- } else {
3395
- // Default error handling
3396
- console.error('Lead Fast:', error.message);
3397
- }
3398
-
3399
- this.emit('error', error);
3400
- }
3401
-
3402
- private async checkPaymentStatus(): Promise<void> {
3403
- // Check if user returned from payment
3404
- const urlParams = new URLSearchParams(window.location.search);
3405
- if (urlParams.get('payment') === 'success') {
3406
- // Wait for auth to be ready
3407
- setTimeout(async () => {
3408
- if (this.currentUser) {
3409
- const isPremium = await this.checkPremiumStatus(this.currentUser.email);
3410
- if (isPremium) {
3411
- this.showSuccess('Payment Successful!', 'Welcome to premium! You now have unlimited usage.');
3412
- } else {
3413
- this.showSuccess('Processing Payment', 'Payment is being processed. Please refresh in a few moments.');
3414
- }
3415
- } else {
3416
- this.showSuccess('Processing Payment', 'Please wait while we verify your payment...');
3417
- }
3418
-
3419
- // Clean up URL
3420
- const cleanUrl = window.location.href.split('?')[0];
3421
- window.history.replaceState({}, document.title, cleanUrl);
3422
- }, 2000);
3423
- }
3424
- }
3425
- }
3426
-
3427
- // Export types for consumer use
3428
- export * from './types.js';