Skip to content

Commit

Permalink
fix issue-#37
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyhalight committed Oct 20, 2022
1 parent 4cc0b9f commit e37c8bd
Showing 1 changed file with 75 additions and 73 deletions.
148 changes: 75 additions & 73 deletions vot.user.js
Original file line number Diff line number Diff line change
Expand Up @@ -535,98 +535,100 @@ $("body").on("yt-page-data-updated", async function () {

const translateYTFunc = (VIDEO_ID) => translateVideo(`https://youtu.be/${VIDEO_ID}`, 0x4075500000000000, function (success, urlOrError) {

if (!success) {
transformBtnError(urlOrError);
if (urlOrError === 'Перевод займет несколько минут') {
clearTimeout(autoRetry);
autoRetry = setTimeout(() => {
translateYTFunc(VIDEO_ID);
}, 70000)
if (getVideoId('youtube') === VIDEO_ID) {
if (!success) {
transformBtnError(urlOrError);
if (urlOrError === 'Перевод займет несколько минут') {
clearTimeout(autoRetry);
autoRetry = setTimeout(() => {
translateYTFunc(VIDEO_ID);
}, 70000)
}
throw urlOrError;
}
throw urlOrError;
}

audio.src = urlOrError;
if (typeof(dbDefaultVolume) === 'number') {
audio.volume = dbDefaultVolume / 100;
}

$("body").on("yt-page-data-updated", function () {
audio.pause();
$("video").off(".translate");
deleteAudioSrc();
});

if (!video.paused) {
lipSync("play");
}

$("video").on("playing.translate ratechange.translate", function () {
lipSync();
});
audio.src = urlOrError;
if (typeof(dbDefaultVolume) === 'number') {
audio.volume = dbDefaultVolume / 100;
}

$("video").on("play.translate canplaythrough.translate", function () {
lipSync();
$("body").on("yt-page-data-updated", function () {
audio.pause();
$("video").off(".translate");
deleteAudioSrc();
});

if (!video.paused) {
lipSync("play");
}
});

$("video").on("pause.translate waiting.translate", function () {
lipSync("pause");
});
$("video").on("playing.translate ratechange.translate", function () {
lipSync();
});

$translationBtn.text('Выключить');
changeColor("#A36EFF");
changeBackgroundSuccess();
if (typeof(dbDefaultVolume) === 'number') {
var defaultTranslateVolume = dbDefaultVolume;
} else {
var defaultTranslateVolume = 100;
}
$("video").on("play.translate canplaythrough.translate", function () {
lipSync();

const volumeBox = $(`
<div class = "translationMenuContainer">
<span class = "translationHeader">Громкость перевода: <b class = "volumePercent">${defaultTranslateVolume}%</b></span>
<div class = "translationVolumeBox" tabindex = "0">
<input type="range" min="0" max="100" value=${defaultTranslateVolume} class="translationVolumeSlider">
</div>
</div>`
);
const volumeSlider = volumeBox.find('.translationVolumeSlider');

if (!$translationMenuContent.has('.translationVolumeBox').length) {
$translationMenuContent.append(volumeBox);
let $volumePercent = volumeBox.find('.volumePercent');
volumeSlider.on('input', async () => {
let value = volumeSlider.val();
audio.volume = (value / 100);
$volumePercent.text(`${value}%`);
await updateDB({defaultVolume: Number(value)});
if (!video.paused) {
lipSync("play");
}
});
}

if (dbShowVideoSlider === 1) {
const videoVolumeBox = $(`
$("video").on("pause.translate waiting.translate", function () {
lipSync("pause");
});

$translationBtn.text('Выключить');
changeColor("#A36EFF");
changeBackgroundSuccess();
if (typeof(dbDefaultVolume) === 'number') {
var defaultTranslateVolume = dbDefaultVolume;
} else {
var defaultTranslateVolume = 100;
}

const volumeBox = $(`
<div class = "translationMenuContainer">
<span class = "translationHeader">Громкость оригинала: <b class = "volumePercent">${video.volume * 100}%</b></span>
<div class = "translationVideoVolumeBox" tabindex = "0">
<input type="range" min="0" max="100" value=${video.volume * 100} class="translationVolumeSlider">
<span class = "translationHeader">Громкость перевода: <b class = "volumePercent">${defaultTranslateVolume}%</b></span>
<div class = "translationVolumeBox" tabindex = "0">
<input type="range" min="0" max="100" value=${defaultTranslateVolume} class="translationVolumeSlider">
</div>
</div>`
);
const videoVolumeSlider = videoVolumeBox.find('.translationVolumeSlider');

if (!$translationMenuContent.has('.translationVideoVolumeBox').length) {
$translationMenuContent.append(videoVolumeBox);
let $volumePercent = videoVolumeBox.find('.volumePercent');
videoVolumeSlider.on('input', async () => {
let value = videoVolumeSlider.val();
video.volume = (value / 100);
const volumeSlider = volumeBox.find('.translationVolumeSlider');

if (!$translationMenuContent.has('.translationVolumeBox').length) {
$translationMenuContent.append(volumeBox);
let $volumePercent = volumeBox.find('.volumePercent');
volumeSlider.on('input', async () => {
let value = volumeSlider.val();
audio.volume = (value / 100);
$volumePercent.text(`${value}%`);
await updateDB({defaultVolume: Number(value)});
});
}

if (dbShowVideoSlider === 1) {
const videoVolumeBox = $(`
<div class = "translationMenuContainer">
<span class = "translationHeader">Громкость оригинала: <b class = "volumePercent">${video.volume * 100}%</b></span>
<div class = "translationVideoVolumeBox" tabindex = "0">
<input type="range" min="0" max="100" value=${video.volume * 100} class="translationVolumeSlider">
</div>
</div>`
);
const videoVolumeSlider = videoVolumeBox.find('.translationVolumeSlider');

if (!$translationMenuContent.has('.translationVideoVolumeBox').length) {
$translationMenuContent.append(videoVolumeBox);
let $volumePercent = videoVolumeBox.find('.volumePercent');
videoVolumeSlider.on('input', async () => {
let value = videoVolumeSlider.val();
video.volume = (value / 100);
$volumePercent.text(`${value}%`);
});
}
}
}
});

Expand Down

0 comments on commit e37c8bd

Please sign in to comment.