From d31a06be89dfd7f4f7de86837d63e83e5475b3aa Mon Sep 17 00:00:00 2001 From: redphx <96280+redphx@users.noreply.github.com> Date: Tue, 2 Jul 2024 17:20:23 +0700 Subject: [PATCH] Use {once: true} in some event listeners --- src/utils/monkey-patches.ts | 4 +--- src/utils/screenshot.ts | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/monkey-patches.ts b/src/utils/monkey-patches.ts index 11ad2ad..7a04649 100644 --- a/src/utils/monkey-patches.ts +++ b/src/utils/monkey-patches.ts @@ -11,8 +11,6 @@ export function patchVideoApi() { // Show video player when it's ready const showFunc = function(this: HTMLVideoElement) { this.style.visibility = 'visible'; - this.removeEventListener('playing', showFunc); - if (!this.videoWidth) { return; } @@ -49,7 +47,7 @@ export function patchVideoApi() { const $parent = this.parentElement!!; // Video tag is stream player if (!this.src && $parent.dataset.testid === 'media-container') { - this.addEventListener('playing', showFunc); + this.addEventListener('loadedmetadata', showFunc, {once: true}); } return nativePlay.apply(this); diff --git a/src/utils/screenshot.ts b/src/utils/screenshot.ts index 215d954..d763f73 100644 --- a/src/utils/screenshot.ts +++ b/src/utils/screenshot.ts @@ -57,7 +57,7 @@ export class Screenshot { return; } - $player.parentElement!.addEventListener('animationend', this.#onAnimationEnd); + $player.parentElement!.addEventListener('animationend', this.#onAnimationEnd, { once: true }); $player.parentElement!.classList.add('bx-taking-screenshot'); const canvasContext = Screenshot.#canvasContext;