From d838e2fa1b0353cbe85219ebe6339230515ce7e3 Mon Sep 17 00:00:00 2001 From: Jade Macho Date: Tue, 14 May 2024 22:54:04 +0200 Subject: [PATCH] Transcript: Ignore scroll to change volume --- mods/Transcript.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/mods/Transcript.js b/mods/Transcript.js index c74de3b..8913726 100644 --- a/mods/Transcript.js +++ b/mods/Transcript.js @@ -89,6 +89,9 @@ export default JadefinIntegrity("Transcript", import.meta.url, () => new (class const worker = detail.worker; worker.addEventListener("message", this.onSsaAssWorkerMessage.bind(this)); }); + + this.initHookDocumentAddEventListener(); + this.initHookDocumentRemoveEventListener(); } get isEnabled() { @@ -241,6 +244,45 @@ export default JadefinIntegrity("Transcript", import.meta.url, () => new (class }; } + initHookDocumentAddEventListener() { + const orig = this._addEventListener = document.addEventListener.bind(document); + document.addEventListener = (type, listener, options) => { + if (type == "wheel") { + const listenerStr = listener.toString(); + + // Anonymous function in playback-video + if (listenerStr.indexOf("volumeUp") != -1 && + listenerStr.indexOf("volumeDown") != -1 && + listenerStr.indexOf("deltaY") != -1) { + this.log.i("Wrapping playback-video wrap listener"); + this.log.dir(listener); + + const origListener = this._playbackWheel = listener; + listener = this._playbackWheelWrap = (e) => { + if (JadefinUtils.hasParent(e.target, this._osdTranscript)) { + return; + } + + return origListener(e); + }; + } + } + + return orig(type, listener, options); + }; + } + + initHookDocumentRemoveEventListener() { + const orig = this._removeEventListener = document.removeEventListener.bind(document); + document.removeEventListener = (type, listener, options) => { + if (listener == this._playbackWheel) { + listener = this._playbackWheelWrap; + } + + return orig(type, listener, options); + }; + } + onSsaAssCanvasAdded() { const htmlVideoPlayer = this._ssaAssFetching;