From 00eeeb2a5add899441a94353b8f896bef1ada957 Mon Sep 17 00:00:00 2001 From: Marcos Carvalho Date: Sun, 19 May 2024 10:40:04 +0100 Subject: [PATCH] Add detectable timestamp --- pages/item/_id/_episode/index.vue | 63 ++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/pages/item/_id/_episode/index.vue b/pages/item/_id/_episode/index.vue index d178dab1..1e915bc3 100644 --- a/pages/item/_id/_episode/index.vue +++ b/pages/item/_id/_episode/index.vue @@ -41,7 +41,7 @@ -

+

@@ -116,6 +116,9 @@ export default { } }, computed: { + transformedDescription() { + return this.parseDescription(this.description) + }, bookCoverAspectRatio() { return this.$store.getters['libraries/getBookCoverAspectRatio'] }, @@ -310,6 +313,58 @@ export default { } }, methods: { + parseDescription(description) { + const timeMarkerRegex = /\d{1,2}:\d{1,2}(:\d{1,2})?/g + + return description.replace(timeMarkerRegex, (match) => { + const time = match.replace(/[()]/g, '') + 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 `${match}` + }) + }, + clickPlaybackTime(event) { + const startTime = event.target.getAttribute('data-time') + if (this.playerIsStartingPlayback) return + + this.$hapticsImpact() + + this.$store.commit('setPlayerIsStartingPlayback', this.episode.id) + + const playbackData = { + libraryItemId: this.libraryItemId, + episodeId: this.episode.id, + serverLibraryItemId: this.serverLibraryItemId, + serverEpisodeId: this.serverEpisodeId, + startTime + } + + if (this.localEpisodeId && this.localLibraryItemId && !this.isLocal) { + playbackData.libraryItemId = this.localLibraryItemId + playbackData.episodeId = this.localEpisodeId + } + + this.$eventBus.$emit('play-item', playbackData) + }, + bindTimeMarkerEvents() { + const container = document.querySelector('.description-container') + if (container) { + container.addEventListener('click', (event) => { + if (event.target.classList.contains('time-marker')) { + this.clickPlaybackTime(event) + } + }) + } + }, async deleteLocalEpisode() { await this.$hapticsImpact() @@ -557,9 +612,13 @@ export default { }, mounted() { this.$eventBus.$on('new-local-library-item', this.newLocalLibraryItem) + this.bindTimeMarkerEvents() }, beforeDestroy() { this.$eventBus.$off('new-local-library-item', this.newLocalLibraryItem) + document.querySelectorAll('.time-marker').forEach(marker => { + marker.removeEventListener('click', this.clickPlaybackTime) + }) } } - \ No newline at end of file +