@@ -9,11 +9,19 @@ document.addEventListener('DOMContentLoaded', () => {
99 const submitButton = frmConvert . querySelector ( "button[type=submit]" ) ;
1010 const link = document . getElementById ( 'link' ) . value ;
1111 const format = document . getElementById ( 'format' ) . value ;
12+ const startAt = document . getElementById ( 'startAt' ) . value ;
13+ const endAt = document . getElementById ( 'endAt' ) . value ;
1214
1315 submitButton . classList . add ( "disabled" ) ;
1416 submitButton . innerHTML = "<i class=\"fas fa-spin fa-sync-alt\"></i> Converting..." ;
1517
16- const endpoint = `${ frmConvert . getAttribute ( "action" ) } ?youtubelink=${ link } &format=${ format } ` ;
18+ let endpoint = `${ frmConvert . getAttribute ( "action" ) } ?youtubelink=${ link } &format=${ format } ` ;
19+
20+ if ( startAt . length > 0 )
21+ endpoint += `&startAt=${ startAt } ` ;
22+
23+ if ( endAt . length > 0 )
24+ endpoint += `&endAt=${ endAt } ` ;
1725
1826 fetch ( endpoint )
1927 . then ( response => response . json ( ) )
@@ -168,4 +176,37 @@ function handleInfoResponse(data, submitButton)
168176 tableCells [ 9 ] . innerText = data . title ;
169177 tableCells [ 10 ] . innerHTML = `<a target='_blank' href='${ data . url } '>${ data . url } </a>` ;
170178 }
179+ }
180+
181+ function fillStartEnd ( )
182+ {
183+ const elLink = document . getElementById ( 'link' ) ;
184+ const elStart = document . getElementById ( 'startAt' ) ;
185+ const elEnd = document . getElementById ( 'endAt' ) ;
186+
187+ const url = new URL ( elLink . value ) ;
188+ const start = url . searchParams . get ( "start" ) || url . searchParams . get ( "t" ) ;
189+ const end = url . searchParams . get ( "end" ) ;
190+
191+ if ( start && start . length > 0 )
192+ {
193+ elStart . value = start ;
194+ elStart . setAttribute ( 'readonly' , 'readonly' ) ;
195+ }
196+ else
197+ {
198+ elStart . value = '' ;
199+ elStart . removeAttribute ( 'readonly' ) ;
200+ }
201+
202+ if ( end && end . length > 0 )
203+ {
204+ elEnd . value = end ;
205+ elEnd . setAttribute ( 'readonly' , 'readonly' ) ;
206+ }
207+ else
208+ {
209+ elEnd . value = '' ;
210+ elEnd . removeAttribute ( 'readonly' ) ;
211+ }
171212}
0 commit comments