parsing yt time from url fixed

This commit is contained in:
Shiba 2021-12-11 20:05:30 +00:00
parent 5c61db3ea0
commit 6cc149a5c6

View file

@ -115,12 +115,12 @@ function redirectTo({ platform, pathname }: UpdateContext) {
const parseYouTubeTime = (timeString: string) => {
const signs = timeString.replace(/[0-9]/g, '')
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
for (let i = 0; i < signs.length; i++) {
let t = parseInt(numbers[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'
}
total += t
@ -131,6 +131,7 @@ function redirectTo({ platform, pathname }: UpdateContext) {
const platformSetting = platformSettings[platform];
const url = new URL(`${platformSetting.domainPrefix}${pathname}`)
const time = new URL(location.href).searchParams.get('t')
if (time) url.searchParams.append('t', parseYouTubeTime(time))
if (platform === 'app') return openApp(url.toString());