@@ -24,7 +24,7 @@ const DEBUG = false;
2424 */
2525function debugLog ( ...messages ) {
2626 if ( DEBUG ) {
27- console . log ( '[GIFs for GitHub]:' , ...messages ) ;
27+ console . log ( '🎨 [GIFs for GitHub]:' , ...messages ) ;
2828 }
2929}
3030
@@ -33,21 +33,18 @@ function debugLog(...messages) {
3333 */
3434async function watchGiphyModals ( element ) {
3535 if ( ! element ) {
36- debugLog ( 'No element provided to watchGiphyModals' ) ;
3736 return ;
3837 }
3938
4039 const parent = element . closest ( '.ghg-has-giphy-field' ) ;
4140 if ( ! parent ) {
42- debugLog ( 'Could not find parent .ghg-has-giphy-field' ) ;
4341 return ;
4442 }
4543
4644 const resultsContainer = select ( '.ghg-giphy-results' , parent ) ;
4745 const searchInput = select ( '.ghg-search-input' , parent ) ;
4846
4947 if ( ! resultsContainer || ! searchInput ) {
50- debugLog ( 'Could not find required elements:' , { resultsContainer, searchInput } ) ;
5148 return ;
5249 }
5350
@@ -81,8 +78,7 @@ async function watchGiphyModals(element) {
8178 } else {
8279 showNoResultsFound ( resultsContainer ) ;
8380 }
84- } catch ( error ) {
85- console . error ( 'Error loading trending GIFs:' , error ) ;
81+ } catch {
8682 resultsContainer . innerHTML = '<div class="ghg-error">Error loading GIFs. Please try again.</div>' ;
8783 }
8884 } else {
@@ -99,8 +95,9 @@ async function watchGiphyModals(element) {
9995 } ) ;
10096 // Keep reference to prevent garbage collection
10197 resultsContainer . masonryLayout = masonryLayout ;
102- } catch ( error ) {
103- console . error ( 'Error initializing Masonry:' , error ) ;
98+ } catch {
99+ // Silently fail if masonry initialization fails
100+ // This is not critical to the functionality
104101 }
105102 } ,
106103 10 ,
@@ -114,7 +111,6 @@ async function watchGiphyModals(element) {
114111 */
115112function addToolbarButton ( toolbar ) {
116113 if ( ! toolbar ) {
117- debugLog ( 'No toolbar found to add button to' ) ;
118114 return ;
119115 }
120116
@@ -141,18 +137,13 @@ function addToolbarButton(toolbar) {
141137 }
142138
143139 if ( ! toolbarGroup ) {
144- debugLog ( 'No suitable toolbar group found in:' , toolbar ) ;
145140 return ;
146141 }
147142
148143 // Find the parent form and text area
149- // Start from the toolbar and traverse up to find the closest form-like container
150- let form ;
144+ let form = toolbar . closest ( 'form, .js-previewable-comment-form, [role="form"]' ) ;
151145 let textArea ;
152146
153- // First try direct form elements
154- form = toolbar . closest ( 'form, .js-previewable-comment-form, [role="form"]' ) ;
155-
156147 // If we haven't found a form, try finding the closest container with a textarea
157148 if ( form === null ) {
158149 let current = toolbar ;
@@ -179,15 +170,6 @@ function addToolbarButton(toolbar) {
179170 }
180171
181172 if ( ! form || ! textArea ) {
182- debugLog ( 'Could not find required form elements:' , {
183- form,
184- textArea,
185- formParents : toolbar . closest ( 'form, .js-previewable-comment-form, [role="form"]' ) ?. outerHTML ,
186- textAreaCandidates : form ? select . all ( 'textarea' , form ) . length : 0 ,
187- toolbarHTML : toolbar . outerHTML ,
188- toolbarParent : toolbar . parentElement ?. outerHTML ,
189- toolbarGrandParent : toolbar . parentElement ?. parentElement ?. outerHTML ,
190- } ) ;
191173 return ;
192174 }
193175
@@ -196,11 +178,7 @@ function addToolbarButton(toolbar) {
196178 return ;
197179 }
198180
199- // Add the classes to mark the form and toolbar
200- form . classList . add ( 'ghg-has-giphy-field' ) ;
201- toolbar . classList . add ( 'ghg-has-giphy-button' ) ;
202-
203- // Clone and append the Giphy button
181+ // Create the GIF button
204182 const button = GiphyToolbarItem . cloneNode ( true ) ;
205183
206184 // Fix space key handling in the input field
@@ -228,6 +206,10 @@ function addToolbarButton(toolbar) {
228206 toolbarGroup . append ( button ) ;
229207 }
230208
209+ // Mark the toolbar and form as processed
210+ toolbar . classList . add ( 'ghg-has-giphy-button' ) ;
211+ form . classList . add ( 'ghg-has-giphy-field' ) ;
212+
231213 // Handle review changes modal positioning
232214 const reviewChangesModal = toolbar . closest ( '#review-changes-modal' ) ;
233215 const reviewChangesList = toolbar . closest ( '#review-changes-modal .SelectMenu-list' ) ;
0 commit comments