@@ -677,14 +677,14 @@ <h3 class="text-lg font-semibold text-gray-800 line-clamp-2 flex-1">
677677 ` : '' }
678678
679679 <div class="mt-4 pt-4 border-t border-gray-100">
680- <a href=" ${ escapeHtml ( link . link ) } "
681- target="_blank "
680+ <button
681+ onclick="handleOpenLink( ${ link . id } , ' ${ escapeHtml ( link . link ) } ') "
682682 class="w-full bg-gradient-to-r from-primary-500 to-secondary-500 hover:from-primary-600 hover:to-secondary-600 text-white py-2 px-4 rounded-lg text-sm font-medium transition-all duration-200 transform hover:scale-105 flex items-center justify-center gap-2">
683683 <svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
684684 <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 6H6a2 2 0 00-2 2v10a2 2 0 002 2h10a2 2 0 002-2v-4M14 4h6m0 0v6m0-6L10 14"></path>
685685 </svg>
686686 Open Link
687- </a >
687+ </button >
688688 </div>
689689 </div>
690690 </div>
@@ -693,6 +693,21 @@ <h3 class="text-lg font-semibold text-gray-800 line-clamp-2 flex-1">
693693 ` ;
694694 }
695695
696+ // Handle opening a link and incrementing count
697+ async function handleOpenLink ( id , url ) {
698+ // Open link in new tab
699+ window . open ( url , '_blank' ) ;
700+
701+ // Increment count in background
702+ try {
703+ await fetch ( `/api/links/increment-count?id=${ id } ` , { method : 'POST' } ) ;
704+ // Optional: refresh links to see updated count
705+ setTimeout ( loadLinks , 1000 ) ;
706+ } catch ( error ) {
707+ console . error ( 'Error incrementing count:' , error ) ;
708+ }
709+ }
710+
696711 // Populate tag filter dropdown
697712 function populateTagFilter ( ) {
698713 const tagFilter = document . getElementById ( 'tagFilter' ) ;
0 commit comments