From dd578f80dec5f57924fcbd32a668e222cc5b25ba Mon Sep 17 00:00:00 2001 From: charles Date: Mon, 28 Aug 2023 21:13:08 -0600 Subject: [PATCH] fix: speed toggle on/off on extension init (#89) --- actions/init.js | 6 ++++++ models/video.js | 9 ++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/actions/init.js b/actions/init.js index 3c7dc6e0..a3d4e246 100644 --- a/actions/init.js +++ b/actions/init.js @@ -105,9 +105,15 @@ async function load() { await store.populate() const app = new App({ video, store }) + const enabled = sessionStorage.getItem('enabled') == 'true' + video.active = enabled document.addEventListener('app.enabled', async e => { const { enabled } = e.detail + + sessionStorage.setItem('enabled', enabled) + video.active = enabled + enabled ? await app.connect() : app.disconnect() }) } diff --git a/models/video.js b/models/video.js index 9234cd23..dbafee6d 100644 --- a/models/video.js +++ b/models/video.js @@ -2,7 +2,7 @@ import { currentData } from '../data/current.js' export default class VideoElement { #video - #active = false + #active = sessionStorage.getItem('enabled') == 'true' constructor(video) { this.#video = video @@ -10,14 +10,17 @@ export default class VideoElement { this.#setPlaybackRateProtection() } + set active(value) { + this.#active = value + } + async activate() { - this.#active = true await this.#handleTrackChange() } reset() { - this.#active = false this.clearCurrentSpeed() + this.playbackRate = 1 this.preservesPitch = true }