@@ -122,27 +122,44 @@ export default function EroScriptsPanel({ currentVideoName }: EroScriptsPanelPro
122122 const links : Array < { filename : string ; url : string } > = [ ]
123123
124124 for ( const post of posts ) {
125- if ( post . link_counts ) {
126- for ( const link of post . link_counts ) {
127- if ( link . url && isFunscriptUrl ( link . url ) ) {
128- const rawName = link . title || link . url . split ( '/' ) . pop ( ) || 'script.funscript'
129- const filename = safeDecodeURI ( rawName )
130- const fullUrl = link . url . startsWith ( 'http' ) ? link . url : `${ BASE_URL } ${ link . url } `
131- links . push ( { filename, url : fullUrl } )
132- }
125+ const cooked = post . cooked || ''
126+
127+ // Parse cooked HTML: <a href="...">Original Filename.funscript</a>
128+ const linkRegex = / < a [ ^ > ] + h r e f = " ( [ ^ " ] * ) " [ ^ > ] * > ( [ ^ < ] * \. (?: f u n s c r i p t | z i p | 7 z | r a r ) ) < \/ a > / gi
129+ let match
130+ while ( ( match = linkRegex . exec ( cooked ) ) !== null ) {
131+ const url = match [ 1 ]
132+ const linkText = match [ 2 ] . trim ( )
133+ const fullUrl = url . startsWith ( 'http' ) ? url : `${ BASE_URL } ${ url } `
134+ const filename = safeDecodeURI ( linkText )
135+ if ( ! links . some ( l => l . url === fullUrl ) ) {
136+ links . push ( { filename, url : fullUrl } )
133137 }
134138 }
135- const cooked = post . cooked || ''
139+
140+ // Fallback: href-only regex for links without visible text matching
136141 const hrefRegex = / h r e f = " ( [ ^ " ] * \. (?: f u n s c r i p t | z i p | 7 z | r a r ) [ ^ " ] * ) " / gi
137- let match
138142 while ( ( match = hrefRegex . exec ( cooked ) ) !== null ) {
139143 const url = match [ 1 ]
140144 const fullUrl = url . startsWith ( 'http' ) ? url : `${ BASE_URL } ${ url } `
141- const filename = safeDecodeURI ( fullUrl . split ( '/' ) . pop ( ) || 'script' )
142145 if ( ! links . some ( l => l . url === fullUrl ) ) {
146+ const filename = safeDecodeURI ( fullUrl . split ( '/' ) . pop ( ) || 'script' )
143147 links . push ( { filename, url : fullUrl } )
144148 }
145149 }
150+
151+ // Fallback: link_counts (only if not already found via HTML)
152+ if ( post . link_counts ) {
153+ for ( const link of post . link_counts ) {
154+ if ( link . url && isFunscriptUrl ( link . url ) ) {
155+ const fullUrl = link . url . startsWith ( 'http' ) ? link . url : `${ BASE_URL } ${ link . url } `
156+ if ( ! links . some ( l => l . url === fullUrl ) ) {
157+ const rawName = link . title || link . url . split ( '/' ) . pop ( ) || 'script.funscript'
158+ links . push ( { filename : safeDecodeURI ( rawName ) , url : fullUrl } )
159+ }
160+ }
161+ }
162+ }
146163 }
147164 setDownloadLinks ( prev => ( { ...prev , [ topicId ] : links } ) )
148165 }
0 commit comments