mirror of
https://github.com/LBRYFoundation/Watch-on-LBRY.git
synced 2025-08-23 17:47:26 +00:00
parsing yt time from url fixed
This commit is contained in:
parent
5c61db3ea0
commit
6cc149a5c6
1 changed files with 20 additions and 19 deletions
|
@ -115,12 +115,12 @@ function redirectTo({ platform, pathname }: UpdateContext) {
|
||||||
const parseYouTubeTime = (timeString: string) => {
|
const parseYouTubeTime = (timeString: string) => {
|
||||||
const signs = timeString.replace(/[0-9]/g, '')
|
const signs = timeString.replace(/[0-9]/g, '')
|
||||||
if (signs.length === 0) return timeString
|
if (signs.length === 0) return timeString
|
||||||
const numbers = timeString.replace(/^[0-9]/g, '-').split('-')
|
const numbers = timeString.replace(/[^0-9]/g, '-').split('-')
|
||||||
let total = 0
|
let total = 0
|
||||||
for (let i = 0; i < signs.length; i++) {
|
for (let i = 0; i < signs.length; i++) {
|
||||||
let t = parseInt(numbers[i])
|
let t = parseInt(numbers[i])
|
||||||
switch (signs[i]) {
|
switch (signs[i]) {
|
||||||
case 's': case 'm': t *= 60; case 'h': t *= 60; case 'd': t *= 24; break
|
case 'd': t *= 24; case 'h': t *= 60; case 'm': t *= 60; case 's': break
|
||||||
default: return '0'
|
default: return '0'
|
||||||
}
|
}
|
||||||
total += t
|
total += t
|
||||||
|
@ -131,6 +131,7 @@ function redirectTo({ platform, pathname }: UpdateContext) {
|
||||||
const platformSetting = platformSettings[platform];
|
const platformSetting = platformSettings[platform];
|
||||||
const url = new URL(`${platformSetting.domainPrefix}${pathname}`)
|
const url = new URL(`${platformSetting.domainPrefix}${pathname}`)
|
||||||
const time = new URL(location.href).searchParams.get('t')
|
const time = new URL(location.href).searchParams.get('t')
|
||||||
|
|
||||||
if (time) url.searchParams.append('t', parseYouTubeTime(time))
|
if (time) url.searchParams.append('t', parseYouTubeTime(time))
|
||||||
|
|
||||||
if (platform === 'app') return openApp(url.toString());
|
if (platform === 'app') return openApp(url.toString());
|
||||||
|
|
Loading…
Add table
Reference in a new issue