diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index c0426fc..35f9cf9 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -71,7 +71,7 @@ "message": "Search Engine Redirects", "description": "Label for enable/disable Search Engine redirects option (options & pop-up)." }, - "disableTranslate": { + "disable": { "message": "SimplyTranslate Redirects", "description": "Label for enable/disable SimplyTranslate redirects option (options & pop-up)." }, diff --git a/src/_locales/es/messages.json b/src/_locales/es/messages.json index b7a3b4f..f2aa3af 100644 --- a/src/_locales/es/messages.json +++ b/src/_locales/es/messages.json @@ -63,7 +63,7 @@ "message": "Redirecciones de Buscador", "description": "Etiqueta para activar/desactivar la opción de redirecciones de Buscador (opciones y pop-up)." }, - "disableTranslate": { + "disable": { "message": "Redirecciones de SimplyTranslate", "description": "Etiqueta para activar/desactivar la opción de redirecciones de SimplyTranslate (opciones y pop-up)." }, diff --git a/src/_locales/it/messages.json b/src/_locales/it/messages.json index 641f784..38359eb 100644 --- a/src/_locales/it/messages.json +++ b/src/_locales/it/messages.json @@ -59,7 +59,7 @@ "message": "Reindirizzamenti motore di ricerca", "description": "Label for enable/disable Search Engine redirects option (options & pop-up)." }, - "disableTranslate": { + "disable": { "message": "Reindirizzamenti SimplyTranslate", "description": "Label for enable/disable SimplyTranslate redirects option (options & pop-up)." }, diff --git a/src/_locales/ru/messages.json b/src/_locales/ru/messages.json index 5564586..dc2fb18 100644 --- a/src/_locales/ru/messages.json +++ b/src/_locales/ru/messages.json @@ -59,7 +59,7 @@ "message": "Перенаправление поисковой системы", "description": "Название настройки для включения/выключения перенаправления поисковой системы (в настройках и всплывающем окне)." }, - "disableTranslate": { + "disable": { "message": "Перенаправление на SimplyTranslate", "description": "Название настройки для включения/выключения перенаправления на SimplyTranslate (в настройках и всплывающем окне)." }, @@ -87,7 +87,7 @@ "message": "Всегда включать темный режим Invidious", "description": "Название настройки для 'Всегда включать темный режим Invidious' (в настройках)." }, - "invidiousVolume": { + "volume": { "message": "Громкость Invidious", "description": "Название настройки для 'Громкость Invidious' (в настройках)." }, @@ -99,7 +99,7 @@ "message": "Субтитры Invidious - коды языков (разделяются запятой)", "description": "Название настройки для 'Субтитры Invidious - коды языков (разделяются запятой)' (в настройках)." }, - "invidiousAutoplay": { + "autoplay": { "message": "Автоматически воспроизводить видео Invidious при загрузке", "description": "Название настройки для 'Автоматически воспроизводить видео Invidious при загрузке' (в настройках)." }, diff --git a/src/assets/javascripts/helpers/translate.js b/src/assets/javascripts/helpers/translate.js index de76fe8..98546bc 100644 --- a/src/assets/javascripts/helpers/translate.js +++ b/src/assets/javascripts/helpers/translate.js @@ -78,7 +78,6 @@ function setSimplyTranslateCustomRedirects(val) { console.log("simplyTranslateCustomRedirects: ", val) } - function setLingvaRedirects(val) { redirects.lingva = val; browser.storage.sync.set({ translateRedirects: redirects }) @@ -107,45 +106,62 @@ function setLingvaCustomRedirects(val) { console.log("lingvaCustomRedirects: ", val) } - -let disableTranslate; -const getDisableTranslate = () => disableTranslate; -function setDisableTranslate(val) { - disableTranslate = val; - browser.storage.sync.set({ disableTranslate }) - console.log("disableTranslate: ", disableTranslate) +let disable; +const getDisable = () => disable; +function setDisable(val) { + disable = val; + browser.storage.sync.set({ translateDisable: disable }) + console.log("disable: ", disable) } -let translateFrontend; -const getFrontend = () => translateFrontend; +let frontend; +const getFrontend = () => frontend; function setFrontend(val) { - translateFrontend = val; - browser.storage.sync.set({ translateFrontend }) - console.log("Translate frontend: ", val) + frontend = val; + browser.storage.sync.set({ translateFrontend: frontend }) + console.log("translateFrontend: ", frontend) +} + +let from; +const getFrom = () => from; +function setFrom(val) { + from = val; + browser.storage.sync.set({ translateFrom: from }) + console.log("from: ", from) +} + +let to; +const getTo = () => to; +function setTo(val) { + to = val; + browser.storage.sync.set({ translateTo: to }) + console.log("to: ", to) +} + +function isTranslate(url) { + if (disable) return null; + return targets.includes(url.host) } function redirect(url, initiator) { - if (disableTranslate) { - console.log("SimplyTranslate disabled") - return null - }; - - if (translateFrontend == 'simplyTranslate') { - + let params_arr = url.search.split('&'); + params_arr[0] = params_arr[0].substring(1); + let myMap = {}; + for (let i = 0; i < params_arr.length; i++) { + let pair = params_arr[i].split('='); + myMap[pair[0]] = pair[1]; + } + if (frontend == 'simplyTranslate') { let instancesList = [...simplyTranslateRedirectsChecks, ...simplyTranslateCustomRedirects]; if (instancesList.length === 0) return null; let randomInstance = commonHelper.getRandomInstance(instancesList) - return `${randomInstance}/${url.search}`; + if (myMap.sl && myMap.tl && myMap.text) + return `${randomInstance}/${url.search}`; + else + return `${randomInstance}/?sl=${from}&tl=${to}` } - else if (translateFrontend == 'lingva') { - let params_arr = url.search.split('&'); - params_arr[0] = params_arr[0].substring(1); - let myMap = {}; - for (let i = 0; i < params_arr.length; i++) { - let pair = params_arr[i].split('='); - myMap[pair[0]] = pair[1]; - } + else if (frontend == 'lingva') { let instancesList = [...lingvaRedirectsChecks, ...lingvaCustomRedirects]; if (instancesList.length === 0) return null; let randomInstance = commonHelper.getRandomInstance(instancesList) @@ -158,26 +174,28 @@ function redirect(url, initiator) { } -function isTranslate(url) { - return targets.includes(url.host) -} - async function init() { return new Promise((resolve) => { browser.storage.sync.get( [ - "disableTranslate", + "translateDisable", "translateFrontend", "translateRedirects", "simplyTranslateRedirectsChecks", "simplyTranslateCustomRedirects", "lingvaRedirectsChecks", "lingvaCustomRedirects", - ], (result) => { - disableTranslate = result.disableTranslate ?? false; - translateFrontend = result.translateFrontend ?? "simplyTranslate"; - if (result.translateRedirects) - redirects = result.translateRedirects + "translateFrom", + "translateTo", + ], + (result) => { + disable = result.translateDisable ?? false; + frontend = result.translateFrontend ?? "simplyTranslate"; + + from = result.translateFrom ?? "auto"; + to = result.translateTo ?? 'en'; + + if (result.translateRedirects) redirects = result.translateRedirects simplyTranslateRedirectsChecks = result.simplyTranslateRedirectsChecks ?? [...redirects.simplyTranslate.normal]; simplyTranslateCustomRedirects = result.simplyTranslateCustomRedirects ?? []; @@ -199,12 +217,17 @@ export default { isTranslate, - getDisableTranslate, - setDisableTranslate, + getDisable, + setDisable, getFrontend, setFrontend, + getFrom, + setFrom, + getTo, + setTo, + getSimplyTranslateRedirectsChecks, setSimplyTranslateRedirectsChecks, diff --git a/src/assets/javascripts/helpers/youtube/invidious-cookies.js b/src/assets/javascripts/helpers/youtube/invidious-cookies.js index 1ccdf1f..6a168b8 100644 --- a/src/assets/javascripts/helpers/youtube/invidious-cookies.js +++ b/src/assets/javascripts/helpers/youtube/invidious-cookies.js @@ -18,20 +18,20 @@ browser.storage.sync.get( "invidiousVideoQuality", "invidiousDarkMode", "OnlyEmbeddedVideo", - "invidiousVolume", + "volume", "invidiousPlayerStyle", "invidiousSubtitles", - "invidiousAutoplay", + "autoplay", ], (result) => { const prefs = getCookie(); prefs.local = result.invidiousAlwaysProxy; prefs.quality = result.invidiousVideoQuality; prefs.dark_mode = result.invidiousDarkMode; - prefs.volume = result.invidiousVolume; + prefs.volume = result.volume; prefs.player_style = result.invidiousPlayerStyle; prefs.subtitles = result.invidiousSubtitles; - prefs.autoplay = result.invidiousAutoplay; + prefs.autoplay = result.autoplay; document.cookie = `PREFS=${encodeURIComponent(JSON.stringify(prefs))}`; } diff --git a/src/assets/javascripts/helpers/youtube/youtube.js b/src/assets/javascripts/helpers/youtube/youtube.js index 7c23f25..4d65b8c 100644 --- a/src/assets/javascripts/helpers/youtube/youtube.js +++ b/src/assets/javascripts/helpers/youtube/youtube.js @@ -141,20 +141,20 @@ function setInvidiousVideoQuality(val) { } const getInvidiousVideoQuality = () => invidiousVideoQuality; -let invidiousTheme; -const getInvidiousTheme = () => invidiousTheme; -function setInvidiousTheme(val) { - invidiousTheme = val; - browser.storage.sync.set({ invidiousTheme }) - console.log("invidiousTheme: ", invidiousTheme) +let theme; +const getTheme = () => theme; +function setTheme(val) { + theme = val; + browser.storage.sync.set({ youtubeTheme: theme }) + console.log("theme: ", theme) } -let invidiousVolume; -const getInvidiousVolume = () => invidiousVolume; -function setInvidiousVolume(val) { - invidiousVolume = val; - browser.storage.sync.set({ invidiousVolume }) - console.log("invidiousVolume: ", invidiousVolume) +let volume; +const getVolume = () => volume; +function setVolume(val) { + volume = val; + browser.storage.sync.set({ youtubeVolume: volume }) + console.log("youtubeVolume: ", volume) } let invidiousPlayerStyle; @@ -173,12 +173,12 @@ function setInvidiousSubtitles(val) { console.log("invidiousSubtitles: ", invidiousSubtitles) } -let invidiousAutoplay; -const getInvidiousAutoplay = () => invidiousAutoplay; -function setInvidiousAutoplay(val) { - invidiousAutoplay = val; - browser.storage.sync.set({ invidiousAutoplay }) - console.log("invidiousAutoplay: ", invidiousAutoplay) +let autoplay; +const getAutoplay = () => autoplay; +function setAutoplay(val) { + autoplay = val; + browser.storage.sync.set({ youtubeAutoplay: autoplay }) + console.log("autoplay: ", autoplay) } let frontend; @@ -262,14 +262,14 @@ async function init() { [ "invidiousAlwaysProxy", "invidiousVideoQuality", - "invidiousTheme", + "youtubeTheme", "persistInvidiousPrefs", "disableYoutube", "OnlyEmbeddedVideo", - "invidiousVolume", + "youtubeVolume", "invidiousPlayerStyle", "invidiousSubtitles", - "invidiousAutoplay", + "youtubeAutoplay", "youtubeRedirects", "youtubeFrontend", "invidiousRedirectsChecks", @@ -287,11 +287,11 @@ async function init() { invidiousAlwaysProxy = result.invidiousAlwaysProxy ?? 'DEFAULT'; OnlyEmbeddedVideo = result.OnlyEmbeddedVideo ?? 'both'; invidiousVideoQuality = result.invidiousVideoQuality ?? 'DEFAULT'; - invidiousTheme = result.invidiousTheme ?? 'DEFAULT'; - invidiousVolume = result.invidiousVolume ?? '--'; + theme = result.youtubeTheme ?? 'DEFAULT'; + volume = result.youtubeVolume ?? '--'; invidiousPlayerStyle = result.invidiousPlayerStyle ?? 'DEFAULT'; invidiousSubtitles = result.invidiousSubtitles || ''; - invidiousAutoplay = result.invidiousAutoplay ?? 'DEFAULT'; + autoplay = result.youtubeAutoplay ?? 'DEFAULT'; invidiousRedirectsChecks = result.invidiousRedirectsChecks ?? [...redirects.invidious.normal]; invidiousCustomRedirects = result.invidiousCustomRedirects ?? []; @@ -318,9 +318,6 @@ function invidiousInitCookies(tabId) { } function redirect(url, type) { - - console.log("type", type); - if (frontend == 'freeTube' && type === "main_frame") return `freetube://${url}`; @@ -335,11 +332,11 @@ function redirect(url, type) { if (invidiousAlwaysProxy != "DEFAULT") url.searchParams.append("local", invidiousAlwaysProxy); if (invidiousVideoQuality != "DEFAULT") url.searchParams.append("quality", invidiousVideoQuality); - if (invidiousTheme != "DEFAULT") url.searchParams.append("dark_mode", invidiousTheme); - if (invidiousVolume != "--") url.searchParams.append("volume", invidiousVolume); + if (theme != "DEFAULT") url.searchParams.append("dark_mode", theme); + if (volume != "--") url.searchParams.append("volume", volume); + if (autoplay != "DEFAULT") url.searchParams.append("autoplay", autoplay); if (invidiousPlayerStyle != "DEFAULT") url.searchParams.append("player_style", invidiousPlayerStyle); if (invidiousSubtitles.trim() != '') url.searchParams.append("subtitles", invidiousSubtitles); - if (invidiousAutoplay != "DEFAULT") url.searchParams.append("autoplay", invidiousAutoplay); return `${randomInstance}${url.pathname.replace("/shorts/", "/watch?v=")}${url.search}`; @@ -352,9 +349,9 @@ function redirect(url, type) { if (OnlyEmbeddedVideo == 'onlyEmbedded' && type !== "sub_frame") return null if (OnlyEmbeddedVideo == 'onlyNotEmbedded' && type !== "main_frame") return null; - if (invidiousTheme != "DEFAULT") url.searchParams.append("theme", invidiousTheme); - if (invidiousVolume != "--") url.searchParams.append("volume", invidiousVolume / 100); - if (invidiousAutoplay != "DEFAULT") url.searchParams.append("playerAutoPlay", invidiousAutoplay); + if (theme != "DEFAULT") url.searchParams.append("theme", theme); + if (volume != "--") url.searchParams.append("volume", volume / 100); + if (autoplay != "DEFAULT") url.searchParams.append("playerAutoPlay", autoplay); return `${randomInstance}${url.pathname.replace("/shorts/", "/watch?v=")}${url.search}`; } @@ -387,11 +384,11 @@ export default { setInvidiousVideoQuality, getInvidiousVideoQuality, - setInvidiousTheme, - getInvidiousTheme, + setTheme, + getTheme, - setInvidiousVolume, - getInvidiousVolume, + setVolume, + getVolume, setInvidiousPlayerStyle, getInvidiousPlayerStyle, @@ -399,8 +396,8 @@ export default { setInvidiousSubtitles, getInvidiousSubtitles, - setInvidiousAutoplay, - getInvidiousAutoplay, + setAutoplay, + getAutoplay, getPersistInvidiousPrefs, setPersistInvidiousPrefs, diff --git a/src/pages/options/translate/translate.html b/src/pages/options/translate/translate.html index 3638086..72ea390 100644 --- a/src/pages/options/translate/translate.html +++ b/src/pages/options/translate/translate.html @@ -122,6 +122,237 @@