From 67d32164d902d98e12644ef9c24d1bf96c8b8871 Mon Sep 17 00:00:00 2001 From: Marcos Carvalho Date: Mon, 20 May 2024 08:33:02 +0100 Subject: [PATCH] Update the parse description to identify time marker in anchor links --- pages/item/_id/_episode/index.vue | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/pages/item/_id/_episode/index.vue b/pages/item/_id/_episode/index.vue index d0ccd69d..c33ee6f4 100644 --- a/pages/item/_id/_episode/index.vue +++ b/pages/item/_id/_episode/index.vue @@ -314,21 +314,20 @@ export default { }, methods: { parseDescription(description) { - const timeMarkerRegex = /\d{1,2}:\d{1,2}(:\d{1,2})?/g + const timeMarkerLinkRegex = /(.*?)<\/a>/g + const timeMarkerRegex = /\b\d{1,2}:\d{1,2}(?::\d{1,2})?\b/g - return description.replace(timeMarkerRegex, (match) => { - const time = match.replace(/[()]/g, '') + function convertToSeconds(time) { const timeParts = time.split(':').map(Number) - let seekTimeInSeconds - - if (timeParts.length === 2) { - const [minutes, seconds] = timeParts - seekTimeInSeconds = minutes * 60 + seconds - } else { - const [hours, minutes, seconds] = timeParts - seekTimeInSeconds = hours * 3600 + minutes * 60 + seconds - } + return timeParts.reduce((acc, part, index) => acc * 60 + part, 0) + } + return description.replace(timeMarkerLinkRegex, (match, href, displayTime) => { + const time = displayTime.match(timeMarkerRegex)[0] + const seekTimeInSeconds = convertToSeconds(time) + return `${displayTime}` + }).replace(timeMarkerRegex, (match) => { + const seekTimeInSeconds = convertToSeconds(match) return `${match}` }) },