]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+videos/+video-watch/shared/timestamp-route-transformer.directive.ts
Increase player control bar size
[github/Chocobozzz/PeerTube.git] / client / src / app / +videos / +video-watch / shared / timestamp-route-transformer.directive.ts
CommitLineData
240458d0 1import { Directive, EventEmitter, HostListener, Output } from '@angular/core'
b29bf61d
RK
2
3@Directive({
9df52d66 4 selector: '[myTimestampRouteTransformer]'
b29bf61d
RK
5})
6export class TimestampRouteTransformerDirective {
7 @Output() timestampClicked = new EventEmitter<number>()
8
9df52d66 9 @HostListener('click', [ '$event' ])
240458d0
C
10 public onClick ($event: Event) {
11 const target = $event.target as HTMLLinkElement
12
d4eea028
C
13 if (target.hasAttribute('href') !== true) return
14
15 const ngxLink = document.createElement('a')
16 ngxLink.href = target.getAttribute('href')
17
18 // we only care about reflective links
19 if (ngxLink.host !== window.location.host) return
20
21 const ngxLinkParams = new URLSearchParams(ngxLink.search)
22 if (ngxLinkParams.has('start') !== true) return
23
9df52d66 24 const separators = [ 'h', 'm', 's' ]
d4eea028
C
25 const start = ngxLinkParams
26 .get('start')
9df52d66 27 .match(new RegExp('(\\d{1,9}[' + separators.join('') + '])', 'g')) // match digits before any given separator
d4eea028
C
28 .map(t => {
29 if (t.includes('h')) return parseInt(t, 10) * 3600
30 if (t.includes('m')) return parseInt(t, 10) * 60
31 return parseInt(t, 10)
32 })
33 .reduce((acc, t) => acc + t)
34
35 this.timestampClicked.emit(start)
36
37 $event.preventDefault()
b29bf61d
RK
38 }
39}