Add only one listener on the window

This commit is contained in:
Tyrritt 2023-01-26 18:23:49 +01:00
parent 95a0e4cbc8
commit 8311888501
2 changed files with 13 additions and 17 deletions

View file

@ -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) {

View file

@ -186,7 +186,6 @@
:comment="comment"
:uploader="video.uploader"
:video-id="getVideoId()"
@seek="navigate"
/>
</div>
@ -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;
});