mirror of https://github.com/Chocobozzz/PeerTube
Fix relative links in video description
parent
1df8a4d79a
commit
d4eea02801
|
@ -10,31 +10,30 @@ export class TimestampRouteTransformerDirective {
|
|||
public onClick ($event: Event) {
|
||||
const target = $event.target as HTMLLinkElement
|
||||
|
||||
if (target.hasAttribute('href')) {
|
||||
const ngxLink = document.createElement('a')
|
||||
ngxLink.href = target.getAttribute('href')
|
||||
if (target.hasAttribute('href') !== true) return
|
||||
|
||||
// we only care about reflective links
|
||||
if (ngxLink.host !== window.location.host) return
|
||||
const ngxLink = document.createElement('a')
|
||||
ngxLink.href = target.getAttribute('href')
|
||||
|
||||
const ngxLinkParams = new URLSearchParams(ngxLink.search)
|
||||
if (ngxLinkParams.has('start')) {
|
||||
const separators = ['h', 'm', 's']
|
||||
const start = ngxLinkParams
|
||||
.get('start')
|
||||
.match(new RegExp('(\\d{1,9}[' + separators.join('') + '])','g')) // match digits before any given separator
|
||||
.map(t => {
|
||||
if (t.includes('h')) return parseInt(t, 10) * 3600
|
||||
if (t.includes('m')) return parseInt(t, 10) * 60
|
||||
return parseInt(t, 10)
|
||||
})
|
||||
.reduce((acc, t) => acc + t)
|
||||
this.timestampClicked.emit(start)
|
||||
}
|
||||
// we only care about reflective links
|
||||
if (ngxLink.host !== window.location.host) return
|
||||
|
||||
$event.preventDefault()
|
||||
}
|
||||
const ngxLinkParams = new URLSearchParams(ngxLink.search)
|
||||
if (ngxLinkParams.has('start') !== true) return
|
||||
|
||||
return
|
||||
const separators = ['h', 'm', 's']
|
||||
const start = ngxLinkParams
|
||||
.get('start')
|
||||
.match(new RegExp('(\\d{1,9}[' + separators.join('') + '])','g')) // match digits before any given separator
|
||||
.map(t => {
|
||||
if (t.includes('h')) return parseInt(t, 10) * 3600
|
||||
if (t.includes('m')) return parseInt(t, 10) * 60
|
||||
return parseInt(t, 10)
|
||||
})
|
||||
.reduce((acc, t) => acc + t)
|
||||
|
||||
this.timestampClicked.emit(start)
|
||||
|
||||
$event.preventDefault()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue