@@ -5,13 +5,110 @@ class FriendshipGreetingApp {
55 this . currentAnimation = null ;
66 this . uploadedFiles = [ ] ;
77 this . effectInterval = null ;
8+ this . currentGreetingId = null ;
9+ this . quotes = [
10+ "Friendship is born at that moment when one person says to another, 'What! You too?'" ,
11+ "A real friend is one who walks in when the rest of the world walks out." ,
12+ "Friends are the family you choose."
13+ ] ;
814
915 this . init ( ) ;
1016 }
1117
1218 init ( ) {
1319 this . bindEvents ( ) ;
1420 this . startDefaultEffect ( ) ;
21+ this . checkForSharedGreeting ( ) ;
22+ }
23+
24+ generateGreetingId ( ) {
25+ return 'greeting_' + Date . now ( ) + '_' + Math . random ( ) . toString ( 36 ) . substr ( 2 , 9 ) ;
26+ }
27+
28+ saveGreeting ( greetingData ) {
29+ const greetingId = this . generateGreetingId ( ) ;
30+ const greetings = JSON . parse ( localStorage . getItem ( 'friendshipGreetings' ) || '{}' ) ;
31+ greetings [ greetingId ] = {
32+ ...greetingData ,
33+ createdAt : new Date ( ) . toISOString ( )
34+ } ;
35+ localStorage . setItem ( 'friendshipGreetings' , JSON . stringify ( greetings ) ) ;
36+ return greetingId ;
37+ }
38+
39+ loadGreeting ( greetingId ) {
40+ const greetings = JSON . parse ( localStorage . getItem ( 'friendshipGreetings' ) || '{}' ) ;
41+ return greetings [ greetingId ] || null ;
42+ }
43+
44+ checkForSharedGreeting ( ) {
45+ const urlParams = new URLSearchParams ( window . location . search ) ;
46+ const greetingId = urlParams . get ( 'greeting' ) ;
47+
48+ if ( greetingId ) {
49+ const greetingData = this . loadGreeting ( greetingId ) ;
50+ if ( greetingData ) {
51+ this . loadGreetingFromData ( greetingData ) ;
52+ this . currentGreetingId = greetingId ;
53+ // Hide the form and show only the greeting
54+ document . querySelector ( '.form-container' ) . style . display = 'none' ;
55+ document . querySelector ( '.greeting-preview' ) . style . width = '100%' ;
56+ document . querySelector ( '.greeting-preview' ) . style . maxWidth = '600px' ;
57+ document . querySelector ( '.greeting-preview' ) . style . margin = '0 auto' ;
58+
59+ // Add a "Create Your Own" button
60+ this . addCreateOwnButton ( ) ;
61+ }
62+ }
63+ }
64+
65+ loadGreetingFromData ( data ) {
66+ // Update form fields
67+ document . getElementById ( 'friendName' ) . value = data . friendName || '' ;
68+ document . getElementById ( 'memories' ) . value = data . memories || '' ;
69+ document . getElementById ( 'message' ) . value = data . message || '' ;
70+
71+ // Set effects and styles
72+ this . currentEffect = data . effect || 'hearts' ;
73+ this . currentStyle = data . style || 'classic' ;
74+ this . currentAnimation = data . animation || 'bounce' ;
75+
76+ // Update the greeting display
77+ this . updateFriendName ( data . friendName || '' ) ;
78+ this . updateMemories ( data . memories || '' ) ;
79+ this . updateMessage ( data . message || '' ) ;
80+ this . setEffect ( this . currentEffect ) ;
81+ this . setStyle ( this . currentStyle ) ;
82+ this . setAnimation ( this . currentAnimation ) ;
83+
84+ // Handle uploaded files if any
85+ if ( data . uploadedFiles && data . uploadedFiles . length > 0 ) {
86+ // Note: We can't restore actual files, but we can show placeholders
87+ this . showNotification ( 'Note: Shared greetings show text content only. Original images are not included for privacy.' , 'info' ) ;
88+ }
89+ }
90+
91+ addCreateOwnButton ( ) {
92+ // Check if button already exists
93+ if ( document . getElementById ( 'createOwnBtn' ) ) return ;
94+
95+ const actionButtons = document . querySelector ( '.action-buttons' ) ;
96+ const createOwnBtn = document . createElement ( 'button' ) ;
97+ createOwnBtn . id = 'createOwnBtn' ;
98+ createOwnBtn . className = 'action-btn' ;
99+ createOwnBtn . innerHTML = '<i class="fas fa-plus"></i> Create Your Own' ;
100+ createOwnBtn . style . background = '#667eea' ;
101+ createOwnBtn . style . color = 'white' ;
102+ createOwnBtn . style . border = '2px solid #667eea' ;
103+
104+ createOwnBtn . addEventListener ( 'click' , ( ) => {
105+ // Remove the greeting parameter from URL and reload
106+ const url = new URL ( window . location ) ;
107+ url . searchParams . delete ( 'greeting' ) ;
108+ window . location . href = url . toString ( ) ;
109+ } ) ;
110+
111+ actionButtons . appendChild ( createOwnBtn ) ;
15112 }
16113
17114 bindEvents ( ) {
@@ -290,18 +387,35 @@ class FriendshipGreetingApp {
290387 const message = document . getElementById ( 'message' ) . value ;
291388
292389 if ( ! friendName . trim ( ) ) {
293- this . showNotification ( 'Please enter your friend\'s name!' , 'warning ' ) ;
390+ this . showNotification ( 'Please enter your friend\'s name! 👤 ' , 'error ' ) ;
294391 return ;
295392 }
296393
394+ // Save greeting data
395+ const greetingData = {
396+ friendName : friendName ,
397+ memories : memories ,
398+ message : message ,
399+ effect : this . currentEffect ,
400+ style : this . currentStyle ,
401+ animation : this . currentAnimation ,
402+ uploadedFiles : this . uploadedFiles . map ( file => ( { name : file . name , type : file . type } ) )
403+ } ;
404+
405+ this . currentGreetingId = this . saveGreeting ( greetingData ) ;
406+
407+ this . updateFriendName ( friendName ) ;
408+ this . updateMemories ( memories ) ;
409+ this . updateMessage ( message ) ;
410+
297411 // Add a special creation animation
298412 const greetingCard = document . getElementById ( 'greetingCard' ) ;
299413 greetingCard . style . transform = 'scale(0.95)' ;
300414 greetingCard . style . transition = 'transform 0.3s ease' ;
301415
302416 setTimeout ( ( ) => {
303417 greetingCard . style . transform = 'scale(1)' ;
304- this . showNotification ( 'Greeting card created successfully ! 🎉' , 'success' ) ;
418+ this . showNotification ( 'Beautiful greeting created! 🎉 Ready to share! ' , 'success' ) ;
305419 } , 300 ) ;
306420
307421 // Add some extra sparkle effect
@@ -352,17 +466,25 @@ class FriendshipGreetingApp {
352466 }
353467
354468 shareGreeting ( ) {
469+ if ( ! this . currentGreetingId ) {
470+ this . showNotification ( 'Please create a greeting first!' , 'warning' ) ;
471+ return ;
472+ }
473+
474+ const shareUrl = `${ window . location . origin } ${ window . location . pathname } ?greeting=${ this . currentGreetingId } ` ;
475+
355476 if ( navigator . share ) {
356477 navigator . share ( {
357478 title : 'Friendship Day Greeting' ,
358479 text : 'Check out this beautiful friendship day greeting I created!' ,
359- url : window . location . href
480+ url : shareUrl
360481 } ) ;
361482 } else {
362483 // Fallback for browsers that don't support Web Share API
363- const url = window . location . href ;
364- navigator . clipboard . writeText ( url ) . then ( ( ) => {
365- this . showNotification ( 'Link copied to clipboard! Share it with your friends! 📋' , 'success' ) ;
484+ navigator . clipboard . writeText ( shareUrl ) . then ( ( ) => {
485+ this . showNotification ( 'Greeting link copied to clipboard! Share it with your friends! 📋' , 'success' ) ;
486+ } ) . catch ( ( ) => {
487+ this . showNotification ( 'Failed to copy link. Please try again.' , 'error' ) ;
366488 } ) ;
367489 }
368490 }
0 commit comments