From 95a0e4cbc87e54e999d23267d09bb317684d1f08 Mon Sep 17 00:00:00 2001 From: Tyrritt <5675742+Tyrritt@users.noreply.github.com> Date: Wed, 18 Jan 2023 16:56:21 +0100 Subject: [PATCH] Make timestamps in comments seek instead of reload --- src/components/CommentItem.vue | 16 ++++++++++++++++ src/components/WatchVideo.vue | 1 + 2 files changed, 17 insertions(+) diff --git a/src/components/CommentItem.vue b/src/components/CommentItem.vue index 160393a1..b3ed6525 100644 --- a/src/components/CommentItem.vue +++ b/src/components/CommentItem.vue @@ -71,6 +71,7 @@ export default { uploader: { type: String, default: null }, videoId: { type: String, default: null }, }, + emits: ["seek"], data() { return { loadingReplies: false, @@ -79,6 +80,21 @@ export default { nextpage: null, }; }, + mounted() { + const thisComment = this; + this.$el.querySelectorAll("a").forEach(elem => { + if (elem.innerText.match(/(?:[\d]{1,2}:)?(?:[\d]{1,2}):(?:[\d]{1,2})/)) { + elem.addEventListener("click", function (event) { + if (!event || !event.target) return; + if (!event.target.getAttribute("href").match(/(?<=t=)\d{1,}/)) return; + + const time = parseInt(event.target.getAttribute("href").match(/(?<=t=)\d{1,}/)[0]); + thisComment.$emit("seek", time); + event.preventDefault(); + }); + } + }); + }, methods: { async loadReplies() { if (!this.showingReplies && this.loadingReplies) { diff --git a/src/components/WatchVideo.vue b/src/components/WatchVideo.vue index 54699416..1e203598 100644 --- a/src/components/WatchVideo.vue +++ b/src/components/WatchVideo.vue @@ -186,6 +186,7 @@ :comment="comment" :uploader="video.uploader" :video-id="getVideoId()" + @seek="navigate" />