Update the parse description to identify time marker in anchor links

This commit is contained in:
Marcos Carvalho 2024-05-20 08:33:02 +01:00
parent b833019a14
commit 67d32164d9
No known key found for this signature in database

View file

@ -314,21 +314,20 @@ export default {
},
methods: {
parseDescription(description) {
const timeMarkerRegex = /\d{1,2}:\d{1,2}(:\d{1,2})?/g
const timeMarkerLinkRegex = /<a href="#([^"]*?\b\d{1,2}:\d{1,2}(?::\d{1,2})?)">(.*?)<\/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 `<span class="time-marker cursor-pointer text-blue-400 hover:text-blue-300" data-time="${seekTimeInSeconds}">${displayTime}</span>`
}).replace(timeMarkerRegex, (match) => {
const seekTimeInSeconds = convertToSeconds(match)
return `<span class="time-marker cursor-pointer text-blue-400 hover:text-blue-300" data-time="${seekTimeInSeconds}">${match}</span>`
})
},