Skip to content

Commit

Permalink
chore: added logic to set proxy status
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyhalight committed Jan 9, 2025
1 parent 22703c8 commit c497ca2
Show file tree
Hide file tree
Showing 66 changed files with 445 additions and 175 deletions.
14 changes: 7 additions & 7 deletions dist/vot-min.user.js

Large diffs are not rendered by default.

88 changes: 65 additions & 23 deletions dist/vot.user.js

Large diffs are not rendered by default.

84 changes: 63 additions & 21 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ class VideoHandler {

videoTranslations = []; // list of video translations
videoTranslationTTL = 7200; // 2 hours
translateProxyEnabled = 0; // 0 - disabled, 1 - enabled, 2 - proxy everything
cachedTranslation; // cached video translation

downloadTranslationUrl = null;
Expand Down Expand Up @@ -422,6 +421,8 @@ class VideoHandler {
hotkeyButton: votStorage.get("hotkeyButton", null),
m3u8ProxyHost: votStorage.get("m3u8ProxyHost", m3u8ProxyHost),
proxyWorkerHost: votStorage.get("proxyWorkerHost", proxyWorkerHost),
// 0 - disabled, 1 - enabled, 2 - proxy everything
translateProxyEnabled: votStorage.get("translateProxyEnabled", 0),
audioBooster: votStorage.get("audioBooster", 0),
useNewModel: votStorage.get("useNewModel", 1),
localeHash: votStorage.get("locale-hash", ""),
Expand Down Expand Up @@ -474,41 +475,33 @@ class VideoHandler {
);

if (
!this.translateProxyEnabled &&
!this.data.translateProxyEnabled &&
GM_info?.scriptHandler &&
proxyOnlyExtensions.includes(GM_info.scriptHandler)
) {
this.translateProxyEnabled = 1;
this.data.translateProxyEnabled = 1;
}

if (!countryCode) {
try {
const response = await GM_fetch("https://speed.cloudflare.com/meta", {
timeout: 7000,
});
const { country } = await response.json();
countryCode = country;
this.translateProxyEnabled =
country === "UA" ? 2 : this.translateProxyEnabled;
({ country: countryCode } = await response.json());
if (countryCode === "UA") {
this.data.translateProxyEnabled = 2;
}
} catch (err) {
console.error("[VOT] Error getting country:", err);
}
} else if (countryCode === "UA") {
this.translateProxyEnabled = 2;
this.data.translateProxyEnabled = 2;
}

debug.log("translateProxyEnabled", this.translateProxyEnabled);
debug.log("translateProxyEnabled", this.data.translateProxyEnabled);
debug.log("Extension compatibility passed...");

this.votOpts = {
fetchFn: GM_fetch,
hostVOT: votBackendUrl,
host: this.translateProxyEnabled ? this.data.proxyWorkerHost : workerHost,
};

this.votClient = new (
this.translateProxyEnabled ? VOTWorkerClient : VOTClient
)(this.votOpts);
this.initVOTClient();

this.subtitlesWidget = new SubtitlesWidget(
this.video,
Expand Down Expand Up @@ -538,6 +531,21 @@ class VideoHandler {
this.initialized = true;
}

initVOTClient() {
this.votOpts = {
fetchFn: GM_fetch,
hostVOT: votBackendUrl,
host: this.data.translateProxyEnabled
? this.data.proxyWorkerHost
: workerHost,
};

this.votClient = new (
this.data.translateProxyEnabled ? VOTWorkerClient : VOTClient
)(this.votOpts);
return this;
}

isLoadingText(text) {
return (
text.includes(localizationProvider.get("translationTake")) ||
Expand Down Expand Up @@ -975,6 +983,40 @@ class VideoHandler {
this.votProxyWorkerHostTextfield.container,
);

const proxyEnabledLabels = [
localizationProvider.get("VOTTranslateProxyDisabled"),
localizationProvider.get("VOTTranslateProxyEnabled"),
localizationProvider.get("VOTTranslateProxyEverything"),
];

this.votTranslateProxyEnabledSelect = ui.createVOTSelect(
proxyEnabledLabels[this.data.translateProxyEnabled],
localizationProvider.get("VOTTranslateProxyStatus"),
genOptionsByOBJ(
proxyEnabledLabels,
proxyEnabledLabels[this.data.translateProxyEnabled],
),
{
onSelectCb: async (_, selectedValue) => {
this.data.translateProxyEnabled =
proxyEnabledLabels.findIndex((val) => val === selectedValue) ?? 0;
await votStorage.set(
"translateProxyEnabled",
this.data.translateProxyEnabled,
);
this.initVOTClient();
this.videoTranslations = [];
},
labelElement: ui.createVOTSelectLabel(
localizationProvider.get("VOTTranslateProxyStatus"),
),
},
);

this.votSettingsDialog.bodyContainer.appendChild(
this.votTranslateProxyEnabledSelect.container,
);

this.votNewAudioPlayerCheckbox = ui.createCheckbox(
localizationProvider.get("VOTNewAudioPlayer"),
this.data?.newAudioPlayer ?? false,
Expand Down Expand Up @@ -1735,7 +1777,7 @@ class VideoHandler {
"proxyWorkerHost value changed. New value: ",
this.data.proxyWorkerHost,
);
if (this.translateProxyEnabled) {
if (this.data.translateProxyEnabled) {
this.votClient.host = this.data.proxyWorkerHost;
}
})();
Expand Down Expand Up @@ -2111,7 +2153,7 @@ class VideoHandler {
} else {
const subtitlesObj = this.subtitlesList.at(parseInt(subs));
if (
this.translateProxyEnabled === 2 &&
this.data.translateProxyEnabled === 2 &&
subtitlesObj.url.startsWith(
"https://brosubs.s3-private.mds.yandex.net/vtrans/",
)
Expand Down Expand Up @@ -2530,7 +2572,7 @@ class VideoHandler {

proxifyAudio(audioUrl) {
if (
this.translateProxyEnabled === 2 &&
this.data.translateProxyEnabled === 2 &&
audioUrl.startsWith("https://vtrans.s3-private.mds.yandex.net/tts/prod/")
) {
const audioPath = audioUrl.replace(
Expand Down
124 changes: 62 additions & 62 deletions src/localization/hashes.json
Original file line number Diff line number Diff line change
@@ -1,64 +1,64 @@
{
"af": "be62a5edf04a111c1a6ac8c0b4ef6727",
"am": "7481188a0d953d1ccc0fbe25181cbdc3",
"ar": "e4daa7cbd5ba4b5e14b68248aad5e7c0",
"az": "47aa19dff6e58f756f6b3653a18fd952",
"bg": "30f236e34b450ea24e9b9f702e08440d",
"bn": "c1d81d3afac6977d1acf263ba5ea1116",
"bs": "6b2cca3ab748bfae89e32414a0b62d15",
"ca": "c0a49af5f7b115e80f8e6266f50ee954",
"cs": "84d8ececa8a80a6350a66deea72111ad",
"cy": "6c5c5f57f1e9d8ca55e847173039f666",
"da": "7841fe2dcb2de40eb6b199f84f1f3d8e",
"de": "ef9873af15eff7b2ec9e720bfe31da93",
"el": "d6fc48d4e79d2d817ef6fd9170fb7c7b",
"en": "93cdc28ca3309cd0e4accdbc6987a7a4",
"es": "d9194d94eb1b07f664d52dfbeac01ef0",
"et": "119f612359fed7013ee22aba34039aac",
"eu": "34b3e81dd53350d3485a40b03570d18e",
"fa": "d6a9030090cd19eb0d7e1477b7e8f378",
"fi": "aea1e3b2a1604c3f60814e9ead9acb8e",
"fr": "ad37da595a4c3510526c20cf8967c11e",
"gl": "1589c2abd57f165dbe3c80096f6bc627",
"hi": "9ae19960d07d46ceba367a677d792efd",
"hr": "5c9567f98db23a2dce730c0e555cb34a",
"hu": "f0098fd50b6733035cf6a1da9de8cbc9",
"hy": "69dc46a38fbe804dc61f9bab2a73e0fc",
"id": "d032618fa522fe911ea085fe11fa103f",
"it": "b148172a6af58cdababd0649f0b49a9a",
"ja": "61efbc0fddb3b08fb453252e6b9cec6d",
"jv": "4fcfd295a7c45f508518f7f8d2b2aca9",
"kk": "8d25ccfecde3159bf3d3f217dbe04ed1",
"km": "62f4faa415b45f57d810f05bb2e61973",
"kn": "290ed45d278b648d27dc790333118f51",
"ko": "490bfb4b3fb7c0047c2640cba702a139",
"lo": "f7d4ad17775ade15ba8f53ea5f0e7814",
"mk": "37e4e56d631e6d6e654b02e16f793ddd",
"ml": "bb91d553e05cddf678846a9d87daee81",
"mn": "95417f5a2caac485289335c443a35e8e",
"ms": "8713ef1cfdf5edb97704b9cc62c0342b",
"mt": "bbd3a60bb3014acf0ba40307a8e07316",
"my": "2121770dfc0bdcecf15afac61c9c5b3e",
"ne": "5deb1c7b959f72adaa58077cfc816da2",
"nl": "30a6391b84d0d160ef4dd1a438f37789",
"pa": "6b8c35f78fbae05a10c1d5d3ee71e859",
"pl": "818e74ec77f268c278152ea3c8ef5de8",
"pt": "7c7711e11e638bb7b14a4eea9f48d5b5",
"ro": "cf709a3ce5ac837f70c70826a4f7ab00",
"ru": "a21636dc154aafc576056298fce14ddc",
"si": "a0283c3f2dfee8b7c3a49c476ec55766",
"sk": "0c8d1893d59c32f203eee30534bc1413",
"sl": "0a0a45735de61ce886b6392035b9512e",
"sq": "9f668cd6f6819582549e5c92ea9f0edc",
"sr": "bf9985444df5e1e2acbc59f3b8ac2508",
"su": "e12fcd92e3ac912ec255e37c245504fe",
"sv": "c19e03cdbdab2d64b4890c491fe2d630",
"sw": "3bea97a08bf38f27512751941fb0b9ea",
"tr": "9073b0f7f9b4f5d34ac08cbc9a3e081f",
"uk": "28263ad970e0e31e6f80627cbf0224d3",
"ur": "36219c85fe3880a4e1bfbbb512aadcbc",
"uz": "43cd933f0422cfbca6ab36bc83db2e64",
"vi": "2076de29638e226195faaa2b2159ab6e",
"zh": "90dfb0ef50986ab75089759d238aa16c",
"zu": "686f762b4722c902a087c2ab950fea45"
"af": "91b2e5398f28956c5bf3b4a9e886ab55",
"am": "d9242a13193b4ace2149af391e158499",
"ar": "c91ceef85e71dd0afca33119bf608105",
"az": "8532217b340bc17054106f5d70da1426",
"bg": "a2b4333033a56adc07b3c1be6ba4ca48",
"bn": "ac85c41bb78d4bb679eb7254e4ed9732",
"bs": "123c3ece1ab5b25ab633f32f2a43a95e",
"ca": "8d6bb5d5a07a7426f6f4a215ed8516a3",
"cs": "5ebaffda0be82705bb08f324a58232b6",
"cy": "8f5ebc887a3b673d5530938b7753f400",
"da": "d52bd97a6fbe830b5a36faf131c08663",
"de": "6e8766b17a42e6b819e94d2209c03b90",
"el": "3832a787859ae27d95517bea3028ca44",
"en": "171cc5600f63c1698b798fd31dd213b0",
"es": "796f7b2725b4fca664c009ca2cfe0d4e",
"et": "da3bc513b9bb69d6b98ce236c2469560",
"eu": "7f5f5c4258827210fa3648d2ab589d8c",
"fa": "fdec3886eaae4974c01c9dd291378654",
"fi": "caf449e3321b391f2d0a9821ba0ad381",
"fr": "fb558c589de992b4224a1930f7f7b638",
"gl": "792d4c120fbc4dcbae68ccd66a495879",
"hi": "f872dcb732f56445cbc5e1ce5ff0b0d4",
"hr": "b49e27440361a4fc15d892f4ca9948a9",
"hu": "28ec0289883dd59a93fcdee86c5fe509",
"hy": "d46c675d5fd5fe12705d8b7374b298af",
"id": "20c3b1db7109410b5e10c5b928f1395d",
"it": "39b23bc9c489f6e2d7019f9dd0dbb1d1",
"ja": "175c647d5ac7c8d70376c504a81b6aff",
"jv": "9589a03f8fd39cf4fce195dc18b11fbf",
"kk": "ec2e87a71a07b544214505d45cd11c54",
"km": "65a7f0a5b463a3d2f981883dfacb66cc",
"kn": "8f82f6749815069c0aaf0ebeb6450c82",
"ko": "185f8d35b55e4e8a023686d7446725ec",
"lo": "bf5245d280f26c5537f828945b04c301",
"mk": "05b5d5267d1498c8414d564579f82112",
"ml": "faf6d48d7be3cd35d41ea4ac5dc66f15",
"mn": "3d17854e57fa6881a82acb39ea47e765",
"ms": "cadda3cad511f57ea28cfcd22552be3f",
"mt": "dcdf47b2efa1a88f2335eb13f68c395a",
"my": "0016595e6ffe54d648d8d3f7642b3ed7",
"ne": "26313a1527206a547080723bb807c278",
"nl": "7cb31462ef0521f3fe6ddf873a155f1e",
"pa": "372b0aa231c1e6dfc16a447490a19ad9",
"pl": "636b5a6837a95c9288519a8bf9ccbb77",
"pt": "8426957d5352cf80224aca11361f0c0e",
"ro": "27c947797f69c108038aaf20f515b1e0",
"ru": "156981d36239c9288942e0eb5cb6709a",
"si": "9b33551456c6263d8fcfc06e200f3e9d",
"sk": "11b1386f3759203c088d477f4f85a047",
"sl": "d3410e13aa414e5b9b393058a1e6dc15",
"sq": "c8bce7050b87512ac412d18566f0eb87",
"sr": "dd0d7593cf8e802e5a95bddd317a31cc",
"su": "9daafa183e90f43bf77493cd7ecc98b3",
"sv": "02eb6dfb6d53f46c7a3cbe1b7bf43c08",
"sw": "71f60ba0c10f582ad3f9ccf69f713423",
"tr": "55c2356514f720c4184c109fb38d3d77",
"uk": "dd527ed5c44012a67fb6f742dc62cf66",
"ur": "e03a33d476d245a1bff229304fe7e71a",
"uz": "2d79654782ca4f369bb409be51769b54",
"vi": "c1dd88db8f58d943d8d3f83eebea8af1",
"zh": "5eb80978727ddd436716c749a0f476c7",
"zu": "111f9a01adb6dbac016c37e4c25a6b2f"
}
5 changes: 4 additions & 1 deletion src/localization/locales/af.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,8 @@
"TranslationDelayed": "Die vertaling is effens vertraag",
"VOTTranslationCompletedNotify": "Die vertaling op die {0} is voltooi!",
"VOTSendNotifyOnComplete": "Stuur'n kennisgewing dat die video vertaal is",
"VOTBugReport": "Rapporteer'n fout"
"VOTBugReport": "Rapporteer'n fout",
"VOTTranslateProxyDisabled": "Gedeaktiveer",
"VOTTranslateProxyEnabled": "Geaktiveer",
"VOTTranslateProxyEverything": "Volmag alles"
}
5 changes: 4 additions & 1 deletion src/localization/locales/am.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,8 @@
"TranslationDelayed": "ትርጉሙ ትንሽ ዘግይቷል",
"VOTTranslationCompletedNotify": "በ {0} ላይ ያለው ትርጉም ተጠናቅቋል!",
"VOTSendNotifyOnComplete": "ቪዲዮው የተተረጎመ መሆኑን ማሳወቂያ ይላኩ",
"VOTBugReport": "ሳንካ ሪፖርት ያድርጉ"
"VOTBugReport": "ሳንካ ሪፖርት ያድርጉ",
"VOTTranslateProxyDisabled": "አካል ጉዳተኞች",
"VOTTranslateProxyEnabled": "ነቅቷል",
"VOTTranslateProxyEverything": "ሁሉንም ነገር ተኪ"
}
5 changes: 4 additions & 1 deletion src/localization/locales/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,8 @@
"TranslationDelayed": "الترجمة متأخرة قليلا",
"VOTTranslationCompletedNotify": "تم الانتهاء من الترجمة على {0}!",
"VOTSendNotifyOnComplete": "إرسال إشعار بأن الفيديو قد تمت ترجمته",
"VOTBugReport": "الإبلاغ عن خطأ"
"VOTBugReport": "الإبلاغ عن خطأ",
"VOTTranslateProxyDisabled": "معاق",
"VOTTranslateProxyEnabled": "ممكن",
"VOTTranslateProxyEverything": "وكيل كل شيء"
}
5 changes: 4 additions & 1 deletion src/localization/locales/az.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,8 @@
"TranslationDelayed": "Tərcümə bir az gecikir",
"VOTTranslationCompletedNotify": "Tərcümə {0} tamamlandı!",
"VOTSendNotifyOnComplete": "Videonun tərcümə olunduğunu bildirən bildiriş göndərin",
"VOTBugReport": "Səhv bildirin"
"VOTBugReport": "Səhv bildirin",
"VOTTranslateProxyDisabled": "Əlil",
"VOTTranslateProxyEnabled": "Daxildir",
"VOTTranslateProxyEverything": "Hər şey üçün proxy server"
}
5 changes: 4 additions & 1 deletion src/localization/locales/bg.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,8 @@
"TranslationDelayed": "Преводът леко закъснява.",
"VOTTranslationCompletedNotify": "Преводът на {0} е завършен!",
"VOTSendNotifyOnComplete": "Изпратете съобщение, че видеото е преведено",
"VOTBugReport": "Съобщете за грешка"
"VOTBugReport": "Съобщете за грешка",
"VOTTranslateProxyDisabled": "Изключено",
"VOTTranslateProxyEnabled": "Включено",
"VOTTranslateProxyEverything": "Прокси всичко"
}
5 changes: 4 additions & 1 deletion src/localization/locales/bn.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,8 @@
"TranslationDelayed": "অনুবাদ সামান্য বিলম্বিত হয়",
"VOTTranslationCompletedNotify": "{0} এর অনুবাদ সম্পন্ন হয়েছে!",
"VOTSendNotifyOnComplete": "একটি বিজ্ঞপ্তি পাঠান যে ভিডিওটি অনুবাদ করা হয়েছে",
"VOTBugReport": "একটি বাগ রিপোর্ট করুন"
"VOTBugReport": "একটি বাগ রিপোর্ট করুন",
"VOTTranslateProxyDisabled": "নিষ্ক্রিয়",
"VOTTranslateProxyEnabled": "সক্রিয়",
"VOTTranslateProxyEverything": "প্রক্সি সবকিছু"
}
5 changes: 4 additions & 1 deletion src/localization/locales/bs.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,8 @@
"TranslationDelayed": "Prevod je malo odložen",
"VOTTranslationCompletedNotify": "Prevod na {0} je završen!",
"VOTSendNotifyOnComplete": "Pošaljite obavještenje da je video preveden",
"VOTBugReport": "Prijavi grešku"
"VOTBugReport": "Prijavi grešku",
"VOTTranslateProxyDisabled": "Isključeno",
"VOTTranslateProxyEnabled": "Uključeno",
"VOTTranslateProxyEverything": "Proxy sve"
}
5 changes: 4 additions & 1 deletion src/localization/locales/ca.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,8 @@
"TranslationDelayed": "La traducció es retarda lleugerament",
"VOTTranslationCompletedNotify": "La traducció al {0} s'ha completat!",
"VOTSendNotifyOnComplete": "Envia una notificació que el vídeo ha estat traduït",
"VOTBugReport": "Informa d ' un error"
"VOTBugReport": "Informa d ' un error",
"VOTTranslateProxyDisabled": "Deshabilitat",
"VOTTranslateProxyEnabled": "Habilitat",
"VOTTranslateProxyEverything": "Proxy tot"
}
5 changes: 4 additions & 1 deletion src/localization/locales/cs.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,8 @@
"TranslationDelayed": "Překlad je mírně zpožděn",
"VOTTranslationCompletedNotify": "Překlad na {0} byl dokončen!",
"VOTSendNotifyOnComplete": "Pošlete oznámení, že video bylo přeloženo",
"VOTBugReport": "Nahlásit chybu"
"VOTBugReport": "Nahlásit chybu",
"VOTTranslateProxyDisabled": "Zakázán",
"VOTTranslateProxyEnabled": "Povolit",
"VOTTranslateProxyEverything": "Proxy vše"
}
5 changes: 4 additions & 1 deletion src/localization/locales/cy.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,8 @@
"TranslationDelayed": "Mae'r cyfieithiad ychydig yn oedi",
"VOTTranslationCompletedNotify": "Mae'r cyfieithiad ar y {0} wedi ei gwblhau!",
"VOTSendNotifyOnComplete": "Anfon hysbysiad bod y fideo wedi'i gyfieithu",
"VOTBugReport": "Rhoi gwybod am nam"
"VOTBugReport": "Rhoi gwybod am nam",
"VOTTranslateProxyDisabled": "Analluogwyd",
"VOTTranslateProxyEnabled": "Galluogwyd",
"VOTTranslateProxyEverything": "Dirprwy popeth"
}
5 changes: 4 additions & 1 deletion src/localization/locales/da.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,5 +199,8 @@
"TranslationDelayed": "Oversættelsen er lidt forsinket",
"VOTTranslationCompletedNotify": "Oversættelsen på {0} er afsluttet!",
"VOTSendNotifyOnComplete": "Send en meddelelse om, at videoen er blevet oversat",
"VOTBugReport": "Rapporter en fejl"
"VOTBugReport": "Rapporter en fejl",
"VOTTranslateProxyDisabled": "Deaktiveret",
"VOTTranslateProxyEnabled": "Aktiveret",
"VOTTranslateProxyEverything": "Fuldmagt alt"
}
Loading

1 comment on commit c497ca2

@ilyhalight
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Кроме этого нет идей, как можно было бы исправить рандомные проблемы с запросами

Please sign in to comment.