diff --git a/src/contents/lib/SpeedController.ts b/src/contents/lib/SpeedController.ts index bea8ed8..3125880 100644 --- a/src/contents/lib/SpeedController.ts +++ b/src/contents/lib/SpeedController.ts @@ -1,4 +1,5 @@ import debugging from "debug" +import inspectMediaElements from "./inspectMediaElements" import type { MediaElement } from "../../shared/types" @@ -16,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. */ @@ -100,17 +107,6 @@ export default class SpeedController { } setPlaybackRate(rate: number) { - this.elements = [ - ...document.querySelectorAll("video, audio") - ] as MediaElement[] - debug( - "Setting playback rate to", - rate, - "on", - this.elements.length, - "elements" - ) - this.elements.forEach((element) => { this.setPlaybackRateForElement(rate, element) })