From f2e29c48b701d884f5136cf523499ba951b4e9d8 Mon Sep 17 00:00:00 2001 From: Jimmy <9859727+Quantizr@users.noreply.github.com> Date: Thu, 9 Mar 2023 02:05:12 -0800 Subject: [PATCH] Prevent unnecessary creation of MutationObservers Moved inspectMediaElements to the constructor where it dynamically updates this.elements --- src/contents/lib/SpeedController.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/contents/lib/SpeedController.ts b/src/contents/lib/SpeedController.ts index 2041840..3125880 100644 --- a/src/contents/lib/SpeedController.ts +++ b/src/contents/lib/SpeedController.ts @@ -17,6 +17,12 @@ export default class SpeedController { elements: MediaElement[] = [] + constructor() { + inspectMediaElements((element: MediaElement) => { + this.elements.push(element) + }) + } + /** * Fixes issues changing the playback rate by temporarily blocking `ratechange` event listeners. */ @@ -101,7 +107,7 @@ export default class SpeedController { } setPlaybackRate(rate: number) { - inspectMediaElements((element: MediaElement) => { + this.elements.forEach((element) => { this.setPlaybackRateForElement(rate, element) }) }