@@ -9,18 +9,29 @@ export default defineComponent({
9
9
}
10
10
} ,
11
11
methods : {
12
- catchTimestampClick : function ( event ) {
13
- const match = event . detail . match ( / ( \d + ) : ( \d + ) : ? ( \d + ) ? / )
14
- if ( match [ 3 ] !== undefined ) { // HH:MM:SS
15
- const seconds = 3600 * Number ( match [ 1 ] ) + 60 * Number ( match [ 2 ] ) + Number ( match [ 3 ] )
16
- this . $emit ( 'timestamp-event' , seconds )
17
- } else { // MM:SS
18
- const seconds = 60 * Number ( match [ 1 ] ) + Number ( match [ 2 ] )
19
- this . $emit ( 'timestamp-event' , seconds )
20
- }
12
+ catchTimestampClick : function ( event ) {
13
+ this . $emit ( 'timestamp-event' , event . detail )
21
14
} ,
22
15
detectTimestamps : function ( input ) {
23
- return input . replaceAll ( / ( \d + ( : \d + ) + ) / g, '<a href="#" onclick="this.dispatchEvent(new CustomEvent(\'timestamp-clicked\',{bubbles:true, detail:\'$1\'}))">$1</a>' )
16
+ const videoId = this . $route . params . id
17
+
18
+ return input . replaceAll ( / (?: ( \d + ) : ) ? ( \d + ) : ( \d + ) / g, ( timestamp , hours , minutes , seconds ) => {
19
+ let time = 60 * Number ( minutes ) + Number ( seconds )
20
+
21
+ if ( hours ) {
22
+ time += 3600 * Number ( hours )
23
+ }
24
+
25
+ const url = this . $router . resolve ( {
26
+ path : `/watch/${ videoId } ` ,
27
+ query : {
28
+ timestamp : time
29
+ }
30
+ } ) . href
31
+
32
+ // Adding the URL lets the user open the video in a new window at this timestamp
33
+ return `<a href="${ url } " onclick="event.preventDefault();this.dispatchEvent(new CustomEvent('timestamp-clicked',{bubbles:true,detail:${ time } }));window.scrollTo(0,0)">${ timestamp } </a>`
34
+ } )
24
35
}
25
36
}
26
37
} )
0 commit comments