From 43afa77b4e668a66cc2912c026d356db32b12457 Mon Sep 17 00:00:00 2001 From: SashaXser <24498484+SashaXser@users.noreply.github.com> Date: Fri, 19 Jan 2024 14:51:54 +0400 Subject: [PATCH] Update index.js --- src/index.js | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/src/index.js b/src/index.js index 3c1c12520..e8092f974 100644 --- a/src/index.js +++ b/src/index.js @@ -238,12 +238,7 @@ class VideoHandler { this.srcObserver.observe(this.video, { attributeFilter: ["src", "currentSrc"], }); - this.srcObjectInterval = setInterval(async () => { - if (this.videoLastSrcObject !== this.video.srcObject) { - this.videoLastSrcObject = this.video.srcObject; - await this.handleSrcChanged(); - } - }, 100); + this.video.addEventListener("canplaythrough", this.handleSrcChanged); this.stopTranslationBound = this.stopTranslation.bind(this); this.handleVideoEventBound = this.handleVideoEvent.bind(this); this.changeOpacityOnEventBound = this.changeOpacityOnEvent.bind(this); @@ -1485,7 +1480,7 @@ class VideoHandler { videoData.translationHelp = null; // ! should be null for ALL websites except coursera and udemy ! videoData.isStream = false; // by default, we request the translation of the video - videoData.duration = this.video?.duration || 343; // ! if 0 - we get 400 error + videoData.duration = this.video.duration; // ! if 0 - we get 400 error videoData.videoId = getVideoId(this.site.host, this.video); videoData.detectedLanguage = this.translateFromLang; videoData.responseLanguage = this.translateToLang; @@ -1687,9 +1682,6 @@ class VideoHandler { console.log("[VOT] Video Data: ", this.videoData); const videoURL = `${this.site.url}${VIDEO_ID}`; - // fix enabling the old requested voiceover when changing the language to the native language (#) - this.videoValidator(); - if (isStream) { debug.log("Executed stream translation"); // if (BUILD_MODE === "cloudflare") { @@ -2067,6 +2059,7 @@ class VideoHandler { debug.log("[VideoHandler] src changed", this); if (!(await this.waitInitialization())) return; + if (!this.video.duration) return; this.stopTranslation();