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 multimedia keys if browser support audio context #844

Merged
merged 1 commit into from
Oct 4, 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
Binary file modified bun.lockb
Binary file not shown.
16 changes: 15 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,23 @@
# 1.7.1 [WIP]

- Включен обход Media CSP для player.vimeo.com
- Добавлена поддержка субтитров от сайта для Vimeo
<!-- - Добавлена поддержка просмотра видео в плеере без перехода по публичной ссылке для Яндекс Диска (Вы все еще должны открыть публичный доступ к файлу (Не к папке!!!)) (#837) -->
- Исправлено неверное название переменной при отключение чекбокса усилителя громкости аудио, что могло приводить к ошибке
- Исправлена работа встраиваемого плеера Vimeo (player.vimeo.com), если видео залито в приватный доступ и доступно только через встраивание (#543, #828)
- Исправлена работа медиаклавиш, если в браузере есть поддержка AudioContext (#192, #357, #841)

В меню расширения добавлен чекбокс "Restoring multimedia keys". По умолчанию чекбокс включен, если браузер поддерживает AudioContext. С включением чекбокса "Restoring multimedia keys", изменение значения чекбокса "Bypassing Media CSP" становится недоступным т.к. эти два чекбокса выполняют один и тот же функционал, но "Bypassing Media CSP" действует для ограниченного числа веб-сайтов, а "Restoring multimedia keys" для всех веб-сайтов с которыми работает расширение. Если после этого перехода не возникнет серьезных проблем, то чекбокс "Bypassing Media CSP" будет полностью удален.

# 1.7.1 Beta 1

- Включен обход Media CSP для player.vimeo.com
- Добавлена поддержка субтитров от сайта для Vimeo
- Исправлено неверное название при отключение чекбокса усилителя громкости аудио
- Исправлено неверное название переменной при отключение чекбокса усилителя громкости аудио, что могло приводить к ошибке
- Исправлена работа встраиваемого плеера Vimeo (player.vimeo.com), если видео залито в приватный доступ и доступно только через встраивание (#543, #828)
- Исправлена работа медиаклавиш, если в браузере есть поддержка AudioContext (#192, #357, #841)

В меню расширения добавлен чекбокс "Restoring multimedia keys". По умолчанию чекбокс включен, если браузер поддерживает AudioContext. С включением чекбокса "Restoring multimedia keys", изменение значения чекбокса "Bypassing Media CSP" становится недоступным т.к. эти два чекбокса выполняют один и тот же функционал, но "Bypassing Media CSP" действует для ограниченного числа веб-сайтов, а "Restoring multimedia keys" для всех веб-сайтов с которыми работает расширение. Если после этого перехода не возникнет серьезных проблем, то чекбокс "Bypassing Media CSP" будет полностью удален.

# 1.7.0

Expand Down
26 changes: 13 additions & 13 deletions dist/vot-min.user.js

Large diffs are not rendered by default.

55 changes: 48 additions & 7 deletions dist/vot.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,12 @@
// @connect onrender.com
// @connect workers.dev
// @namespace vot
// @version 1.7.0
// @version 1.7.1-beta1
// @icon https://translate.yandex.ru/icons/favicon.ico
// @author sodapng, mynovelhost, Toil, SashaXser, MrSoczekXD
// @homepageURL https://github.com/ilyhalight/voice-over-translation
// @updateURL https://raw.githubusercontent.com/ilyhalight/voice-over-translation/master/dist/vot.user.js
// @downloadURL https://raw.githubusercontent.com/ilyhalight/voice-over-translation/master/dist/vot.user.js
// @updateURL https://raw.githubusercontent.com/ilyhalight/voice-over-translation/dev/dist/vot.user.js
// @downloadURL https://raw.githubusercontent.com/ilyhalight/voice-over-translation/dev/dist/vot.user.js
// @supportURL https://github.com/ilyhalight/voice-over-translation/issues
// ==/UserScript==

Expand Down Expand Up @@ -2391,7 +2391,7 @@ const votStorage = new (class {

const localeCacheTTL = 7200;
const localizationUrl = `${contentUrl}/${
false ? 0 : "master"
true ? "dev" : 0
}/src/localization`;

// TODO: add get from hashes.json or use DEFAULT_LOCALES
Expand Down Expand Up @@ -7315,6 +7315,10 @@ class VideoHandler {
"bypassMediaCSP",
Number(!!this.audioContext),
),
restoreMultiMediaKeys: votStorage.get(
"restoreMultiMediaKeys",
Number(!!this.audioContext),
),
showPiPButton: votStorage.get("showPiPButton", 0),
translateAPIErrors: votStorage.get("translateAPIErrors", 1),
translationService: votStorage.get(
Expand Down Expand Up @@ -7864,6 +7868,19 @@ class VideoHandler {
this.votBypassMediaCSPCheckbox.container,
);

this.votRestoreMultiMediaKeysCheckbox = ui.createCheckbox(
localizationProvider.get("VOTRestoreMultiMediaKeys"),
this.data?.restoreMultiMediaKeys ?? false,
);
if (!this.audioContext) {
this.votRestoreMultiMediaKeysCheckbox.input.disabled = true;
this.votRestoreMultiMediaKeysCheckbox.container.title =
localizationProvider.get("VOTNeedWebAudioAPI");
}
this.votSettingsDialog.bodyContainer.appendChild(
this.votRestoreMultiMediaKeysCheckbox.container,
);

// ABOUT

this.votAboutHeader = ui.createHeader(localizationProvider.get("about"));
Expand Down Expand Up @@ -8525,6 +8542,28 @@ class VideoHandler {
})();
});

this.votRestoreMultiMediaKeysCheckbox.input.addEventListener(
"change",
(e) => {
(async () => {
this.data.restoreMultiMediaKeys = Number(e.target.checked);
await votStorage.set(
"restoreMultiMediaKeys",
this.data.restoreMultiMediaKeys,
);
utils_debug.log(
"restoreMultiMediaKeys value changed. New value: ",
this.data.restoreMultiMediaKeys,
);
this.stopTranslate();
// TODO: delete if everything goes well
this.votBypassMediaCSPCheckbox.input.disabled = e.target.checked;
this.votBypassMediaCSPCheckbox.input.value =
e.target.checked ?? this.data.bypassMediaCSP;
})();
},
);

this.votUpdateLocaleFilesButton.addEventListener("click", () => {
(async () => {
await votStorage.set("locale-hash", "");
Expand Down Expand Up @@ -9205,7 +9244,7 @@ class VideoHandler {
this.audio.currentTime = this.video.currentTime;
this.audio.playbackRate = this.video.playbackRate;

return this.needBypassCSP()
return this.needUseAudioContext()
? this.lipsyncAudioContext(mode)
: this.lipsyncAudio(mode);
}
Expand All @@ -9216,7 +9255,9 @@ class VideoHandler {
this.lipSync(event.type);
};

needBypassCSP = () => this.data.bypassMediaCSP && this.site.needBypassCSP;
needUseAudioContext = () =>
(this.data.bypassMediaCSP && this.site.needBypassCSP) ||
this.data.restoreMultiMediaKeys;

// Default actions on stop translate
stopTranslate() {
Expand Down Expand Up @@ -9405,7 +9446,7 @@ class VideoHandler {
}

// eslint-disable-next-line sonarjs/no-unused-expressions
this.needBypassCSP()
this.needUseAudioContext()
? await this.configurePlaySound(audioUrl)
: (this.audio.src = audioUrl);

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
"browserslist": "^4.24.0",
"bun-types": "^1.1.29",
"enquirer": "^2.4.1",
"eslint": "^9.11.1",
"eslint-plugin-oxlint": "^0.9.8",
"eslint-plugin-sonarjs": "^2.0.2",
"eslint": "^9.12.0",
"eslint-plugin-oxlint": "^0.9.9",
"eslint-plugin-sonarjs": "^2.0.3",
"eslint-webpack-plugin": "^4.2.0",
"globals": "^15.9.0",
"globals": "^15.10.0",
"husky": "^9.1.6",
"lightningcss": "^1.27.0",
"lint-staged": "^15.2.10",
"npm-run-all2": "^6.2.3",
"oxlint": "^0.9.8",
"oxlint": "^0.9.9",
"patch-package": "^8.0.0",
"postinstall-postinstall": "^2.1.0",
"sass": "^1.79.3",
"sass": "^1.79.4",
"typescript": "^5.6.2",
"webpack": "^5.95.0",
"webpack-cli": "^5.1.4",
Expand Down
2 changes: 1 addition & 1 deletion src/headers.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "[VOT] - Voice Over Translation",
"description": "A small extension that adds a Yandex Browser video translation to other browsers",
"version": "1.7.0",
"version": "1.7.1-beta1",
"author": "sodapng, mynovelhost, Toil, SashaXser, MrSoczekXD",
"namespace": "vot",
"icon": "https://translate.yandex.ru/icons/favicon.ico",
Expand Down
47 changes: 44 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@
"bypassMediaCSP",
Number(!!this.audioContext),
),
restoreMultiMediaKeys: votStorage.get(
"restoreMultiMediaKeys",
Number(!!this.audioContext),
),
showPiPButton: votStorage.get("showPiPButton", 0),
translateAPIErrors: votStorage.get("translateAPIErrors", 1),
translationService: votStorage.get(
Expand Down Expand Up @@ -363,7 +367,7 @@
}

// convert old vot-worker domain to actual
// TODO: remove converter in one of the next versions after release 1.7.0

Check warning on line 370 in src/index.js

View workflow job for this annotation

GitHub Actions / node (18.18.x)

Complete the task associated to this "TODO" comment

Check warning on line 370 in src/index.js

View workflow job for this annotation

GitHub Actions / node (22.x)

Complete the task associated to this "TODO" comment
if (this.data.proxyWorkerHost === "vot.toil.cc") {
this.data.proxyWorkerHost = proxyWorkerHost;
await votStorage.set("proxyWorkerHost", proxyWorkerHost);
Expand Down Expand Up @@ -473,7 +477,7 @@
}
}

initUI() {

Check warning on line 480 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 29 to the 15 allowed

Check warning on line 480 in src/index.js

View workflow job for this annotation

GitHub Actions / node (22.x)

Refactor this function to reduce its Cognitive Complexity from 29 to the 15 allowed
// VOT Button
{
this.votButton = ui.createVOTButton(
Expand Down Expand Up @@ -875,6 +879,19 @@
this.votBypassMediaCSPCheckbox.container,
);

this.votRestoreMultiMediaKeysCheckbox = ui.createCheckbox(
localizationProvider.get("VOTRestoreMultiMediaKeys"),
this.data?.restoreMultiMediaKeys ?? false,
);
if (!this.audioContext) {
this.votRestoreMultiMediaKeysCheckbox.input.disabled = true;
this.votRestoreMultiMediaKeysCheckbox.container.title =
localizationProvider.get("VOTNeedWebAudioAPI");
}
this.votSettingsDialog.bodyContainer.appendChild(
this.votRestoreMultiMediaKeysCheckbox.container,
);

// ABOUT

this.votAboutHeader = ui.createHeader(localizationProvider.get("about"));
Expand Down Expand Up @@ -1535,6 +1552,28 @@
})();
});

this.votRestoreMultiMediaKeysCheckbox.input.addEventListener(
"change",
(e) => {
(async () => {
this.data.restoreMultiMediaKeys = Number(e.target.checked);
await votStorage.set(
"restoreMultiMediaKeys",
this.data.restoreMultiMediaKeys,
);
debug.log(
"restoreMultiMediaKeys value changed. New value: ",
this.data.restoreMultiMediaKeys,
);
this.stopTranslate();
// TODO: delete if everything goes well

Check warning on line 1569 in src/index.js

View workflow job for this annotation

GitHub Actions / node (18.18.x)

Complete the task associated to this "TODO" comment

Check warning on line 1569 in src/index.js

View workflow job for this annotation

GitHub Actions / node (22.x)

Complete the task associated to this "TODO" comment
this.votBypassMediaCSPCheckbox.input.disabled = e.target.checked;
this.votBypassMediaCSPCheckbox.input.value =
e.target.checked ?? this.data.bypassMediaCSP;
})();
},
);

this.votUpdateLocaleFilesButton.addEventListener("click", () => {
(async () => {
await votStorage.set("locale-hash", "");
Expand Down Expand Up @@ -2214,7 +2253,7 @@
this.audio.currentTime = this.video.currentTime;
this.audio.playbackRate = this.video.playbackRate;

return this.needBypassCSP()
return this.needUseAudioContext()
? this.lipsyncAudioContext(mode)
: this.lipsyncAudio(mode);
}
Expand All @@ -2225,7 +2264,9 @@
this.lipSync(event.type);
};

needBypassCSP = () => this.data.bypassMediaCSP && this.site.needBypassCSP;
needUseAudioContext = () =>
(this.data.bypassMediaCSP && this.site.needBypassCSP) ||
this.data.restoreMultiMediaKeys;

// Default actions on stop translate
stopTranslate() {
Expand Down Expand Up @@ -2414,7 +2455,7 @@
}

// eslint-disable-next-line sonarjs/no-unused-expressions
this.needBypassCSP()
this.needUseAudioContext()
? await this.configurePlaySound(audioUrl)
: (this.audio.src = audioUrl);

Expand Down Expand Up @@ -2443,7 +2484,7 @@
}

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

Check warning on line 2487 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 2487 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
Loading