Skip to content

Commit

Permalink
Merge pull request #803 from ilyhalight/fix-yt-shorts
Browse files Browse the repository at this point in the history
Fix YT shorts
  • Loading branch information
ilyhalight authored Sep 9, 2024
2 parents 7e9b064 + 80c24cc commit 553209c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
1 change: 1 addition & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- Исправлена ошибка из-за которой при запросе субтитров не учитывался выбранный язык видео
- Исправлена ошибка из-за которой для определения языка видео на ютубе использовалось локализованное название видео
- Исправлена ошибка из-за которой субтитры на некоторых сайтах могли иметь неверный размер шрифта
- Исправлена ошибка из-за которой не отключалась озвучка после перелистывания видео в YT Shorts (#802)
- Исправлено появление значка загрузки при переводе на "кастомных" сайтах
- Исправлено появление кнопки в Rumble (#784)
- Исправлен жирный размер текста в меню и кнопке перевода на некоторых сайтах
Expand Down
2 changes: 1 addition & 1 deletion dist/vot-min.user.js

Large diffs are not rendered by default.

30 changes: 23 additions & 7 deletions dist/vot.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -6821,8 +6821,8 @@ class VideoHandler {
await this.updateTranslationErrorMsg(
res.remainingTime > 0
? secsToStrTime(res.remainingTime)
: res.message ??
localizationProvider.get("translationTakeFewMinutes"),
: (res.message ??
localizationProvider.get("translationTakeFewMinutes")),
);
} catch (err) {
console.error("[VOT] Failed to translate video", err);
Expand Down Expand Up @@ -8335,11 +8335,7 @@ class VideoHandler {
if (this.site.host === "rutube" && this.video.src) {
return;
}
if ((await getVideoID(this.site, this.video)) === this.videoData.videoId)
return;
await this.handleSrcChanged();
await this.autoTranslate();
utils_debug.log("lipsync mode is canplay");
await this.setCanPlay();
});

addExtraEventListener(this.video, "emptied", async () => {
Expand All @@ -8358,6 +8354,25 @@ class VideoHandler {
this.syncVideoVolumeSlider();
});
}

if (this.site.host === "youtube" && !this.site.additionalData) {
addExtraEventListener(document, "yt-page-data-updated", async () => {
utils_debug.log("yt-page-data-updated");
// fix #802
if (!window.location.pathname.includes("/shorts/")) {
return;
}
await this.setCanPlay();
});
}
}

async setCanPlay() {
if ((await getVideoID(this.site, this.video)) === this.videoData.videoId)
return;
await this.handleSrcChanged();
await this.autoTranslate();
utils_debug.log("lipsync mode is canplay");
}

logout(n) {
Expand Down Expand Up @@ -9096,6 +9111,7 @@ class VideoHandler {
async handleSrcChanged() {
utils_debug.log("[VideoHandler] src changed", this);
this.firstPlay = true;
this.stopTranslation();

const hide =
!this.video.src && !this.video.currentSrc && !this.video.srcObject;
Expand Down
26 changes: 21 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1691,11 +1691,7 @@ class VideoHandler {
if (this.site.host === "rutube" && this.video.src) {
return;
}
if ((await getVideoID(this.site, this.video)) === this.videoData.videoId)
return;
await this.handleSrcChanged();
await this.autoTranslate();
debug.log("lipsync mode is canplay");
await this.setCanPlay();
});

addExtraEventListener(this.video, "emptied", async () => {
Expand All @@ -1714,6 +1710,25 @@ class VideoHandler {
this.syncVideoVolumeSlider();
});
}

if (this.site.host === "youtube" && !this.site.additionalData) {
addExtraEventListener(document, "yt-page-data-updated", async () => {
debug.log("yt-page-data-updated");
// fix #802
if (!window.location.pathname.includes("/shorts/")) {
return;
}
await this.setCanPlay();
});
}
}

async setCanPlay() {
if ((await getVideoID(this.site, this.video)) === this.videoData.videoId)
return;
await this.handleSrcChanged();
await this.autoTranslate();
debug.log("lipsync mode is canplay");
}

logout(n) {
Expand Down Expand Up @@ -2452,6 +2467,7 @@ class VideoHandler {
async handleSrcChanged() {
debug.log("[VideoHandler] src changed", this);
this.firstPlay = true;
this.stopTranslation();

const hide =
!this.video.src && !this.video.currentSrc && !this.video.srcObject;
Expand Down

0 comments on commit 553209c

Please sign in to comment.