From d384f1d77c7191d36c60f83bcadd63662c9bd4c1 Mon Sep 17 00:00:00 2001 From: Toil <62353659+ilyhalight@users.noreply.github.com> Date: Wed, 28 Aug 2024 03:40:42 +0300 Subject: [PATCH] removed extra check --- dist/vot-min.user.js | 4 ++-- dist/vot.user.js | 7 ++----- src/index.js | 7 ++----- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/dist/vot-min.user.js b/dist/vot-min.user.js index 78702cf0..7a4c4ae5 100644 --- a/dist/vot-min.user.js +++ b/dist/vot-min.user.js @@ -264,7 +264,7 @@ ${100*this.getVideoVolume()}%`,100*this.getVideoVolume()),this.votVideoVolumeSlider.container.hidden=1!==this.data.showVideoSlider||"success"!==this.votButton.container.dataset.status,this.votMenu.bodyContainer.appendChild(this.votVideoVolumeSlider.container),this.votVideoTranslationVolumeSlider=Ve.createSlider(Gt`${N.get("VOTVolumeTranslation")}: ${this.data?.defaultVolume??100}%`,this.data?.defaultVolume??100,0,this.data.audioBooster?900:100),this.votVideoTranslationVolumeSlider.container.hidden="success"!==this.votButton.container.dataset.status,this.votMenu.bodyContainer.appendChild(this.votVideoTranslationVolumeSlider.container),this.votMenu.container.addEventListener("click",(t=>{t.preventDefault(),t.stopPropagation(),t.stopImmediatePropagation()})),this.votSettingsDialog=Ve.createDialog(N.get("VOTSettings")),document.documentElement.appendChild(this.votSettingsDialog.container),this.votTranslationHeader=Ve.createHeader(N.get("translationSettings")),this.votSettingsDialog.bodyContainer.appendChild(this.votTranslationHeader),this.votAutoTranslateCheckbox=Ve.createCheckbox(N.get("VOTAutoTranslate"),this.data?.autoTranslate??!1),this.votSettingsDialog.bodyContainer.appendChild(this.votAutoTranslateCheckbox.container),this.votDontTranslateYourLangSelect=Ve.createVOTSelect(N.get("langs")[this.data.dontTranslateLanguage],N.get("VOTDontTranslateYourLang"),Je(at,this.data.dontTranslateLanguage),{onSelectCb:async t=>{this.data.dontTranslateLanguage=t.target.dataset.votValue,await _.set("dontTranslateLanguage",this.data.dontTranslateLanguage)},labelElement:Ve.createCheckbox(N.get("VOTDontTranslateYourLang"),this.data?.dontTranslateYourLang??!0).container}),this.votSettingsDialog.bodyContainer.appendChild(this.votDontTranslateYourLangSelect.container),this.changehotkeyButton=Ve.createOutlinedButton(Ke(this.data.hotkeyButton)),this.votSettingsDialog.bodyContainer.appendChild(this.changehotkeyButton),this.votAutoSetVolumeCheckbox=Ve.createCheckbox(`${N.get("VOTAutoSetVolume")}`,this.data?.autoSetVolumeYandexStyle??!0),this.votSettingsDialog.bodyContainer.appendChild(this.votAutoSetVolumeCheckbox.container),this.votAutoSetVolumeSlider=Ve.createSlider(Gt`${100*(this.data?.autoVolume??pe)}%`,100*(this.data?.autoVolume??pe),0,100),this.votSettingsDialog.bodyContainer.appendChild(this.votAutoSetVolumeSlider.container),this.votShowVideoSliderCheckbox=Ve.createCheckbox(N.get("VOTShowVideoSlider"),this.data?.showVideoSlider??!1),this.votSettingsDialog.bodyContainer.appendChild(this.votShowVideoSliderCheckbox.container),this.votAudioBoosterCheckbox=Ve.createCheckbox(N.get("VOTAudioBooster"),this.data?.audioBooster??!1),this.votAudioBoosterCheckbox.container.hidden=!this.audioContext,this.votSettingsDialog.bodyContainer.appendChild(this.votAudioBoosterCheckbox.container),this.votSyncVolumeCheckbox=Ve.createCheckbox(N.get("VOTSyncVolume"),this.data?.syncVolume??!1),this.votSettingsDialog.bodyContainer.appendChild(this.votSyncVolumeCheckbox.container),this.votTranslationServiceSelect=Ve.createVOTSelect(this.data.translationService.toUpperCase(),N.get("VOTTranslationService"),Je(Oe,this.data.translationService),{onSelectCb:async t=>{this.data.translationService=t.target.dataset.votValue,await _.set("translationService",this.data.translationService)},labelElement:Ve.createCheckbox(N.get("VOTTranslateAPIErrors"),this.data.translateAPIErrors??!0).container}),this.votTranslationServiceSelect.container.hidden="ru"===N.lang,this.votSettingsDialog.bodyContainer.appendChild(this.votTranslationServiceSelect.container),this.votDetectServiceSelect=Ve.createVOTSelect(this.data.detectService.toUpperCase(),N.get("VOTDetectService"),Je(Ie,this.data.detectService),{onSelectCb:async t=>{this.data.detectService=t.target.dataset.votValue,await _.set("detectService",this.data.detectService)},labelElement:Ve.createVOTSelectLabel(N.get("VOTDetectService"))}),this.votSettingsDialog.bodyContainer.appendChild(this.votDetectServiceSelect.container),this.votSubtitlesHeader=Ve.createHeader(N.get("subtitlesSettings")),this.votSettingsDialog.bodyContainer.appendChild(this.votSubtitlesHeader),this.votSubtitlesDetails=Ve.createDetails(N.get("VOTSubtitlesDesign")),this.votSettingsDialog.bodyContainer.appendChild(this.votSubtitlesDetails.container),this.votProxyHeader=Ve.createHeader(N.get("proxySettings")),this.votSettingsDialog.bodyContainer.appendChild(this.votProxyHeader),this.votM3u8ProxyHostTextfield=Ve.createTextfield(N.get("VOTM3u8ProxyHost"),this.data?.m3u8ProxyHost,ue),this.votSettingsDialog.bodyContainer.appendChild(this.votM3u8ProxyHostTextfield.container),this.votProxyWorkerHostTextfield=Ve.createTextfield(N.get("VOTProxyWorkerHost"),this.data?.proxyWorkerHost,ce),this.votSettingsDialog.bodyContainer.appendChild(this.votProxyWorkerHostTextfield.container),this.votAudioProxyCheckbox=Ve.createCheckbox(N.get("VOTAudioProxy"),this.data?.audioProxy??!1),this.votSettingsDialog.bodyContainer.appendChild(this.votAudioProxyCheckbox.container),this.votAboutHeader=Ve.createHeader(N.get("about")),this.votSettingsDialog.bodyContainer.appendChild(this.votAboutHeader),this.votLanguageSelect=Ve.createVOTSelect(N.get("langs")[_.syncGet("locale-lang-override","auto")],N.get("VOTMenuLanguage"),Je($,_.syncGet("locale-lang-override","auto")),{onSelectCb:async t=>{await _.set("locale-lang-override",t.target.dataset.votValue)},labelElement:Ve.createVOTSelectLabel(N.get("VOTMenuLanguage"))}),this.votSettingsDialog.bodyContainer.appendChild(this.votLanguageSelect.container),this.votShowPiPButtonCheckbox=Ve.createCheckbox(N.get("VOTShowPiPButton"),this.data?.showPiPButton??!1),this.votShowPiPButtonCheckbox.container.hidden=!F(),this.votSettingsDialog.bodyContainer.appendChild(this.votShowPiPButtonCheckbox.container),this.votVersionInfo=Ve.createInformation(`${N.get("VOTVersion")}:`,GM_info.script.version),this.votSettingsDialog.bodyContainer.appendChild(this.votVersionInfo.container),this.votAuthorsInfo=Ve.createInformation(`${N.get("VOTAuthors")}:`,GM_info.script.author),this.votSettingsDialog.bodyContainer.appendChild(this.votAuthorsInfo.container),this.votLoaderInfo=Ve.createInformation(`${N.get("VOTLoader")}:`,`${GM_info.scriptHandler} v${GM_info.version}`),this.votSettingsDialog.bodyContainer.appendChild(this.votLoaderInfo.container),this.votBrowserInfo=Ve.createInformation(`${N.get("VOTBrowser")}:`,`${We.browser.name} ${We.browser.version} (${We.os.name} ${We.os.version})`),this.votSettingsDialog.bodyContainer.appendChild(this.votBrowserInfo.container),this.votResetSettingsButton=Ve.createButton(N.get("resetSettings")),this.votSettingsDialog.bodyContainer.appendChild(this.votResetSettingsButton)}async handleTranslationBtnClick(){if(this.audio.src)return E.log("[click translationBtn] audio.src is not empty"),void this.stopTranslate();if(this.hls.url)return E.log("[click translationBtn] hls is not empty"),void this.stopTranslate();try{if(E.log("[click translationBtn] trying execute translation"),!this.videoData.videoId)throw new gt("VOTNoVideoIDFound");"vk"===this.site.host&&"clips"===this.site.additionalData&&(this.videoData=await this.getVideoData()),await this.translateExecutor(this.videoData.videoId)}catch(t){console.error("[VOT]",t),"VOTLocalizedError"===t?.name?this.transformBtn("error",t.localizedMessage):this.transformBtn("error",t)}}initUIEvents(){this.votButton.translateButton.addEventListener("click",(async()=>{await this.handleTranslationBtnClick()})),this.votButton.pipButton.addEventListener("click",(()=>{(async()=>{this.video!==document.pictureInPictureElement?await this.video.requestPictureInPicture():await document.exitPictureInPicture()})()})),this.votButton.menuButton.addEventListener("click",(()=>{this.votMenu.container.hidden=!this.votMenu.container.hidden})),this.votButton.container.addEventListener("mousedown",(()=>{this.dragging=!0})),this.container.addEventListener("mouseup",(()=>{this.dragging=!1})),this.container.addEventListener("mousemove",(async t=>{if(this.dragging){t.preventDefault();const e=t.clientX/this.container.clientWidth*100,o=this.container.clientWidth&&this.container.clientWidth>550,n=e<=44?"left":e>=66?"right":"default";this.data.buttonPos=o?n:"default",this.votButton.container.dataset.direction="default"===this.data.buttonPos?"row":"column",this.votButton.container.dataset.position=this.data.buttonPos,this.votMenu.container.dataset.position=this.data.buttonPos,o&&await _.set("buttonPos",this.data.buttonPos)}})),this.votDownloadButton.addEventListener("click",(()=>{this.downloadTranslationUrl&&window.open(this.downloadTranslationUrl,"_blank").focus()})),this.votDownloadSubtitlesButton.addEventListener("click",(async()=>{const t=this.data.subtitlesDownloadFormat,e=kt(this.yandexSubtitles,t),o=new Blob(["json"===t?JSON.stringify(e):e],{type:"text/plain"}),n=URL.createObjectURL(o),i=document.createElement("a");i.href=n,i.download=`subtitles_${this.videoData.videoId}.${t}`,i.click(),URL.revokeObjectURL(n)})),this.votSettingsButton.addEventListener("click",(()=>{this.votSettingsDialog.container.hidden=!this.votSettingsDialog.container.hidden,(document.fullscreenElement||document.webkitFullscreenElement)&&(document.webkitExitFullscreen&&document.webkitExitFullscreen(),document.exitFullscreen&&document.exitFullscreen())})),this.votVideoVolumeSlider.input.addEventListener("input",(t=>{const e=Number(t.target.value);this.votVideoVolumeSlider.label.querySelector("strong").textContent=`${e}%`,this.setVideoVolume(e/100),this.data.syncVolume&&this.syncVolumeWrapper("video",e)})),this.votVideoTranslationVolumeSlider.input.addEventListener("input",(t=>{(async()=>{this.data.defaultVolume=Number(t.target.value),await _.set("defaultVolume",this.data.defaultVolume),this.votVideoTranslationVolumeSlider.label.querySelector("strong").textContent=`${this.data.defaultVolume}%`,this.setAudioVolume(this.data.defaultVolume/100),this.data.syncVolume&&(this.syncVolumeWrapper("translation",this.data.defaultVolume),["youtube","googledrive"].includes(this.site.host)&&"mobile"!==this.site.additionalData&&this.setVideoVolume(this.tempOriginalVolume/100))})()}));{this.votAutoTranslateCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.autoTranslate=Number(t.target.checked),await Promise.all([_.set("autoTranslate",this.data.autoTranslate),this.autoTranslate()]),E.log("autoTranslate value changed. New value: ",this.data.autoTranslate)})()})),this.votDontTranslateYourLangSelect.labelElement.addEventListener("change",(t=>{(async()=>{this.data.dontTranslateYourLang=Number(t.target.checked),await _.set("dontTranslateYourLang",this.data.dontTranslateYourLang),E.log("dontTranslateYourLang value changed. New value: ",this.data.dontTranslateYourLang)})()}));const t=async t=>{await _.set("hotkeyButton",t),this.data.hotkeyButton=t,this.changehotkeyButton.textContent=Ke(t)},e=o=>{const n="Escape"===o.code?null:o.code;t(n),document.removeEventListener("keydown",e)};this.changehotkeyButton.addEventListener("click",(()=>{this.changehotkeyButton.textContent=N.get("VOTPressNewHotkey"),document.addEventListener("keydown",e)})),this.votAutoSetVolumeCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.autoSetVolumeYandexStyle=Number(t.target.checked),await _.set("autoSetVolumeYandexStyle",this.data.autoSetVolumeYandexStyle),E.log("autoSetVolumeYandexStyle value changed. New value: ",this.data.autoSetVolumeYandexStyle)})()})),this.votAutoSetVolumeSlider.input.addEventListener("input",(t=>{(async()=>{const e=Number(t.target.value);this.data.autoVolume=(e/100).toFixed(2),await _.set("autoVolume",this.data.autoVolume),this.votAutoSetVolumeSlider.label.querySelector("strong").textContent=`${e}%`})()})),this.votShowVideoSliderCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.showVideoSlider=Number(t.target.checked),await _.set("showVideoSlider",this.data.showVideoSlider),E.log("showVideoSlider value changed. New value: ",this.data.showVideoSlider),this.votVideoVolumeSlider.container.hidden=1!==this.data.showVideoSlider||"success"!==this.votButton.container.dataset.status})()})),this.votAudioBoosterCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.audioBooster=Number(t.target.checked),await _.set("audioBooster",this.data.audioBooster),E.log("audioBooster value changed. New value: ",this.data.audioBooster);const e=this.votVideoTranslationVolumeSlider.input.value;this.votVideoTranslationVolumeSlider.input.max=this.data.audioBooster?900:100,this.data.audioBooster||(this.votVideoTranslationVolumeSlider.input.value=e>100?100:e,this.votVideoTranslationVolumeSlider.input.dispatchEvent(new Event("input")))})()})),this.votSyncVolumeCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.syncVolume=Number(t.target.checked),await _.set("syncVolume",this.data.syncVolume),E.log("syncVolume value changed. New value: ",this.data.syncVolume)})()})),this.votTranslationServiceSelect.labelElement.addEventListener("change",(t=>{(async()=>{this.data.translateAPIErrors=Number(t.target.checked),await _.set("translateAPIErrors",this.data.translateAPIErrors),E.log("translateAPIErrors value changed. New value: ",this.data.translateAPIErrors)})()})),this.votSubtitlesDetails.container.addEventListener("click",(()=>{this.votSubtitlesDialog=Ve.createDialog(N.get("VOTSubtitlesDesign")),this.votSubtitlesDialog.container.classList.add("vot-dialog-temp"),this.votSubtitlesDialog.container.hidden=!1,this.votSubtitlesDialog.backdrop.onclick=this.votSubtitlesDialog.closeButton.onclick=()=>{this.votSubtitlesDialog.container.remove()},this.votSubtitlesHighlightWordsCheckbox=Ve.createCheckbox(N.get("VOTHighlightWords"),this.data?.highlightWords??!1),this.votSubtitlesDialog.bodyContainer.appendChild(this.votSubtitlesHighlightWordsCheckbox.container),this.votSubtitlesDownloadFormatSelect=Ve.createVOTSelect(this.data.subtitlesDownloadFormat.toUpperCase(),N.get("VOTSubtitlesDownloadFormat"),Je(st,this.data.subtitlesDownloadFormat),{onSelectCb:async t=>{this.data.subtitlesDownloadFormat=t.target.dataset.votValue,await _.set("subtitlesDownloadFormat",this.data.subtitlesDownloadFormat)},labelElement:Ve.createVOTSelectLabel(N.get("VOTSubtitlesDownloadFormat"))}),this.votSubtitlesDialog.bodyContainer.appendChild(this.votSubtitlesDownloadFormatSelect.container),this.votSubtitlesMaxLengthSlider=Ve.createSlider(Gt`${N.get("VOTSubtitlesMaxLength")}: + >`,100*(this.data?.autoVolume??pe),0,100),this.votSettingsDialog.bodyContainer.appendChild(this.votAutoSetVolumeSlider.container),this.votShowVideoSliderCheckbox=Ve.createCheckbox(N.get("VOTShowVideoSlider"),this.data?.showVideoSlider??!1),this.votSettingsDialog.bodyContainer.appendChild(this.votShowVideoSliderCheckbox.container),this.votAudioBoosterCheckbox=Ve.createCheckbox(N.get("VOTAudioBooster"),this.data?.audioBooster??!1),this.votAudioBoosterCheckbox.container.hidden=!this.audioContext,this.votSettingsDialog.bodyContainer.appendChild(this.votAudioBoosterCheckbox.container),this.votSyncVolumeCheckbox=Ve.createCheckbox(N.get("VOTSyncVolume"),this.data?.syncVolume??!1),this.votSettingsDialog.bodyContainer.appendChild(this.votSyncVolumeCheckbox.container),this.votTranslationServiceSelect=Ve.createVOTSelect(this.data.translationService.toUpperCase(),N.get("VOTTranslationService"),Je(Oe,this.data.translationService),{onSelectCb:async t=>{this.data.translationService=t.target.dataset.votValue,await _.set("translationService",this.data.translationService)},labelElement:Ve.createCheckbox(N.get("VOTTranslateAPIErrors"),this.data.translateAPIErrors??!0).container}),this.votTranslationServiceSelect.container.hidden="ru"===N.lang,this.votSettingsDialog.bodyContainer.appendChild(this.votTranslationServiceSelect.container),this.votDetectServiceSelect=Ve.createVOTSelect(this.data.detectService.toUpperCase(),N.get("VOTDetectService"),Je(Ie,this.data.detectService),{onSelectCb:async t=>{this.data.detectService=t.target.dataset.votValue,await _.set("detectService",this.data.detectService)},labelElement:Ve.createVOTSelectLabel(N.get("VOTDetectService"))}),this.votSettingsDialog.bodyContainer.appendChild(this.votDetectServiceSelect.container),this.votSubtitlesHeader=Ve.createHeader(N.get("subtitlesSettings")),this.votSettingsDialog.bodyContainer.appendChild(this.votSubtitlesHeader),this.votSubtitlesDetails=Ve.createDetails(N.get("VOTSubtitlesDesign")),this.votSettingsDialog.bodyContainer.appendChild(this.votSubtitlesDetails.container),this.votProxyHeader=Ve.createHeader(N.get("proxySettings")),this.votSettingsDialog.bodyContainer.appendChild(this.votProxyHeader),this.votM3u8ProxyHostTextfield=Ve.createTextfield(N.get("VOTM3u8ProxyHost"),this.data?.m3u8ProxyHost,ue),this.votSettingsDialog.bodyContainer.appendChild(this.votM3u8ProxyHostTextfield.container),this.votProxyWorkerHostTextfield=Ve.createTextfield(N.get("VOTProxyWorkerHost"),this.data?.proxyWorkerHost,ce),this.votSettingsDialog.bodyContainer.appendChild(this.votProxyWorkerHostTextfield.container),this.votAudioProxyCheckbox=Ve.createCheckbox(N.get("VOTAudioProxy"),this.data?.audioProxy??!1),this.votSettingsDialog.bodyContainer.appendChild(this.votAudioProxyCheckbox.container),this.votAboutHeader=Ve.createHeader(N.get("about")),this.votSettingsDialog.bodyContainer.appendChild(this.votAboutHeader),this.votLanguageSelect=Ve.createVOTSelect(N.get("langs")[_.syncGet("locale-lang-override","auto")],N.get("VOTMenuLanguage"),Je($,_.syncGet("locale-lang-override","auto")),{onSelectCb:async t=>{await _.set("locale-lang-override",t.target.dataset.votValue)},labelElement:Ve.createVOTSelectLabel(N.get("VOTMenuLanguage"))}),this.votSettingsDialog.bodyContainer.appendChild(this.votLanguageSelect.container),this.votShowPiPButtonCheckbox=Ve.createCheckbox(N.get("VOTShowPiPButton"),this.data?.showPiPButton??!1),this.votShowPiPButtonCheckbox.container.hidden=!F(),this.votSettingsDialog.bodyContainer.appendChild(this.votShowPiPButtonCheckbox.container),this.votVersionInfo=Ve.createInformation(`${N.get("VOTVersion")}:`,GM_info.script.version),this.votSettingsDialog.bodyContainer.appendChild(this.votVersionInfo.container),this.votAuthorsInfo=Ve.createInformation(`${N.get("VOTAuthors")}:`,GM_info.script.author),this.votSettingsDialog.bodyContainer.appendChild(this.votAuthorsInfo.container),this.votLoaderInfo=Ve.createInformation(`${N.get("VOTLoader")}:`,`${GM_info.scriptHandler} v${GM_info.version}`),this.votSettingsDialog.bodyContainer.appendChild(this.votLoaderInfo.container),this.votBrowserInfo=Ve.createInformation(`${N.get("VOTBrowser")}:`,`${We.browser.name} ${We.browser.version} (${We.os.name} ${We.os.version})`),this.votSettingsDialog.bodyContainer.appendChild(this.votBrowserInfo.container),this.votResetSettingsButton=Ve.createButton(N.get("resetSettings")),this.votSettingsDialog.bodyContainer.appendChild(this.votResetSettingsButton)}async handleTranslationBtnClick(){if(this.audio.src)return E.log("[click translationBtn] audio.src is not empty"),void this.stopTranslate();if(this.hls.url)return E.log("[click translationBtn] hls is not empty"),void this.stopTranslate();try{if(E.log("[click translationBtn] trying execute translation"),!this.videoData.videoId)throw new gt("VOTNoVideoIDFound");"vk"===this.site.host&&"clips"===this.site.additionalData&&(this.videoData=await this.getVideoData()),await this.translateExecutor(this.videoData.videoId)}catch(t){console.error("[VOT]",t),"VOTLocalizedError"===t?.name?this.transformBtn("error",t.localizedMessage):this.transformBtn("error",t)}}initUIEvents(){this.votButton.translateButton.addEventListener("click",(async()=>{await this.handleTranslationBtnClick()})),this.votButton.pipButton.addEventListener("click",(()=>{(async()=>{this.video!==document.pictureInPictureElement?await this.video.requestPictureInPicture():await document.exitPictureInPicture()})()})),this.votButton.menuButton.addEventListener("click",(()=>{this.votMenu.container.hidden=!this.votMenu.container.hidden})),this.votButton.container.addEventListener("mousedown",(()=>{this.dragging=!0})),this.container.addEventListener("mouseup",(()=>{this.dragging=!1})),this.container.addEventListener("mousemove",(async t=>{if(this.dragging){t.preventDefault();const e=t.clientX/this.container.clientWidth*100,o=this.container.clientWidth>550,n=e<=44?"left":e>=66?"right":"default";this.data.buttonPos=o?n:"default",this.votButton.container.dataset.direction="default"===this.data.buttonPos?"row":"column",this.votButton.container.dataset.position=this.data.buttonPos,this.votMenu.container.dataset.position=this.data.buttonPos,o&&await _.set("buttonPos",this.data.buttonPos)}})),this.votDownloadButton.addEventListener("click",(()=>{this.downloadTranslationUrl&&window.open(this.downloadTranslationUrl,"_blank").focus()})),this.votDownloadSubtitlesButton.addEventListener("click",(async()=>{const t=this.data.subtitlesDownloadFormat,e=kt(this.yandexSubtitles,t),o=new Blob(["json"===t?JSON.stringify(e):e],{type:"text/plain"}),n=URL.createObjectURL(o),i=document.createElement("a");i.href=n,i.download=`subtitles_${this.videoData.videoId}.${t}`,i.click(),URL.revokeObjectURL(n)})),this.votSettingsButton.addEventListener("click",(()=>{this.votSettingsDialog.container.hidden=!this.votSettingsDialog.container.hidden,(document.fullscreenElement||document.webkitFullscreenElement)&&(document.webkitExitFullscreen&&document.webkitExitFullscreen(),document.exitFullscreen&&document.exitFullscreen())})),this.votVideoVolumeSlider.input.addEventListener("input",(t=>{const e=Number(t.target.value);this.votVideoVolumeSlider.label.querySelector("strong").textContent=`${e}%`,this.setVideoVolume(e/100),this.data.syncVolume&&this.syncVolumeWrapper("video",e)})),this.votVideoTranslationVolumeSlider.input.addEventListener("input",(t=>{(async()=>{this.data.defaultVolume=Number(t.target.value),await _.set("defaultVolume",this.data.defaultVolume),this.votVideoTranslationVolumeSlider.label.querySelector("strong").textContent=`${this.data.defaultVolume}%`,this.setAudioVolume(this.data.defaultVolume/100),this.data.syncVolume&&(this.syncVolumeWrapper("translation",this.data.defaultVolume),["youtube","googledrive"].includes(this.site.host)&&"mobile"!==this.site.additionalData&&this.setVideoVolume(this.tempOriginalVolume/100))})()}));{this.votAutoTranslateCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.autoTranslate=Number(t.target.checked),await Promise.all([_.set("autoTranslate",this.data.autoTranslate),this.autoTranslate()]),E.log("autoTranslate value changed. New value: ",this.data.autoTranslate)})()})),this.votDontTranslateYourLangSelect.labelElement.addEventListener("change",(t=>{(async()=>{this.data.dontTranslateYourLang=Number(t.target.checked),await _.set("dontTranslateYourLang",this.data.dontTranslateYourLang),E.log("dontTranslateYourLang value changed. New value: ",this.data.dontTranslateYourLang)})()}));const t=async t=>{await _.set("hotkeyButton",t),this.data.hotkeyButton=t,this.changehotkeyButton.textContent=Ke(t)},e=o=>{const n="Escape"===o.code?null:o.code;t(n),document.removeEventListener("keydown",e)};this.changehotkeyButton.addEventListener("click",(()=>{this.changehotkeyButton.textContent=N.get("VOTPressNewHotkey"),document.addEventListener("keydown",e)})),this.votAutoSetVolumeCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.autoSetVolumeYandexStyle=Number(t.target.checked),await _.set("autoSetVolumeYandexStyle",this.data.autoSetVolumeYandexStyle),E.log("autoSetVolumeYandexStyle value changed. New value: ",this.data.autoSetVolumeYandexStyle)})()})),this.votAutoSetVolumeSlider.input.addEventListener("input",(t=>{(async()=>{const e=Number(t.target.value);this.data.autoVolume=(e/100).toFixed(2),await _.set("autoVolume",this.data.autoVolume),this.votAutoSetVolumeSlider.label.querySelector("strong").textContent=`${e}%`})()})),this.votShowVideoSliderCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.showVideoSlider=Number(t.target.checked),await _.set("showVideoSlider",this.data.showVideoSlider),E.log("showVideoSlider value changed. New value: ",this.data.showVideoSlider),this.votVideoVolumeSlider.container.hidden=1!==this.data.showVideoSlider||"success"!==this.votButton.container.dataset.status})()})),this.votAudioBoosterCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.audioBooster=Number(t.target.checked),await _.set("audioBooster",this.data.audioBooster),E.log("audioBooster value changed. New value: ",this.data.audioBooster);const e=this.votVideoTranslationVolumeSlider.input.value;this.votVideoTranslationVolumeSlider.input.max=this.data.audioBooster?900:100,this.data.audioBooster||(this.votVideoTranslationVolumeSlider.input.value=e>100?100:e,this.votVideoTranslationVolumeSlider.input.dispatchEvent(new Event("input")))})()})),this.votSyncVolumeCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.syncVolume=Number(t.target.checked),await _.set("syncVolume",this.data.syncVolume),E.log("syncVolume value changed. New value: ",this.data.syncVolume)})()})),this.votTranslationServiceSelect.labelElement.addEventListener("change",(t=>{(async()=>{this.data.translateAPIErrors=Number(t.target.checked),await _.set("translateAPIErrors",this.data.translateAPIErrors),E.log("translateAPIErrors value changed. New value: ",this.data.translateAPIErrors)})()})),this.votSubtitlesDetails.container.addEventListener("click",(()=>{this.votSubtitlesDialog=Ve.createDialog(N.get("VOTSubtitlesDesign")),this.votSubtitlesDialog.container.classList.add("vot-dialog-temp"),this.votSubtitlesDialog.container.hidden=!1,this.votSubtitlesDialog.backdrop.onclick=this.votSubtitlesDialog.closeButton.onclick=()=>{this.votSubtitlesDialog.container.remove()},this.votSubtitlesHighlightWordsCheckbox=Ve.createCheckbox(N.get("VOTHighlightWords"),this.data?.highlightWords??!1),this.votSubtitlesDialog.bodyContainer.appendChild(this.votSubtitlesHighlightWordsCheckbox.container),this.votSubtitlesDownloadFormatSelect=Ve.createVOTSelect(this.data.subtitlesDownloadFormat.toUpperCase(),N.get("VOTSubtitlesDownloadFormat"),Je(st,this.data.subtitlesDownloadFormat),{onSelectCb:async t=>{this.data.subtitlesDownloadFormat=t.target.dataset.votValue,await _.set("subtitlesDownloadFormat",this.data.subtitlesDownloadFormat)},labelElement:Ve.createVOTSelectLabel(N.get("VOTSubtitlesDownloadFormat"))}),this.votSubtitlesDialog.bodyContainer.appendChild(this.votSubtitlesDownloadFormatSelect.container),this.votSubtitlesMaxLengthSlider=Ve.createSlider(Gt`${N.get("VOTSubtitlesMaxLength")}: ${this.data?.subtitlesMaxLength??300}`,this.data?.subtitlesMaxLength??300,50,300),this.votSubtitlesDialog.bodyContainer.appendChild(this.votSubtitlesMaxLengthSlider.container),this.votSubtitlesFontSizeSlider=Ve.createSlider(Gt`${N.get("VOTSubtitlesFontSize")}: ${this.data?.subtitlesFontSize??20}`,this.data?.subtitlesFontSize??20,8,50),this.votSubtitlesDialog.bodyContainer.appendChild(this.votSubtitlesFontSizeSlider.container),this.votSubtitlesOpacitySlider=Ve.createSlider(Gt`${N.get("VOTSubtitlesOpacity")}: - ${this.data?.subtitlesOpacity??20}`,this.data?.subtitlesOpacity??20,0,100),this.votSubtitlesDialog.bodyContainer.appendChild(this.votSubtitlesOpacitySlider.container),this.votSubtitlesHighlightWordsCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.highlightWords=Number(t.target.checked),await _.set("highlightWords",this.data.highlightWords),E.log("highlightWords value changed. New value: ",this.data.highlightWords),this.subtitlesWidget.setHighlightWords(this.data.highlightWords)})()})),this.votSubtitlesMaxLengthSlider.input.addEventListener("input",(t=>{(async()=>{this.data.subtitlesMaxLength=Number(t.target.value),await _.set("subtitlesMaxLength",this.data.subtitlesMaxLength),this.votSubtitlesMaxLengthSlider.label.querySelector("strong").textContent=`${this.data.subtitlesMaxLength}`,this.subtitlesWidget.setMaxLength(this.data.subtitlesMaxLength)})()})),this.votSubtitlesFontSizeSlider.input.addEventListener("input",(t=>{(async()=>{this.data.subtitlesFontSize=Number(t.target.value),await _.set("subtitlesFontSize",this.data.subtitlesFontSize),this.votSubtitlesFontSizeSlider.label.querySelector("strong").textContent=`${this.data.subtitlesFontSize}`,this.subtitlesWidget.setFontSize(this.data.subtitlesFontSize)})()})),this.votSubtitlesOpacitySlider.input.addEventListener("input",(t=>{(async()=>{this.data.subtitlesOpacity=Number(t.target.value),await _.set("subtitlesOpacity",this.data.subtitlesOpacity),this.votSubtitlesOpacitySlider.label.querySelector("strong").textContent=`${this.data.subtitlesOpacity}`,this.subtitlesWidget.setOpacity(this.data.subtitlesOpacity)})()})),document.documentElement.appendChild(this.votSubtitlesDialog.container)})),this.votShowPiPButtonCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.showPiPButton=Number(t.target.checked),await _.set("showPiPButton",this.data.showPiPButton),E.log("showPiPButton value changed. New value: ",this.data.showPiPButton),this.votButton.pipButton.hidden=!F()||!this.data.showPiPButton,this.votButton.separator2.hidden=!F()||!this.data.showPiPButton})()})),this.votM3u8ProxyHostTextfield.input.addEventListener("change",(t=>{(async()=>{this.data.m3u8ProxyHost=t.target.value||ue,await _.set("m3u8ProxyHost",this.data.m3u8ProxyHost),E.log("m3u8ProxyHost value changed. New value: ",this.data.m3u8ProxyHost)})()})),this.votProxyWorkerHostTextfield.input.addEventListener("change",(t=>{(async()=>{this.data.proxyWorkerHost=t.target.value||ce,await _.set("proxyWorkerHost",this.data.proxyWorkerHost),E.log("proxyWorkerHost value changed. New value: ",this.data.proxyWorkerHost),this.data.translateProxyEnabled&&(this.votClient.host=this.data.proxyWorkerHost)})()})),this.votAudioProxyCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.audioProxy=Number(t.target.checked),await _.set("audioProxy",this.data.audioProxy),E.log("audioProxy value changed. New value: ",this.data.audioProxy)})()})),this.votResetSettingsButton.addEventListener("click",(()=>{(async()=>{N.reset();const t=await _.list();for(let e=0;e{this.extraEvents.push({element:t,event:e,handler:o}),t.addEventListener(e,o)},e=(e,o,n)=>{for(const i of o)t(e,i,n)};if(this.resizeObserver=new ResizeObserver((t=>{for(let e=0;e550;this.votButton.container.dataset.position=this.votMenu.container.dataset.position=e?this.data?.buttonPos:"default",this.votButton.container.dataset.direction=this.data?.buttonPos&&"default"!==this.data?.buttonPos&&e?"column":"row"})),this.resizeObserver.observe(this.video),this.votMenu.container.setAttribute("style",`--vot-container-height: ${this.video.getBoundingClientRect().height}px`),["youtube","googledrive"].includes(this.site.host)&&"mobile"!==this.site.additionalData){this.syncVolumeObserver=new MutationObserver((t=>{if(this.audio.src&&this.data.syncVolume)for(let e=0;e{const e=t.target,o=this.votButton.container,n=this.votMenu.container,i=this.container,a=this.votSettingsDialog.container,r=document.querySelector(".vot-dialog-temp"),s=o.contains(e),l=n.contains(e),d=i.contains(e),u=a.contains(e),c=r?.contains(e)??!1;E.log(`[document click] ${s} ${l} ${d} ${u} ${c}`),s||l||u||c||(d||this.logout(0),this.votMenu.container.hidden=!0)})),document.addEventListener("keydown",(async t=>{const e=t.code,o=document.activeElement;["input","textarea"].includes(o.tagName.toLowerCase())||o.isContentEditable||e!==this.data.hotkeyButton||await this.handleTranslationBtnClick()})),o="pornhub"===this.site.host?"embed"===this.site.additionalData?document.querySelector("#player"):this.container.querySelector(".mgp_eventCatcher"):"twitter"===this.site.host?document.querySelector('div[data-testid="videoPlayer"]'):"yandexdisk"===this.site.host?document.querySelector(".video-player__player"):this.container,o&&e(o,["mousemove","mouseout"],this.resetTimer),t(this.votButton.container,"mousemove",this.changeOpacityOnEvent),t(this.votMenu.container,"mousemove",this.changeOpacityOnEvent),e(document,["touchstart","touchmove","touchend"],this.changeOpacityOnEvent),t(this.votButton.container,"mousedown",(t=>{t.stopImmediatePropagation()})),t(this.votMenu.container,"mousedown",(t=>{t.stopImmediatePropagation()})),"youtube"===this.site.host&&(this.container.draggable=!1),"googledrive"===this.site.host&&(this.container.style.height="100%"),t(this.video,"canplay",(async()=>{"rutube"===this.site.host&&this.video.src||await ht(this.site,this.video)!==this.videoData.videoId&&(await this.handleSrcChanged(),await this.autoTranslate(),E.log("lipsync mode is canplay"))})),t(this.video,"emptied",(async()=>{this.video.src&&await ht(this.site,this.video)===this.videoData.videoId||(E.log("lipsync mode is emptied"),this.videoData="",this.stopTranslation())})),["rutube","ok"].includes(this.site.host)||t(this.video,"volumechange",(()=>{this.syncVideoVolumeSlider()}))}logout(t){this.votMenu.container.hidden&&(this.votButton.container.style.opacity=t)}resetTimer=()=>{clearTimeout(this.timer),this.logout(1),this.timer=setTimeout((()=>{this.logout(0)}),1e3)};changeOpacityOnEvent=t=>{clearTimeout(this.timer),this.logout(1),t.stopPropagation()};async changeSubtitlesLang(t){if(E.log("[onchange] subtitles",t),this.votSubtitlesSelect.setSelected(t),"disabled"===t)this.votSubtitlesSelect.setTitle(N.get("VOTSubtitlesDisabled")),this.subtitlesWidget.setContent(null),this.votDownloadSubtitlesButton.hidden=!0,this.yandexSubtitles=null;else{const e=this.subtitlesList.at(parseInt(t));if(1===this.data.audioProxy&&e.url.startsWith("https://brosubs.s3-private.mds.yandex.net/vtrans/")){const t=e.url.replace("https://brosubs.s3-private.mds.yandex.net/vtrans/","");e.url=`https://${this.data.proxyWorkerHost}/video-subtitles/subtitles-proxy/${t}`,console.log(`[VOT] Subs proxied via ${e.url}`)}this.yandexSubtitles=await De(e),this.subtitlesWidget.setContent(this.yandexSubtitles),this.votDownloadSubtitlesButton.hidden=!1}}async updateSubtitlesLangSelect(){const t=[{label:N.get("VOTSubtitlesDisabled"),value:"disabled",selected:!0,disabled:!1},...this.subtitlesList.map(((t,e)=>({label:(N.get("langs")[t.language]??t.language.toUpperCase())+(t.translatedFromLanguage?` ${N.get("VOTTranslatedFrom")} ${N.get("langs")[t.translatedFromLanguage]??t.translatedFromLanguage.toUpperCase()}`:"")+("yandex"!==t.source?`, ${window.location.hostname}`:"")+(t.isAutoGenerated?` (${N.get("VOTAutogenerated")})`:""),value:e,selected:!1,disabled:!1})))];this.votSubtitlesSelect.updateItems(t),await this.changeSubtitlesLang(t[0].value)}async updateSubtitles(){if(await this.changeSubtitlesLang("disabled"),!this.videoData.videoId)return console.error(`[VOT] ${N.getDefault("VOTNoVideoIDFound")}`),this.subtitlesList=[],this.subtitlesListVideoId=null,this.votButton.container.hidden=!0,void await this.updateSubtitlesLangSelect();if(this.votButton.container.hidden=!1,this.subtitlesListVideoId!==this.videoData.videoId){try{this.subtitlesList=await Fe(this.votClient,this.videoData)}catch(t){E.log("Error with yandex server, try auto-fix...",t),this.votOpts={fetchFn:z,hostVOT:he,host:this.data.proxyWorkerHost},this.votClient=new ft(this.votOpts),this.subtitlesList=await Fe(this.votClient,this.videoData),await _.set("translateProxyEnabled",1)}this.subtitlesList?this.subtitlesListVideoId=this.videoData.videoId:await this.changeSubtitlesLang("disabled"),await this.updateSubtitlesLangSelect()}}getVideoVolume(){let t=this.video?.volume;return["youtube","googledrive"].includes(this.site.host)&&(t=Ne.getVideoVolume()??t),t}setVideoVolume(t){if(["youtube","googledrive"].includes(this.site.host)){if(Ne.setVideoVolume(t))return}this.video.volume=t}getAudioVolume(){return this.gainNode?this.gainNode.gain.value:this.audio.volume}setAudioVolume(t){return this.gainNode?this.gainNode.gain.value=t:this.audio.volume=t}isMuted(){return["youtube","googledrive"].includes(this.site.host)?Ne.isMuted():this.video?.muted}syncVideoVolumeSlider(){const t=this.isMuted()?0:100*this.getVideoVolume(),e=Math.round(t);this.votVideoVolumeSlider.input.value=e,this.votVideoVolumeSlider.label.querySelector("strong").textContent=`${e}%`,Ve.updateSlider(this.votVideoVolumeSlider.input),1===this.data.syncVolume&&(this.tempOriginalVolume=Number(e))}setSelectMenuValues(t,e){this.votTranslationLanguageSelect.fromSelect.setTitle(N.get("langs")[t]),this.votTranslationLanguageSelect.toSelect.setTitle(N.get("langs")[e]),this.votTranslationLanguageSelect.fromSelect.setSelected(t),this.votTranslationLanguageSelect.toSelect.setSelected(e),console.log(`[VOT] Set translation from ${t} to ${e}`),this.videoData.detectedLanguage=t,this.videoData.responseLanguage=e}syncVolumeWrapper(t,e){const o="translation"===t?this.votVideoVolumeSlider:this.votVideoTranslationVolumeSlider,n=Number(o.input.value),i=function(t,e,o,n){let i=e;return e>n?(i=o+(e-n),i=i>100?100:Math.max(i,0),t.volume=i/100):e100?100:Math.max(i,0),t.volume=i/100),i}("translation"===t?this.video:this.audio,e,n,"translation"===t?this.tempVolume:this.tempOriginalVolume);o.input.value=i,o.label.querySelector("strong").textContent=`${i}%`,Ve.updateSlider(o.input),this.tempOriginalVolume="translation"===t?i:e,this.tempVolume="translation"===t?e:i}async getVideoData(){const{duration:t,url:e,videoId:o,host:n,translationHelp:i,detectedLanguage:a,subtitles:r}=await pt(this.site,this.video),s={translationHelp:i??null,isStream:!1,duration:this.video?.duration||t||y.defaultDuration,videoId:o,url:e,host:n,detectedLanguage:a??this.translateFromLang,responseLanguage:this.translateToLang,subtitles:r};if("youtube"===this.site.host){const t=await Ne.getVideoData();s.isStream=t.isLive,t.title&&(s.detectedLanguage=t.detectedLanguage)}else if(["rutube","ok.ru","mail_ru"].includes(this.site.host))s.detectedLanguage="ru";else if("youku"===this.site.host)s.detectedLanguage="zh";else if("vk"===this.site.host){const t=document.getElementsByTagName("track")?.[0]?.srclang;s.detectedLanguage=t||"auto"}else"weverse"===this.site.host?s.detectedLanguage="ko":["bilibili","piped","invidious","bitchute","rumble","peertube","dailymotion","trovo","yandexdisk","coursehunter","archive","nineanimetv","directlink"].includes(this.site.host)&&(s.detectedLanguage="auto");return s}videoValidator(){if(["youtube","ok.ru","vk"].includes(this.site.host)&&(E.log("VideoValidator videoData: ",this.videoData),1===this.data.dontTranslateYourLang&&this.videoData.detectedLanguage===this.data.dontTranslateLanguage))throw new gt("VOTDisableFromYourLang");if(!this.videoData.isStream&&this.videoData.duration>14400)throw new gt("VOTVideoIsTooLong");return!0}lipSync(t=!1){if(E.log("lipsync video",this.video),this.video)if(this.audio.currentTime=this.video.currentTime,this.audio.playbackRate=this.video.playbackRate,t)if("play"!=t)["pause","stop","waiting"].includes(t)&&(E.log(`lipsync mode is ${t}`),this.audio.pause()),"playing"==t&&(E.log("lipsync mode is playing"),this.audio.play());else{E.log("lipsync mode is play");const t=this.audio.play();void 0!==t&&t.catch((async t=>{if(console.error("[VOT]",t),"NotAllowedError"===t.name)throw this.transformBtn("error",N.get("grantPermissionToAutoPlay")),new gt("grantPermissionToAutoPlay")}))}else E.log("lipsync mode is not set")}handleVideoEvent=t=>{E.log(`video ${t.type}`),this.lipSync(t.type)};stopTranslate(){for(const t of Ye)this.video.removeEventListener(t,this.handleVideoEvent);this.audio.pause(),this.audio.src="",this.audio.removeAttribute("src"),this.votVideoVolumeSlider.container.hidden=!0,this.votVideoTranslationVolumeSlider.container.hidden=!0,this.votDownloadButton.hidden=!0,this.downloadTranslationUrl=null,this.transformBtn("none",N.get("translateVideo")),E.log(`Volume on start: ${this.volumeOnStart}`),this.volumeOnStart&&this.setVideoVolume(this.volumeOnStart),this.volumeOnStart="",clearInterval(this.streamPing),clearTimeout(this.autoRetry),this.hls?.destroy(),this.hls=q(),this.firstSyncVolume=!0}async translateExecutor(t){E.log("Run translateFunc",t),await this.translateFunc(t,this.videoData.isStream,this.videoData.detectedLanguage,this.videoData.responseLanguage,this.videoData.translationHelp)}async updateTranslationErrorMsg(t){const e=N.get("translationTake"),o=N.lang;if("VOTLocalizedError"===t?.name)this.transformBtn("error",t.localizedMessage);else if(t instanceof Error)this.transformBtn("error",t?.message);else if(1!==this.data.translateAPIErrors||t.includes(e)||"ru"===o)this.transformBtn("error",t);else{this.setLoadingBtn(!0);const e=await async function(t,e="",o="ru"){switch(await _.get("translationService",ge)){case"yandex":{const n=e&&o?`${e}-${o}`:o;return await Le.translate(t,n)}case"deepl":return await Ae.translate(t,e,o);default:return t}}(t,"ru",o);this.transformBtn("error",e)}["Подготавливаем перевод","Видео передано в обработку","Ожидаем перевод видео","Загружаем переведенное аудио"].includes(t)&&this.setLoadingBtn(!0)}afterUpdateTranslation(t){this.votVideoVolumeSlider.container.hidden=1!==this.data.showVideoSlider||"success"!==this.votButton.container.dataset.status,this.votVideoTranslationVolumeSlider.container.hidden="success"!==this.votButton.container.dataset.status,1===this.data.autoSetVolumeYandexStyle&&(this.votVideoVolumeSlider.input.value=100*this.data.autoVolume,this.votVideoVolumeSlider.label.querySelector("strong").textContent=100*this.data.autoVolume+"%",Ve.updateSlider(this.votVideoVolumeSlider.input)),this.votDownloadButton.hidden=!1,this.downloadTranslationUrl=t}async validateAudioUrl(t){try{const e=await z(t,{method:"HEAD",timeout:5e3});if(E.log("Test audio response",e),404===e.status){E.log("Yandex returned not valid audio, trying to fix...");let e=await this.translateVideoImpl(this.videoData,this.videoData.detectedLanguage="auto",this.videoData.responseLanguage,this.videoData.translationHelp);this.setSelectMenuValues(this.videoData.detectedLanguage,this.videoData.responseLanguage),t=e.url,E.log("Fixed audio audioUrl",t)}else E.log("Valid audioUrl",t)}catch(t){"Timeout"===t.message?(E.log("Request timed out. Handling timeout error..."),this.data.audioProxy=1,await _.set("audioProxy",1)):E.log("Test audio error:",t)}this.audio.src=t;try{await this.audio.play()}catch(t){if(console.error("[VOT]",t),"NotSupportedError"===t.name){if([...A,...O].includes(window.location.hostname))throw new gt("VOTMediaCSPError");this.data.audioProxy=1,await _.set("audioProxy",1)}}return t}async updateTranslation(t){if(this.cachedTranslation?.url===this.audio.currentSrc?(E.log("[translateFunc] Audio src is the same"),this.audio.src=t):t=await this.validateAudioUrl(t),1===this.data.audioProxy&&t.startsWith("https://vtrans.s3-private.mds.yandex.net/tts/prod/")){const e=t.replace("https://vtrans.s3-private.mds.yandex.net/tts/prod/","");t=`https://${this.data.proxyWorkerHost}/video-translation/audio-proxy/${e}`,console.log(`[VOT] Audio proxied via ${t}`)}if(this.audio.src=t,this.volumeOnStart||(this.volumeOnStart=this.getVideoVolume()),this.setupAudioSettings(),"twitter"===this.site.host)document.querySelector('button[data-testid="app-bar-back"][role="button"]').addEventListener("click",this.stopTranslation);this.video&&!this.video.paused&&this.lipSync("play");for(const t of Ye)this.video.addEventListener(t,this.handleVideoEvent);this.transformBtn("success",N.get("disableTranslate")),this.afterUpdateTranslation(t)}async translateFunc(t,e,o,n,i){if(console.log("[VOT] Video Data: ",this.videoData),E.log("Run videoValidator"),this.videoValidator(),this.setLoadingBtn(!0),e){let t=await this.translateStreamImpl(this.videoData,o,n);if(!t)return void E.log("Skip translation");this.transformBtn("success",N.get("disableTranslate"));const e=this.setHLSSource(t.result.url);if("youtube"===this.site.host&&Ne.videoSeek(this.video,10),this.setupAudioSettings(),!this.video.src&&!this.video.currentSrc&&!this.video.srcObject)return this.stopTranslation();this.video&&!this.video.paused&&this.lipSync("play");for(const t of Ye)this.video.addEventListener(t,this.handleVideoEvent);return this.afterUpdateTranslation(e)}if(this.cachedTranslation=this.videoTranslations.find((e=>e.videoId===t&&e.expires>Date.now()/1e3&&e.from===o&&e.to===n)),this.cachedTranslation)return await this.updateTranslation(this.cachedTranslation.url),void E.log("[translateFunc] Cached translation was received");let a=await this.translateVideoImpl(this.videoData,o,n,i);E.log("[translateRes]",a),a?(await this.updateTranslation(a.url),this.subtitlesList.some((t=>"yandex"===t.source&&t.translatedFromLanguage===this.videoData.detectedLanguage&&t.language===this.videoData.responseLanguage))||(this.subtitlesList=await Fe(this.votClient,this.videoData),await this.updateSubtitlesLangSelect()),this.videoTranslations.push({videoId:t,from:o,to:n,url:this.downloadTranslationUrl,expires:Date.now()/1e3+this.videoTranslationTTL})):E.log("Skip translation")}setupHLS(t){this.hls.on(Hls.Events.MEDIA_ATTACHED,(function(){E.log("audio and hls.js are now bound together !")})),this.hls.on(Hls.Events.MANIFEST_PARSED,(function(t){E.log("manifest loaded, found "+t?.levels?.length+" quality level")})),this.hls.loadSource(t),this.hls.attachMedia(this.audio),this.hls.on(Hls.Events.ERROR,(function(t){if(t.fatal)switch(t.type){case Hls.ErrorTypes.MEDIA_ERROR:console.log("fatal media error encountered, try to recover"),this.hls.recoverMediaError();break;case Hls.ErrorTypes.NETWORK_ERROR:console.error("fatal network error encountered",t);break;default:this.hls.destroy()}})),E.log(this.hls)}setHLSSource(t){const e=`https://${this.data.m3u8ProxyHost}/?all=yes&origin=${encodeURIComponent("https://strm.yandex.ru")}&referer=${encodeURIComponent("https://strm.yandex.ru")}&url=${encodeURIComponent(t)}`;if(this.hls)this.setupHLS(e);else{if(!this.audio.canPlayType("application/vnd.apple.mpegurl"))throw new gt("audioFormatNotSupported");this.audio.src=e}return e}setupAudioSettings(){"number"==typeof this.data.defaultVolume&&this.setAudioVolume(this.data.defaultVolume/100),"number"==typeof this.data.autoSetVolumeYandexStyle&&this.data.autoSetVolumeYandexStyle&&this.setVideoVolume(this.data.autoVolume)}stopTranslation=()=>{this.stopTranslate(),this.syncVideoVolumeSlider()};async handleSrcChanged(){E.log("[VideoHandler] src changed",this),this.firstPlay=!0;const t=!this.video.src&&!this.video.currentSrc&&!this.video.srcObject;this.votButton.container.hidden=t,t&&(this.votMenu.container.hidden=t),this.site.selector||(this.container=this.video.parentElement),this.container.contains(this.votButton.container)||this.container.append(this.votButton.container,this.votMenu.container),await Promise.all([this.videoData=await this.getVideoData(),this.updateSubtitles(),this.translateToLang=this.data.responseLanguage??"ru"]),this.setSelectMenuValues(this.videoData.detectedLanguage,this.videoData.responseLanguage)}async release(){E.log("[VideoHandler] release"),this.initialized=!1,this.releaseExtraEvents(),this.subtitlesWidget.release(),this.votButton.container.remove(),this.votMenu.container.remove()}}const Qe=new class{constructor(){this.videoCache=new Set,this.onVideoAdded=new He,this.onVideoRemoved=new He,this.observer=new MutationObserver(this.handleMutations),this.intersectionObserver=new IntersectionObserver(this.handleIntersections,{threshold:.1})}handleMutations=t=>{window.requestIdleCallback((()=>{for(let e=0;e{for(let e=0;e{if(!t)return;const n=t.querySelectorAll("video");for(let t=0;t{this.videoCache.has(t)||(this.videoCache.add(t),this.intersectionObserver.observe(t))};handleIntersectingVideo=t=>{this.intersectionObserver.unobserve(t),(t=>{if(Ue.test(t.className)||Ue.test(t.title))return!0;let e=t.parentElement;for(;e;){if(Ue.test(e.className)||Ue.test(e.id))return!0;e=e.parentElement}return!1})(t)||(t=>t.hasAttribute("muted")&&!t.classList.contains("vjs-tech"))(t)?E.log("The promotional/muted video was ignored",t):((t,e)=>{const o=()=>{(t=>t.readyState>=3)(t)?e(t):requestAnimationFrame(o)};o()})(t,this.handleVideoAdded)};handleVideoAdded=t=>{this.onVideoAdded.dispatch(t)};handleVideoRemoved=t=>{document.contains(t)||(this.videoCache.delete(t),this.onVideoRemoved.dispatch(t))}},Xe=new WeakMap;function to(t,e){if(t.shadowRoot){let o=t.selector?Array.from(document.querySelectorAll(t.selector)).find((t=>t.shadowRoot.contains(e))):e.parentElement;return o&&o.shadowRoot?o.parentElement:o}const o=We.browser.version.split(".")[0];if(t.selector?.includes(":not")&&t.selector?.includes("*")&&o&&("Chrome"===We.browser.name&&Number(o)<88||"Firefox"===We.browser.name&&Number(o)<84)){const o=t.selector.split(" *")[0];return o?Array.from(document.querySelectorAll(o)).find((t=>t.contains(e))):e.parentElement}return t.selector?Array.from(document.querySelectorAll(t.selector)).find((t=>t.contains(e))):e.parentElement}(async function(){E.log("Loading extension..."),await N.update(),E.log(`Selected menu language: ${N.lang}`),"https://9animetv.to"===window.location.origin&&window.addEventListener("message",(t=>{if("https://rapid-cloud.co"===t.origin&&"getVideoId"===t.data){const t=/[^/]+$/.exec(window.location.href)?.[0],e=document.querySelector("#iframe-embed")?.contentWindow;e.postMessage(`getVideoId:${t}`,"https://rapid-cloud.co/")}})),Qe.onVideoAdded.addListener((t=>{for(const e of function(){if(/(http(s)?:\/\/)(127\.0\.0\.1|localhost)/.exec(window.location.href))return[];const t=window.location.hostname,e=new URL(window.location),o=o=>o instanceof RegExp?o.test(t):"string"==typeof o?t.includes(o):"function"==typeof o&&o(e);return I.filter((t=>(Array.isArray(t.match)?t.match.some(o):o(t.match))&&t.host&&t.url))}()){if(!e)continue;let o=to(e,t);if(o&&(("rumble"!==e.host||t.style.display)&&(["peertube","directlink"].includes(e.host)&&(e.url=window.location.origin),!Xe.has(t)))){Xe.set(t,new Ze(t,o,e));break}}})),Qe.onVideoRemoved.addListener((async t=>{Xe.has(t)&&(await Xe.get(t).release(),Xe.delete(t))})),Qe.enable()})().catch((t=>{console.error("[VOT]",t)}))})()})(); \ No newline at end of file + ${this.data?.subtitlesOpacity??20}`,this.data?.subtitlesOpacity??20,0,100),this.votSubtitlesDialog.bodyContainer.appendChild(this.votSubtitlesOpacitySlider.container),this.votSubtitlesHighlightWordsCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.highlightWords=Number(t.target.checked),await _.set("highlightWords",this.data.highlightWords),E.log("highlightWords value changed. New value: ",this.data.highlightWords),this.subtitlesWidget.setHighlightWords(this.data.highlightWords)})()})),this.votSubtitlesMaxLengthSlider.input.addEventListener("input",(t=>{(async()=>{this.data.subtitlesMaxLength=Number(t.target.value),await _.set("subtitlesMaxLength",this.data.subtitlesMaxLength),this.votSubtitlesMaxLengthSlider.label.querySelector("strong").textContent=`${this.data.subtitlesMaxLength}`,this.subtitlesWidget.setMaxLength(this.data.subtitlesMaxLength)})()})),this.votSubtitlesFontSizeSlider.input.addEventListener("input",(t=>{(async()=>{this.data.subtitlesFontSize=Number(t.target.value),await _.set("subtitlesFontSize",this.data.subtitlesFontSize),this.votSubtitlesFontSizeSlider.label.querySelector("strong").textContent=`${this.data.subtitlesFontSize}`,this.subtitlesWidget.setFontSize(this.data.subtitlesFontSize)})()})),this.votSubtitlesOpacitySlider.input.addEventListener("input",(t=>{(async()=>{this.data.subtitlesOpacity=Number(t.target.value),await _.set("subtitlesOpacity",this.data.subtitlesOpacity),this.votSubtitlesOpacitySlider.label.querySelector("strong").textContent=`${this.data.subtitlesOpacity}`,this.subtitlesWidget.setOpacity(this.data.subtitlesOpacity)})()})),document.documentElement.appendChild(this.votSubtitlesDialog.container)})),this.votShowPiPButtonCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.showPiPButton=Number(t.target.checked),await _.set("showPiPButton",this.data.showPiPButton),E.log("showPiPButton value changed. New value: ",this.data.showPiPButton),this.votButton.pipButton.hidden=!F()||!this.data.showPiPButton,this.votButton.separator2.hidden=!F()||!this.data.showPiPButton})()})),this.votM3u8ProxyHostTextfield.input.addEventListener("change",(t=>{(async()=>{this.data.m3u8ProxyHost=t.target.value||ue,await _.set("m3u8ProxyHost",this.data.m3u8ProxyHost),E.log("m3u8ProxyHost value changed. New value: ",this.data.m3u8ProxyHost)})()})),this.votProxyWorkerHostTextfield.input.addEventListener("change",(t=>{(async()=>{this.data.proxyWorkerHost=t.target.value||ce,await _.set("proxyWorkerHost",this.data.proxyWorkerHost),E.log("proxyWorkerHost value changed. New value: ",this.data.proxyWorkerHost),this.data.translateProxyEnabled&&(this.votClient.host=this.data.proxyWorkerHost)})()})),this.votAudioProxyCheckbox.input.addEventListener("change",(t=>{(async()=>{this.data.audioProxy=Number(t.target.checked),await _.set("audioProxy",this.data.audioProxy),E.log("audioProxy value changed. New value: ",this.data.audioProxy)})()})),this.votResetSettingsButton.addEventListener("click",(()=>{(async()=>{N.reset();const t=await _.list();for(let e=0;e{this.extraEvents.push({element:t,event:e,handler:o}),t.addEventListener(e,o)},e=(e,o,n)=>{for(const i of o)t(e,i,n)};if(this.resizeObserver=new ResizeObserver((t=>{for(let e=0;e550;this.votButton.container.dataset.position=this.votMenu.container.dataset.position=e?this.data?.buttonPos:"default",this.votButton.container.dataset.direction=this.data?.buttonPos&&"default"!==this.data?.buttonPos&&e?"column":"row"})),this.resizeObserver.observe(this.video),this.votMenu.container.setAttribute("style",`--vot-container-height: ${this.video.getBoundingClientRect().height}px`),["youtube","googledrive"].includes(this.site.host)&&"mobile"!==this.site.additionalData){this.syncVolumeObserver=new MutationObserver((t=>{if(this.audio.src&&this.data.syncVolume)for(let e=0;e{const e=t.target,o=this.votButton.container,n=this.votMenu.container,i=this.container,a=this.votSettingsDialog.container,r=document.querySelector(".vot-dialog-temp"),s=o.contains(e),l=n.contains(e),d=i.contains(e),u=a.contains(e),c=r?.contains(e)??!1;E.log(`[document click] ${s} ${l} ${d} ${u} ${c}`),s||l||u||c||(d||this.logout(0),this.votMenu.container.hidden=!0)})),document.addEventListener("keydown",(async t=>{const e=t.code,o=document.activeElement;["input","textarea"].includes(o.tagName.toLowerCase())||o.isContentEditable||e!==this.data.hotkeyButton||await this.handleTranslationBtnClick()})),o="pornhub"===this.site.host?"embed"===this.site.additionalData?document.querySelector("#player"):this.container.querySelector(".mgp_eventCatcher"):"twitter"===this.site.host?document.querySelector('div[data-testid="videoPlayer"]'):"yandexdisk"===this.site.host?document.querySelector(".video-player__player"):this.container,o&&e(o,["mousemove","mouseout"],this.resetTimer),t(this.votButton.container,"mousemove",this.changeOpacityOnEvent),t(this.votMenu.container,"mousemove",this.changeOpacityOnEvent),e(document,["touchstart","touchmove","touchend"],this.changeOpacityOnEvent),t(this.votButton.container,"mousedown",(t=>{t.stopImmediatePropagation()})),t(this.votMenu.container,"mousedown",(t=>{t.stopImmediatePropagation()})),"youtube"===this.site.host&&(this.container.draggable=!1),"googledrive"===this.site.host&&(this.container.style.height="100%"),t(this.video,"canplay",(async()=>{"rutube"===this.site.host&&this.video.src||await ht(this.site,this.video)!==this.videoData.videoId&&(await this.handleSrcChanged(),await this.autoTranslate(),E.log("lipsync mode is canplay"))})),t(this.video,"emptied",(async()=>{this.video.src&&await ht(this.site,this.video)===this.videoData.videoId||(E.log("lipsync mode is emptied"),this.videoData="",this.stopTranslation())})),["rutube","ok"].includes(this.site.host)||t(this.video,"volumechange",(()=>{this.syncVideoVolumeSlider()}))}logout(t){this.votMenu.container.hidden&&(this.votButton.container.style.opacity=t)}resetTimer=()=>{clearTimeout(this.timer),this.logout(1),this.timer=setTimeout((()=>{this.logout(0)}),1e3)};changeOpacityOnEvent=t=>{clearTimeout(this.timer),this.logout(1),t.stopPropagation()};async changeSubtitlesLang(t){if(E.log("[onchange] subtitles",t),this.votSubtitlesSelect.setSelected(t),"disabled"===t)this.votSubtitlesSelect.setTitle(N.get("VOTSubtitlesDisabled")),this.subtitlesWidget.setContent(null),this.votDownloadSubtitlesButton.hidden=!0,this.yandexSubtitles=null;else{const e=this.subtitlesList.at(parseInt(t));if(1===this.data.audioProxy&&e.url.startsWith("https://brosubs.s3-private.mds.yandex.net/vtrans/")){const t=e.url.replace("https://brosubs.s3-private.mds.yandex.net/vtrans/","");e.url=`https://${this.data.proxyWorkerHost}/video-subtitles/subtitles-proxy/${t}`,console.log(`[VOT] Subs proxied via ${e.url}`)}this.yandexSubtitles=await De(e),this.subtitlesWidget.setContent(this.yandexSubtitles),this.votDownloadSubtitlesButton.hidden=!1}}async updateSubtitlesLangSelect(){const t=[{label:N.get("VOTSubtitlesDisabled"),value:"disabled",selected:!0,disabled:!1},...this.subtitlesList.map(((t,e)=>({label:(N.get("langs")[t.language]??t.language.toUpperCase())+(t.translatedFromLanguage?` ${N.get("VOTTranslatedFrom")} ${N.get("langs")[t.translatedFromLanguage]??t.translatedFromLanguage.toUpperCase()}`:"")+("yandex"!==t.source?`, ${window.location.hostname}`:"")+(t.isAutoGenerated?` (${N.get("VOTAutogenerated")})`:""),value:e,selected:!1,disabled:!1})))];this.votSubtitlesSelect.updateItems(t),await this.changeSubtitlesLang(t[0].value)}async updateSubtitles(){if(await this.changeSubtitlesLang("disabled"),!this.videoData.videoId)return console.error(`[VOT] ${N.getDefault("VOTNoVideoIDFound")}`),this.subtitlesList=[],this.subtitlesListVideoId=null,this.votButton.container.hidden=!0,void await this.updateSubtitlesLangSelect();if(this.votButton.container.hidden=!1,this.subtitlesListVideoId!==this.videoData.videoId){try{this.subtitlesList=await Fe(this.votClient,this.videoData)}catch(t){E.log("Error with yandex server, try auto-fix...",t),this.votOpts={fetchFn:z,hostVOT:he,host:this.data.proxyWorkerHost},this.votClient=new ft(this.votOpts),this.subtitlesList=await Fe(this.votClient,this.videoData),await _.set("translateProxyEnabled",1)}this.subtitlesList?this.subtitlesListVideoId=this.videoData.videoId:await this.changeSubtitlesLang("disabled"),await this.updateSubtitlesLangSelect()}}getVideoVolume(){let t=this.video?.volume;return["youtube","googledrive"].includes(this.site.host)&&(t=Ne.getVideoVolume()??t),t}setVideoVolume(t){if(["youtube","googledrive"].includes(this.site.host)){if(Ne.setVideoVolume(t))return}this.video.volume=t}getAudioVolume(){return this.gainNode?this.gainNode.gain.value:this.audio.volume}setAudioVolume(t){return this.gainNode?this.gainNode.gain.value=t:this.audio.volume=t}isMuted(){return["youtube","googledrive"].includes(this.site.host)?Ne.isMuted():this.video?.muted}syncVideoVolumeSlider(){const t=this.isMuted()?0:100*this.getVideoVolume(),e=Math.round(t);this.votVideoVolumeSlider.input.value=e,this.votVideoVolumeSlider.label.querySelector("strong").textContent=`${e}%`,Ve.updateSlider(this.votVideoVolumeSlider.input),1===this.data.syncVolume&&(this.tempOriginalVolume=Number(e))}setSelectMenuValues(t,e){this.votTranslationLanguageSelect.fromSelect.setTitle(N.get("langs")[t]),this.votTranslationLanguageSelect.toSelect.setTitle(N.get("langs")[e]),this.votTranslationLanguageSelect.fromSelect.setSelected(t),this.votTranslationLanguageSelect.toSelect.setSelected(e),console.log(`[VOT] Set translation from ${t} to ${e}`),this.videoData.detectedLanguage=t,this.videoData.responseLanguage=e}syncVolumeWrapper(t,e){const o="translation"===t?this.votVideoVolumeSlider:this.votVideoTranslationVolumeSlider,n=Number(o.input.value),i=function(t,e,o,n){let i=e;return e>n?(i=o+(e-n),i=i>100?100:Math.max(i,0),t.volume=i/100):e100?100:Math.max(i,0),t.volume=i/100),i}("translation"===t?this.video:this.audio,e,n,"translation"===t?this.tempVolume:this.tempOriginalVolume);o.input.value=i,o.label.querySelector("strong").textContent=`${i}%`,Ve.updateSlider(o.input),this.tempOriginalVolume="translation"===t?i:e,this.tempVolume="translation"===t?e:i}async getVideoData(){const{duration:t,url:e,videoId:o,host:n,translationHelp:i,detectedLanguage:a,subtitles:r}=await pt(this.site,this.video),s={translationHelp:i??null,isStream:!1,duration:this.video?.duration||t||y.defaultDuration,videoId:o,url:e,host:n,detectedLanguage:a??this.translateFromLang,responseLanguage:this.translateToLang,subtitles:r};if("youtube"===this.site.host){const t=await Ne.getVideoData();s.isStream=t.isLive,t.title&&(s.detectedLanguage=t.detectedLanguage)}else if(["rutube","ok.ru","mail_ru"].includes(this.site.host))s.detectedLanguage="ru";else if("youku"===this.site.host)s.detectedLanguage="zh";else if("vk"===this.site.host){const t=document.getElementsByTagName("track")?.[0]?.srclang;s.detectedLanguage=t||"auto"}else"weverse"===this.site.host?s.detectedLanguage="ko":["bilibili","piped","invidious","bitchute","rumble","peertube","dailymotion","trovo","yandexdisk","coursehunter","archive","nineanimetv","directlink"].includes(this.site.host)&&(s.detectedLanguage="auto");return s}videoValidator(){if(["youtube","ok.ru","vk"].includes(this.site.host)&&(E.log("VideoValidator videoData: ",this.videoData),1===this.data.dontTranslateYourLang&&this.videoData.detectedLanguage===this.data.dontTranslateLanguage))throw new gt("VOTDisableFromYourLang");if(!this.videoData.isStream&&this.videoData.duration>14400)throw new gt("VOTVideoIsTooLong");return!0}lipSync(t=!1){if(E.log("lipsync video",this.video),this.video)if(this.audio.currentTime=this.video.currentTime,this.audio.playbackRate=this.video.playbackRate,t)if("play"!=t)["pause","stop","waiting"].includes(t)&&(E.log(`lipsync mode is ${t}`),this.audio.pause()),"playing"==t&&(E.log("lipsync mode is playing"),this.audio.play());else{E.log("lipsync mode is play");const t=this.audio.play();void 0!==t&&t.catch((async t=>{if(console.error("[VOT]",t),"NotAllowedError"===t.name)throw this.transformBtn("error",N.get("grantPermissionToAutoPlay")),new gt("grantPermissionToAutoPlay")}))}else E.log("lipsync mode is not set")}handleVideoEvent=t=>{E.log(`video ${t.type}`),this.lipSync(t.type)};stopTranslate(){for(const t of Ye)this.video.removeEventListener(t,this.handleVideoEvent);this.audio.pause(),this.audio.src="",this.audio.removeAttribute("src"),this.votVideoVolumeSlider.container.hidden=!0,this.votVideoTranslationVolumeSlider.container.hidden=!0,this.votDownloadButton.hidden=!0,this.downloadTranslationUrl=null,this.transformBtn("none",N.get("translateVideo")),E.log(`Volume on start: ${this.volumeOnStart}`),this.volumeOnStart&&this.setVideoVolume(this.volumeOnStart),this.volumeOnStart="",clearInterval(this.streamPing),clearTimeout(this.autoRetry),this.hls?.destroy(),this.hls=q(),this.firstSyncVolume=!0}async translateExecutor(t){E.log("Run translateFunc",t),await this.translateFunc(t,this.videoData.isStream,this.videoData.detectedLanguage,this.videoData.responseLanguage,this.videoData.translationHelp)}async updateTranslationErrorMsg(t){const e=N.get("translationTake"),o=N.lang;if("VOTLocalizedError"===t?.name)this.transformBtn("error",t.localizedMessage);else if(t instanceof Error)this.transformBtn("error",t?.message);else if(1!==this.data.translateAPIErrors||t.includes(e)||"ru"===o)this.transformBtn("error",t);else{this.setLoadingBtn(!0);const e=await async function(t,e="",o="ru"){switch(await _.get("translationService",ge)){case"yandex":{const n=e&&o?`${e}-${o}`:o;return await Le.translate(t,n)}case"deepl":return await Ae.translate(t,e,o);default:return t}}(t,"ru",o);this.transformBtn("error",e)}["Подготавливаем перевод","Видео передано в обработку","Ожидаем перевод видео","Загружаем переведенное аудио"].includes(t)&&this.setLoadingBtn(!0)}afterUpdateTranslation(t){this.votVideoVolumeSlider.container.hidden=1!==this.data.showVideoSlider||"success"!==this.votButton.container.dataset.status,this.votVideoTranslationVolumeSlider.container.hidden="success"!==this.votButton.container.dataset.status,1===this.data.autoSetVolumeYandexStyle&&(this.votVideoVolumeSlider.input.value=100*this.data.autoVolume,this.votVideoVolumeSlider.label.querySelector("strong").textContent=100*this.data.autoVolume+"%",Ve.updateSlider(this.votVideoVolumeSlider.input)),this.votDownloadButton.hidden=!1,this.downloadTranslationUrl=t}async validateAudioUrl(t){try{const e=await z(t,{method:"HEAD",timeout:5e3});if(E.log("Test audio response",e),404===e.status){E.log("Yandex returned not valid audio, trying to fix...");let e=await this.translateVideoImpl(this.videoData,this.videoData.detectedLanguage="auto",this.videoData.responseLanguage,this.videoData.translationHelp);this.setSelectMenuValues(this.videoData.detectedLanguage,this.videoData.responseLanguage),t=e.url,E.log("Fixed audio audioUrl",t)}else E.log("Valid audioUrl",t)}catch(t){"Timeout"===t.message?(E.log("Request timed out. Handling timeout error..."),this.data.audioProxy=1,await _.set("audioProxy",1)):E.log("Test audio error:",t)}this.audio.src=t;try{await this.audio.play()}catch(t){if(console.error("[VOT]",t),"NotSupportedError"===t.name){if([...A,...O].includes(window.location.hostname))throw new gt("VOTMediaCSPError");this.data.audioProxy=1,await _.set("audioProxy",1)}}return t}async updateTranslation(t){if(this.cachedTranslation?.url===this.audio.currentSrc?(E.log("[translateFunc] Audio src is the same"),this.audio.src=t):t=await this.validateAudioUrl(t),1===this.data.audioProxy&&t.startsWith("https://vtrans.s3-private.mds.yandex.net/tts/prod/")){const e=t.replace("https://vtrans.s3-private.mds.yandex.net/tts/prod/","");t=`https://${this.data.proxyWorkerHost}/video-translation/audio-proxy/${e}`,console.log(`[VOT] Audio proxied via ${t}`)}if(this.audio.src=t,this.volumeOnStart||(this.volumeOnStart=this.getVideoVolume()),this.setupAudioSettings(),"twitter"===this.site.host)document.querySelector('button[data-testid="app-bar-back"][role="button"]').addEventListener("click",this.stopTranslation);this.video&&!this.video.paused&&this.lipSync("play");for(const t of Ye)this.video.addEventListener(t,this.handleVideoEvent);this.transformBtn("success",N.get("disableTranslate")),this.afterUpdateTranslation(t)}async translateFunc(t,e,o,n,i){if(console.log("[VOT] Video Data: ",this.videoData),E.log("Run videoValidator"),this.videoValidator(),this.setLoadingBtn(!0),e){let t=await this.translateStreamImpl(this.videoData,o,n);if(!t)return void E.log("Skip translation");this.transformBtn("success",N.get("disableTranslate"));const e=this.setHLSSource(t.result.url);if("youtube"===this.site.host&&Ne.videoSeek(this.video,10),this.setupAudioSettings(),!this.video.src&&!this.video.currentSrc&&!this.video.srcObject)return this.stopTranslation();this.video&&!this.video.paused&&this.lipSync("play");for(const t of Ye)this.video.addEventListener(t,this.handleVideoEvent);return this.afterUpdateTranslation(e)}if(this.cachedTranslation=this.videoTranslations.find((e=>e.videoId===t&&e.expires>Date.now()/1e3&&e.from===o&&e.to===n)),this.cachedTranslation)return await this.updateTranslation(this.cachedTranslation.url),void E.log("[translateFunc] Cached translation was received");let a=await this.translateVideoImpl(this.videoData,o,n,i);E.log("[translateRes]",a),a?(await this.updateTranslation(a.url),this.subtitlesList.some((t=>"yandex"===t.source&&t.translatedFromLanguage===this.videoData.detectedLanguage&&t.language===this.videoData.responseLanguage))||(this.subtitlesList=await Fe(this.votClient,this.videoData),await this.updateSubtitlesLangSelect()),this.videoTranslations.push({videoId:t,from:o,to:n,url:this.downloadTranslationUrl,expires:Date.now()/1e3+this.videoTranslationTTL})):E.log("Skip translation")}setupHLS(t){this.hls.on(Hls.Events.MEDIA_ATTACHED,(function(){E.log("audio and hls.js are now bound together !")})),this.hls.on(Hls.Events.MANIFEST_PARSED,(function(t){E.log("manifest loaded, found "+t?.levels?.length+" quality level")})),this.hls.loadSource(t),this.hls.attachMedia(this.audio),this.hls.on(Hls.Events.ERROR,(function(t){if(t.fatal)switch(t.type){case Hls.ErrorTypes.MEDIA_ERROR:console.log("fatal media error encountered, try to recover"),this.hls.recoverMediaError();break;case Hls.ErrorTypes.NETWORK_ERROR:console.error("fatal network error encountered",t);break;default:this.hls.destroy()}})),E.log(this.hls)}setHLSSource(t){const e=`https://${this.data.m3u8ProxyHost}/?all=yes&origin=${encodeURIComponent("https://strm.yandex.ru")}&referer=${encodeURIComponent("https://strm.yandex.ru")}&url=${encodeURIComponent(t)}`;if(this.hls)this.setupHLS(e);else{if(!this.audio.canPlayType("application/vnd.apple.mpegurl"))throw new gt("audioFormatNotSupported");this.audio.src=e}return e}setupAudioSettings(){"number"==typeof this.data.defaultVolume&&this.setAudioVolume(this.data.defaultVolume/100),"number"==typeof this.data.autoSetVolumeYandexStyle&&this.data.autoSetVolumeYandexStyle&&this.setVideoVolume(this.data.autoVolume)}stopTranslation=()=>{this.stopTranslate(),this.syncVideoVolumeSlider()};async handleSrcChanged(){E.log("[VideoHandler] src changed",this),this.firstPlay=!0;const t=!this.video.src&&!this.video.currentSrc&&!this.video.srcObject;this.votButton.container.hidden=t,t&&(this.votMenu.container.hidden=t),this.site.selector||(this.container=this.video.parentElement),this.container.contains(this.votButton.container)||this.container.append(this.votButton.container,this.votMenu.container),await Promise.all([this.videoData=await this.getVideoData(),this.updateSubtitles(),this.translateToLang=this.data.responseLanguage??"ru"]),this.setSelectMenuValues(this.videoData.detectedLanguage,this.videoData.responseLanguage)}async release(){E.log("[VideoHandler] release"),this.initialized=!1,this.releaseExtraEvents(),this.subtitlesWidget.release(),this.votButton.container.remove(),this.votMenu.container.remove()}}const Qe=new class{constructor(){this.videoCache=new Set,this.onVideoAdded=new He,this.onVideoRemoved=new He,this.observer=new MutationObserver(this.handleMutations),this.intersectionObserver=new IntersectionObserver(this.handleIntersections,{threshold:.1})}handleMutations=t=>{window.requestIdleCallback((()=>{for(let e=0;e{for(let e=0;e{if(!t)return;const n=t.querySelectorAll("video");for(let t=0;t{this.videoCache.has(t)||(this.videoCache.add(t),this.intersectionObserver.observe(t))};handleIntersectingVideo=t=>{this.intersectionObserver.unobserve(t),(t=>{if(Ue.test(t.className)||Ue.test(t.title))return!0;let e=t.parentElement;for(;e;){if(Ue.test(e.className)||Ue.test(e.id))return!0;e=e.parentElement}return!1})(t)||(t=>t.hasAttribute("muted")&&!t.classList.contains("vjs-tech"))(t)?E.log("The promotional/muted video was ignored",t):((t,e)=>{const o=()=>{(t=>t.readyState>=3)(t)?e(t):requestAnimationFrame(o)};o()})(t,this.handleVideoAdded)};handleVideoAdded=t=>{this.onVideoAdded.dispatch(t)};handleVideoRemoved=t=>{document.contains(t)||(this.videoCache.delete(t),this.onVideoRemoved.dispatch(t))}},Xe=new WeakMap;function to(t,e){if(t.shadowRoot){let o=t.selector?Array.from(document.querySelectorAll(t.selector)).find((t=>t.shadowRoot.contains(e))):e.parentElement;return o&&o.shadowRoot?o.parentElement:o}const o=We.browser.version.split(".")[0];if(t.selector?.includes(":not")&&t.selector?.includes("*")&&o&&("Chrome"===We.browser.name&&Number(o)<88||"Firefox"===We.browser.name&&Number(o)<84)){const o=t.selector.split(" *")[0];return o?Array.from(document.querySelectorAll(o)).find((t=>t.contains(e))):e.parentElement}return t.selector?Array.from(document.querySelectorAll(t.selector)).find((t=>t.contains(e))):e.parentElement}(async function(){E.log("Loading extension..."),await N.update(),E.log(`Selected menu language: ${N.lang}`),"https://9animetv.to"===window.location.origin&&window.addEventListener("message",(t=>{if("https://rapid-cloud.co"===t.origin&&"getVideoId"===t.data){const t=/[^/]+$/.exec(window.location.href)?.[0],e=document.querySelector("#iframe-embed")?.contentWindow;e.postMessage(`getVideoId:${t}`,"https://rapid-cloud.co/")}})),Qe.onVideoAdded.addListener((t=>{for(const e of function(){if(/(http(s)?:\/\/)(127\.0\.0\.1|localhost)/.exec(window.location.href))return[];const t=window.location.hostname,e=new URL(window.location),o=o=>o instanceof RegExp?o.test(t):"string"==typeof o?t.includes(o):"function"==typeof o&&o(e);return I.filter((t=>(Array.isArray(t.match)?t.match.some(o):o(t.match))&&t.host&&t.url))}()){if(!e)continue;let o=to(e,t);if(o&&(("rumble"!==e.host||t.style.display)&&(["peertube","directlink"].includes(e.host)&&(e.url=window.location.origin),!Xe.has(t)))){Xe.set(t,new Ze(t,o,e));break}}})),Qe.onVideoRemoved.addListener((async t=>{Xe.has(t)&&(await Xe.get(t).release(),Xe.delete(t))})),Qe.enable()})().catch((t=>{console.error("[VOT]",t)}))})()})(); \ No newline at end of file diff --git a/dist/vot.user.js b/dist/vot.user.js index bc3ddcf1..b6ca2c62 100644 --- a/dist/vot.user.js +++ b/dist/vot.user.js @@ -7344,8 +7344,7 @@ class VideoHandler { const percentX = (e.clientX / this.container.clientWidth) * 100; // const percentY = (e.clientY / this.video.clientHeight) * 100; - const isBigContainer = - this.container.clientWidth && this.container.clientWidth > 550; + const isBigContainer = this.container.clientWidth > 550; const isLeft = percentX <= 44; const isRightSide = percentX >= 66 ? "right" : "default"; const side = isLeft ? "left" : isRightSide; @@ -7834,9 +7833,7 @@ class VideoHandler { ); } - const isBigWidth = - this.container.clientWidth && this.container.clientWidth > 550; - + const isBigWidth = this.container.clientWidth > 550; this.votButton.container.dataset.position = this.votMenu.container.dataset.position = isBigWidth ? this.data?.buttonPos diff --git a/src/index.js b/src/index.js index 905a8d5f..e60faa26 100644 --- a/src/index.js +++ b/src/index.js @@ -968,8 +968,7 @@ class VideoHandler { const percentX = (e.clientX / this.container.clientWidth) * 100; // const percentY = (e.clientY / this.video.clientHeight) * 100; - const isBigContainer = - this.container.clientWidth && this.container.clientWidth > 550; + const isBigContainer = this.container.clientWidth > 550; const isLeft = percentX <= 44; const isRightSide = percentX >= 66 ? "right" : "default"; const side = isLeft ? "left" : isRightSide; @@ -1458,9 +1457,7 @@ class VideoHandler { ); } - const isBigWidth = - this.container.clientWidth && this.container.clientWidth > 550; - + const isBigWidth = this.container.clientWidth > 550; this.votButton.container.dataset.position = this.votMenu.container.dataset.position = isBigWidth ? this.data?.buttonPos