Fix relative links in video description

pull/2737/head
Chocobozzz 2020-05-06 14:21:10 +02:00
parent 1df8a4d79a
commit d4eea02801
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
1 changed files with 21 additions and 22 deletions

View File

@ -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()
}
}