Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix YT shorts #803

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -450,7 +450,7 @@
}
}

initUI() {

Check warning on line 453 in src/index.js

View workflow job for this annotation

GitHub Actions / node (18.18.x)

Refactor this function to reduce its Cognitive Complexity from 23 to the 15 allowed

Check warning on line 453 in src/index.js

View workflow job for this annotation

GitHub Actions / node (22.x)

Refactor this function to reduce its Cognitive Complexity from 23 to the 15 allowed
// VOT Button
{
this.votButton = ui.createVOTButton(
Expand Down Expand Up @@ -1691,11 +1691,7 @@
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 @@
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 @@ -2276,7 +2291,7 @@
}

// Define a function to translate a video and handle the callback
async translateFunc(

Check warning on line 2294 in src/index.js

View workflow job for this annotation

GitHub Actions / node (18.18.x)

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed

Check warning on line 2294 in src/index.js

View workflow job for this annotation

GitHub Actions / node (22.x)

Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed
VIDEO_ID,
isStream,
requestLang,
Expand Down Expand Up @@ -2452,6 +2467,7 @@
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
Loading