@@ -16,6 +16,7 @@ <h1 class="text-2xl font-bold text-center mb-4 text-gray-800 dark:text-white">Da
1616 < div class ="mb-4 ">
1717 < label for ="category " class ="block text-sm font-medium text-gray-700 dark:text-gray-300 "> Category:</ label >
1818 < select id ="category " class ="mt-1 p-2 w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm dark:bg-gray-600 dark:text-white ">
19+ < option value ="random "> Random</ option >
1920 < option value ="inspirational "> Inspirational</ option >
2021 < option value ="motivational "> Motivational</ option >
2122 < option value ="success "> Success</ option >
@@ -31,8 +32,8 @@ <h1 class="text-2xl font-bold text-center mb-4 text-gray-800 dark:text-white">Da
3132 </ div >
3233 < div class ="mb-4 ">
3334 < label for ="creativity " class ="block text-sm font-medium text-gray-700 dark:text-gray-300 "> Creativity:</ label >
34- < input type ="range " id ="creativity " min ="0 " max ="100 " step ="5 " value ="50 " class ="w-full ">
35- < div id ="creativity-value " class ="text-center text-sm text-gray-600 dark:text-gray-400 "> 50 %</ div >
35+ < input type ="range " id ="creativity " min ="0 " max ="100 " step ="5 " value ="30 " class ="w-full ">
36+ < div id ="creativity-value " class ="text-center text-sm text-gray-600 dark:text-gray-400 "> 30 %</ div >
3637 </ div >
3738 < button id ="generate-quote " class ="w-full rounded-md bg-indigo-600 text-white p-2 hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 "> Generate Quote</ button >
3839 < div id ="result " class ="mt-4 text-center text-sm font-medium text-gray-800 dark:text-white "> </ div >
@@ -46,38 +47,63 @@ <h1 class="text-2xl font-bold text-center mb-4 text-gray-800 dark:text-white">Da
4647 Share
4748 </ button >
4849 </ div >
50+ < button id ="save-quote " class ="mt-4 w-full rounded-md bg-green-600 text-white p-2 hover:bg-green-700 focus:outline-none focus:ring-2 focus:ring-green-500 hidden "> Save Quote</ button >
51+ < div id ="saved-quotes " class ="mt-4 text-sm text-gray-800 dark:text-white hidden ">
52+ < h3 class ="font-bold mb-2 "> Saved Quotes:</ h3 >
53+ < ul id ="saved-quotes-list " class ="list-disc pl-5 "> </ ul >
54+ </ div >
4955 < div id ="howToUseSection " class ="my-6 ">
5056 < button onclick ="toggleCollapse() " class ="flex items-center justify-between w-full p-4 bg-blue-50 dark:bg-blue-900 border-l-4 border-blue-400 text-blue-700 dark:text-blue-300 cursor-pointer ">
5157 < h2 class ="font-semibold text-lg "> How to Use Daily Quote Generator</ h2 >
5258 < span id ="collapseIcon " class ="text-xl "> +</ span >
5359 </ button >
5460 < div id ="howToUseContent " class ="hidden ">
5561 < div class ="p-4 bg-blue-50 dark:bg-blue-900 border-l-4 border-blue-400 text-blue-700 dark:text-blue-300 ">
56- < p class ="mb-2 "> Generate and share inspiring daily quotes with ease:</ p >
62+ < p class ="mb-2 "> Generate, share, and save inspiring daily quotes with ease:</ p >
5763 < ul class ="list-disc pl-5 space-y-1 ">
58- < li > Select a category from the dropdown menu .</ li >
64+ < li > Select a category or leave it as "Random" for variety .</ li >
5965 < li > Optionally, enter an author's name for a quote from that person.</ li >
6066 < li > Adjust the "Creativity" slider to control the uniqueness of the generated quotes.</ li >
6167 < li > Click the "Generate Quote" button to create your quote.</ li >
6268 < li > Click on the generated quote to copy it to your clipboard.</ li >
6369 < li > Use the share buttons to post the quote on social media.</ li >
70+ < li > Save your favorite quotes for later reference.</ li >
6471 </ ul >
6572 </ div >
6673 </ div >
6774 </ div >
6875</ div >
6976< script >
77+ const categories = [ 'inspirational' , 'motivational' , 'success' , 'life' , 'love' , 'wisdom' , 'humor' ] ;
78+ let userSelectedCategory = false ;
7079 document . getElementById ( 'creativity' ) . addEventListener ( 'input' , function ( ) {
7180 const creativityValue = this . value ;
7281 document . getElementById ( 'creativity-value' ) . textContent = `${ creativityValue } %` ;
7382 } ) ;
83+ document . getElementById ( 'category' ) . addEventListener ( 'change' , function ( ) {
84+ userSelectedCategory = this . value !== 'random' ;
85+ } ) ;
7486 document . getElementById ( 'generate-quote' ) . addEventListener ( 'click' , generateQuote ) ;
87+ document . getElementById ( 'save-quote' ) . addEventListener ( 'click' , saveQuote ) ;
88+ function getRandomCategory ( ) {
89+ return categories [ Math . floor ( Math . random ( ) * categories . length ) ] ;
90+ }
91+ function setRandomCategory ( ) {
92+ if ( ! userSelectedCategory ) {
93+ document . getElementById ( 'category' ) . value = 'random' ;
94+ }
95+ }
96+ setRandomCategory ( ) ;
7597 async function generateQuote ( ) {
76- const category = document . getElementById ( 'category' ) . value ;
98+ let category = document . getElementById ( 'category' ) . value ;
99+ if ( category === 'random' ) {
100+ category = getRandomCategory ( ) ;
101+ }
77102 const author = document . getElementById ( 'author' ) . value ;
78103 const creativity = document . getElementById ( 'creativity' ) . value / 100 ;
79104 const resultContainer = document . getElementById ( 'result' ) ;
80105 const shareButtons = document . getElementById ( 'share-buttons' ) ;
106+ const saveButton = document . getElementById ( 'save-quote' ) ;
81107 toggleButtonState ( ) ;
82108 const botMessage = `I am currently functioning as the Daily Quote Generator API. I will provide responses in this JSON format: {"quote":"generated quote", "author":"quote author"}` ;
83109 const userMessage = `Generate a ${ category } quote${ author ? ` by ${ author } ` : '' } .` ;
@@ -105,10 +131,12 @@ <h2 class="font-semibold text-lg">How to Use Daily Quote Generator</h2>
105131 const responseJsonData = JSON5 . parse ( responseJsonStr ) ;
106132 displayQuote ( responseJsonData . quote , responseJsonData . author ) ;
107133 shareButtons . classList . remove ( 'hidden' ) ;
134+ saveButton . classList . remove ( 'hidden' ) ;
108135 } catch ( error ) {
109136 console . error ( 'Error:' , error ) ;
110137 resultContainer . textContent = 'Failed to generate a quote. Please try again.' ;
111138 shareButtons . classList . add ( 'hidden' ) ;
139+ saveButton . classList . add ( 'hidden' ) ;
112140 } finally {
113141 toggleButtonState ( ) ;
114142 }
@@ -148,6 +176,43 @@ <h2 class="font-semibold text-lg">How to Use Daily Quote Generator</h2>
148176 const facebookUrl = `https://www.facebook.com/sharer/sharer.php?u=${ encodeURIComponent ( window . location . href ) } "e=${ encodeURIComponent ( quote ) } ` ;
149177 window . open ( facebookUrl , '_blank' ) ;
150178 }
179+ function saveQuote ( ) {
180+ const quote = document . getElementById ( 'result' ) . innerText ;
181+ let savedQuotes = JSON . parse ( localStorage . getItem ( 'savedQuotes' ) ) || [ ] ;
182+ savedQuotes . push ( quote ) ;
183+ localStorage . setItem ( 'savedQuotes' , JSON . stringify ( savedQuotes ) ) ;
184+ updateSavedQuotesList ( ) ;
185+ alert ( 'Quote saved successfully!' ) ;
186+ }
187+ function updateSavedQuotesList ( ) {
188+ const savedQuotes = JSON . parse ( localStorage . getItem ( 'savedQuotes' ) ) || [ ] ;
189+ const savedQuotesList = document . getElementById ( 'saved-quotes-list' ) ;
190+ const savedQuotesContainer = document . getElementById ( 'saved-quotes' ) ;
191+ savedQuotesList . innerHTML = '' ;
192+ if ( savedQuotes . length > 0 ) {
193+ savedQuotes . forEach ( ( quote , index ) => {
194+ const li = document . createElement ( 'li' ) ;
195+ li . textContent = quote ;
196+ li . classList . add ( 'mb-2' ) ;
197+ const deleteButton = document . createElement ( 'button' ) ;
198+ deleteButton . textContent = 'Delete' ;
199+ deleteButton . classList . add ( 'ml-2' , 'text-red-600' , 'hover:text-red-800' ) ;
200+ deleteButton . onclick = ( ) => deleteQuote ( index ) ;
201+ li . appendChild ( deleteButton ) ;
202+ savedQuotesList . appendChild ( li ) ;
203+ } ) ;
204+ savedQuotesContainer . classList . remove ( 'hidden' ) ;
205+ } else {
206+ savedQuotesContainer . classList . add ( 'hidden' ) ;
207+ }
208+ }
209+ function deleteQuote ( index ) {
210+ let savedQuotes = JSON . parse ( localStorage . getItem ( 'savedQuotes' ) ) || [ ] ;
211+ savedQuotes . splice ( index , 1 ) ;
212+ localStorage . setItem ( 'savedQuotes' , JSON . stringify ( savedQuotes ) ) ;
213+ updateSavedQuotesList ( ) ;
214+ }
215+ updateSavedQuotesList ( ) ;
151216</ script >
152217< script src ="../sidebar.js "> </ script >
153218</ body >
0 commit comments