Use {once: true} in some event listeners

This commit is contained in:
redphx 2024-07-02 17:20:23 +07:00
parent 277c777121
commit d31a06be89
2 changed files with 2 additions and 4 deletions

View File

@ -11,8 +11,6 @@ export function patchVideoApi() {
// Show video player when it's ready // Show video player when it's ready
const showFunc = function(this: HTMLVideoElement) { const showFunc = function(this: HTMLVideoElement) {
this.style.visibility = 'visible'; this.style.visibility = 'visible';
this.removeEventListener('playing', showFunc);
if (!this.videoWidth) { if (!this.videoWidth) {
return; return;
} }
@ -49,7 +47,7 @@ export function patchVideoApi() {
const $parent = this.parentElement!!; const $parent = this.parentElement!!;
// Video tag is stream player // Video tag is stream player
if (!this.src && $parent.dataset.testid === 'media-container') { if (!this.src && $parent.dataset.testid === 'media-container') {
this.addEventListener('playing', showFunc); this.addEventListener('loadedmetadata', showFunc, {once: true});
} }
return nativePlay.apply(this); return nativePlay.apply(this);

View File

@ -57,7 +57,7 @@ export class Screenshot {
return; return;
} }
$player.parentElement!.addEventListener('animationend', this.#onAnimationEnd); $player.parentElement!.addEventListener('animationend', this.#onAnimationEnd, { once: true });
$player.parentElement!.classList.add('bx-taking-screenshot'); $player.parentElement!.classList.add('bx-taking-screenshot');
const canvasContext = Screenshot.#canvasContext; const canvasContext = Screenshot.#canvasContext;