From 83118885019e3f5080e2e4cb55677cec7c869477 Mon Sep 17 00:00:00 2001 From: Tyrritt <5675742+Tyrritt@users.noreply.github.com> Date: Thu, 26 Jan 2023 18:23:49 +0100 Subject: [PATCH] Add only one listener on the window --- src/components/CommentItem.vue | 16 ---------------- src/components/WatchVideo.vue | 14 +++++++++++++- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/components/CommentItem.vue b/src/components/CommentItem.vue index b3ed6525..160393a1 100644 --- a/src/components/CommentItem.vue +++ b/src/components/CommentItem.vue @@ -71,7 +71,6 @@ export default { uploader: { type: String, default: null }, videoId: { type: String, default: null }, }, - emits: ["seek"], data() { return { loadingReplies: false, @@ -80,21 +79,6 @@ 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 1e203598..ea7e48e7 100644 --- a/src/components/WatchVideo.vue +++ b/src/components/WatchVideo.vue @@ -186,7 +186,6 @@ :comment="comment" :uploader="video.uploader" :video-id="getVideoId()" - @seek="navigate" /> @@ -337,6 +336,19 @@ export default { this.getPlaylistData(); this.getSponsors(); if (!this.isEmbed && this.showComments) this.getComments(); + window.addEventListener("click", event => { + if (!event || !event.target) return; + var target = event.target; + if ( + !target.nodeName == "A" || + !target.getAttribute("href") || + !target.innerText.match(/(?:[\d]{1,2}:)?(?:[\d]{1,2}):(?:[\d]{1,2})/) + ) + return; + const time = parseInt(event.target.getAttribute("href").match(/(?<=t=)\d+/)[0]); + this.navigate(time); + event.preventDefault(); + }); window.addEventListener("resize", () => { this.smallView = this.smallViewQuery.matches; });