diff --git a/js/app.js b/js/app.js index d6f1ea91..6a16a6d6 100644 --- a/js/app.js +++ b/js/app.js @@ -5572,6 +5572,12 @@ class bitvidApp { } attachVideoListHandler() { + const nextTarget = document; + + if (this._videoListElement === nextTarget && this._videoListClickHandler) { + return; + } + if (this._videoListElement && this._videoListClickHandler) { this._videoListElement.removeEventListener( "click", @@ -5581,10 +5587,6 @@ class bitvidApp { this._videoListClickHandler = null; } - if (!this.videoList) { - return; - } - const handler = async (event) => { const trigger = event.target.closest( "[data-play-magnet],[data-play-url]" @@ -5593,7 +5595,9 @@ class bitvidApp { return; } - if (event.button === 0 && !event.ctrlKey && !event.metaKey) { + const isPrimaryClick = + typeof event.button !== "number" || event.button === 0; + if (isPrimaryClick && !event.ctrlKey && !event.metaKey) { event.preventDefault(); const rawUrlValue = @@ -5626,9 +5630,9 @@ class bitvidApp { } }; - this._videoListElement = this.videoList; + nextTarget.addEventListener("click", handler); + this._videoListElement = nextTarget; this._videoListClickHandler = handler; - this.videoList.addEventListener("click", handler); } /** diff --git a/js/channelProfile.js b/js/channelProfile.js index 3a3865d8..8e0b6dc1 100644 --- a/js/channelProfile.js +++ b/js/channelProfile.js @@ -794,7 +794,6 @@ async function loadUserVideos(pubkey) { app.handleUrlHealthBadge({ video, url, badgeEl }); }); - window.app.videoList = container; window.app.attachVideoListHandler(); // Lazy-load images diff --git a/js/subscriptions.js b/js/subscriptions.js index e3147a25..95392d7f 100644 --- a/js/subscriptions.js +++ b/js/subscriptions.js @@ -614,10 +614,7 @@ class SubscriptionsManager { window.app.handleUrlHealthBadge({ video, url, badgeEl }); }); - if (window.app) { - window.app.videoList = container; - window.app.attachVideoListHandler?.(); - } + window.app?.attachVideoListHandler?.(); // Lazy-load const lazyEls = container.querySelectorAll("[data-lazy]");