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 @@
+
+
+

From

+ +
+ +
+

To

+ +
+
+

Default Instances

diff --git a/src/pages/options/translate/translate.js b/src/pages/options/translate/translate.js index a28d321..4db8007 100644 --- a/src/pages/options/translate/translate.js +++ b/src/pages/options/translate/translate.js @@ -1,22 +1,24 @@ import translateHelper from "../../../assets/javascripts/helpers/translate.js"; import commonHelper from "../../../assets/javascripts/helpers/common.js"; -let disableTranslateElement = document.getElementById("disable-simplyTranslate"); -disableTranslateElement.addEventListener("change", - (event) => translateHelper.setDisableTranslate(!event.target.checked) +let disableElement = document.getElementById("disable-simplyTranslate"); +disableElement.addEventListener("change", + (event) => translateHelper.setDisable(!event.target.checked) ); - +let simplyTranslateLingvaDivElement = document.getElementById("simplyTranslate-lingva") let simplyTranslateDivElement = document.getElementById("simplyTranslate") let lingvaDivElement = document.getElementById("lingva") function changeFrontendsSettings(frontend) { if (frontend == 'simplyTranslate') { + simplyTranslateLingvaDivElement.style.display = 'block'; simplyTranslateDivElement.style.display = 'block'; lingvaDivElement.style.display = 'none'; } else if (frontend == 'lingva') { + simplyTranslateLingvaDivElement.style.display = 'block'; simplyTranslateDivElement.style.display = 'none'; lingvaDivElement.style.display = 'block'; } @@ -30,11 +32,29 @@ translateFrontendElement.addEventListener("change", } ); +let fromElement = document.getElementById("from"); +fromElement.addEventListener("change", + (event) => { + let from = event.target.options[fromElement.selectedIndex].value; + translateHelper.setFrom(from); + } +); + +let toElement = document.getElementById("to"); +toElement.addEventListener("change", + (event) => { + let to = event.target.options[toElement.selectedIndex].value; + translateHelper.setTo(to); + } +); + translateHelper.init().then(() => { - disableTranslateElement.checked = !translateHelper.getDisableTranslate(); + disableElement.checked = !translateHelper.getDisable(); let frontend = translateHelper.getFrontend(); translateFrontendElement.value = frontend; changeFrontendsSettings(frontend); + fromElement.value = translateHelper.getFrom(); + toElement.value = translateHelper.getTo(); commonHelper.processDefaultCustomInstances( 'simplyTranslate', diff --git a/src/pages/options/youtube/youtube.js b/src/pages/options/youtube/youtube.js index 2983119..097ba09 100644 --- a/src/pages/options/youtube/youtube.js +++ b/src/pages/options/youtube/youtube.js @@ -36,31 +36,31 @@ disableYoutubeElement.addEventListener("change", (event) => youtubeHelper.setDisableYoutube(!event.target.checked) ); -let invidiousThemeElement = document.getElementById("invidious-theme"); -invidiousThemeElement.addEventListener("change", - (event) => youtubeHelper.setInvidiousTheme(event.target.options[invidiousThemeElement.selectedIndex].value) +let themeElement = document.getElementById("invidious-theme"); +themeElement.addEventListener("change", + (event) => youtubeHelper.setTheme(event.target.options[themeElement.selectedIndex].value) ); -let invidiousVolumeElement = document.getElementById("invidious-volume"); -let invidiousVolumeValueElement = document.querySelector("#volume-value"); -invidiousVolumeElement.addEventListener("input", +let volumeElement = document.getElementById("invidious-volume"); +let volumeValueElement = document.querySelector("#volume-value"); +volumeElement.addEventListener("input", () => { - youtubeHelper.setInvidiousVolume(invidiousVolumeElement.value); - invidiousVolumeValueElement.textContent = `${invidiousVolumeElement.value}%`; + youtubeHelper.setVolume(volumeElement.value); + volumeValueElement.textContent = `${volumeElement.value}%`; } ); let invidiousClearVolumeElement = document.getElementById("clear-invidious-volume"); invidiousClearVolumeElement.addEventListener("click", (_) => { - youtubeHelper.setInvidiousVolume('--'); - invidiousVolumeValueElement.textContent = `--%`; - invidiousVolumeElement.value = 50; + youtubeHelper.setVolume('--'); + volumeValueElement.textContent = `--%`; + volumeElement.value = 50; } ); -let invidiousAutoplayElement = document.getElementById("invidious-autoplay"); -invidiousAutoplayElement.addEventListener("change", - (event) => youtubeHelper.setInvidiousAutoplay(event.target.options[invidiousAutoplayElement.selectedIndex].value) +let autoplayElement = document.getElementById("invidious-autoplay"); +autoplayElement.addEventListener("change", + (event) => youtubeHelper.setAutoplay(event.target.options[autoplayElement.selectedIndex].value) ); let OnlyEmbeddedVideoElement = document.getElementById("only-embed"); @@ -75,12 +75,12 @@ alwaysUsePreferredElement.addEventListener("change", youtubeHelper.init().then(() => { disableYoutubeElement.checked = !youtubeHelper.getDisableYoutube(); - invidiousThemeElement.checked = youtubeHelper.getInvidiousTheme(); - invidiousVolumeElement.value = youtubeHelper.getInvidiousVolume(); - invidiousVolumeValueElement.textContent = `${youtubeHelper.getInvidiousVolume()}%`; + themeElement.checked = youtubeHelper.getTheme(); + volumeElement.value = youtubeHelper.getVolume(); + volumeValueElement.textContent = `${youtubeHelper.getVolume()}%`; OnlyEmbeddedVideoElement.value = youtubeHelper.getOnlyEmbeddedVideo(); alwaysUsePreferredElement.checked = youtubeHelper.getAlwaysusePreferred(); - invidiousAutoplayElement.checked = youtubeHelper.getInvidiousAutoplay(); + autoplayElement.checked = youtubeHelper.getAutoplay(); let frontend = youtubeHelper.getFrontend(); youtubeFrontendElement.value = frontend; changeFrontendsSettings(frontend); diff --git a/src/pages/popup/popup.js b/src/pages/popup/popup.js index fb46d96..5ae42b9 100644 --- a/src/pages/popup/popup.js +++ b/src/pages/popup/popup.js @@ -20,7 +20,7 @@ let disableInstagramElement = document.querySelector("#disable-bibliogram"); let disableMapsElement = document.querySelector("#disable-osm"); let disableRedditElement = document.querySelector("#disable-reddit"); let disableSearchElement = document.querySelector("#disable-search"); -let disableTranslateElement = document.querySelector("#disable-simplyTranslate"); +let disableElement = document.querySelector("#disable-simplyTranslate"); let disableWikipediaElement = document.querySelector("#disable-wikipedia"); let disableMediumElement = document.querySelector("#disable-medium"); let disableImgurElement = document.querySelector("#disable-imgur"); @@ -47,7 +47,7 @@ wholeInit().then(() => { disableMapsElement.checked = !mapsHelper.getDisableMaps(); disableRedditElement.checked = !redditHelper.getDisableReddit(); disableSearchElement.checked = !searchHelper.getDisableSearch(); - disableTranslateElement.checked = !translateHelper.getDisableTranslate(); + disableElement.checked = !translateHelper.getDisable(); disableWikipediaElement.checked = !wikipediaHelper.getDisableWikipedia(); disableImgurElement.checked = !imgurHelper.getDisableImgur(); disableTiktokElement.checked = !tiktokHelper.getDisableTiktok(); @@ -78,8 +78,8 @@ disableSearchElement.addEventListener("change", (event) => searchHelper.setDisableSearch(!event.target.checked) ); -disableTranslateElement.addEventListener("change", - (event) => translateHelper.setDisableTranslate(!event.target.checked) +disableElement.addEventListener("change", + (event) => translateHelper.setDisable(!event.target.checked) ); disableWikipediaElement.addEventListener("change",