diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 1dce07b..dd3c3a9 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -31,6 +31,10 @@ "message": "Search Engine Instance", "description": "Label for Search Engine instance field option (options)." }, + "simplyTranslateInstance": { + "message": "SimplyTranslate Instance", + "description": "Label for SimplyTranslate instance field option (options)." + }, "disableNitter": { "message": "Nitter Redirects", "description": "Label for enable/disable Nitter redirects option (options & pop-up)." @@ -55,6 +59,10 @@ "message": "Search Engine Redirects", "description": "Label for enable/disable Search Engine redirects option (options & pop-up)." }, + "disableSimplyTranslate": { + "message": "SimplyTranslate Redirects", + "description": "Label for enable/disable SimplyTranslate redirects option (options & pop-up)." + }, "alwaysProxy": { "message": "Always proxy videos through Invidious", "description": "Label for 'Always proxy videos through Invidious' option (options)." diff --git a/src/assets/javascripts/helpers/google-translate.js b/src/assets/javascripts/helpers/google-translate.js new file mode 100644 index 0000000..e6f450d --- /dev/null +++ b/src/assets/javascripts/helpers/google-translate.js @@ -0,0 +1,12 @@ +const targets = [ + "translate.google.com" +]; + +const redirects = [ + "https://translate.metalune.xyz" +]; + +export default { + targets, + redirects, +} diff --git a/src/pages/background/background.js b/src/pages/background/background.js index 9df083b..4199ab1 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -7,6 +7,7 @@ import instagramHelper from "../../assets/javascripts/helpers/instagram.js"; import mapsHelper from "../../assets/javascripts/helpers/google-maps.js"; import redditHelper from "../../assets/javascripts/helpers/reddit.js"; import searchHelper from "../../assets/javascripts/helpers/google-search.js"; +import googleTranslateHelper from "../../assets/javascripts/helpers/google-translate.js"; const nitterInstances = twitterHelper.redirects; const twitterDomains = twitterHelper.targets; @@ -29,6 +30,9 @@ const redditBypassPaths = redditHelper.bypassPaths; const redditDefault = redditHelper.redirects[0]; const googleSearchRegex = searchHelper.targets; const searchEngineInstances = searchHelper.redirects; +const simplyTranslateInstances = googleTranslateHelper.redirects; +const simplyTranslateDefault = simplyTranslateInstances[0]; +const googleTranslateDomains = googleTranslateHelper.targets; let disableNitter; let disableInvidious; @@ -36,12 +40,14 @@ let disableBibliogram; let disableOsm; let disableReddit; let disableSearchEngine; +let disableSimplyTranslate; let nitterInstance; let invidiousInstance; let bibliogramInstance; let osmInstance; let redditInstance; let searchEngineInstance; +let simplyTranslateInstance; let alwaysProxy; let onlyEmbeddedVideo; let videoQuality; @@ -66,12 +72,14 @@ browser.storage.sync.get( "osmInstance", "redditInstance", "searchEngineInstance", + "simplyTranslateInstance", "disableNitter", "disableInvidious", "disableBibliogram", "disableOsm", "disableReddit", "disableSearchEngine", + "disableSimplyTranslate", "alwaysProxy", "onlyEmbeddedVideo", "videoQuality", @@ -93,12 +101,14 @@ browser.storage.sync.get( osmInstance = result.osmInstance || osmDefault; redditInstance = result.redditInstance || redditDefault; searchEngineInstance = result.searchEngineInstance; + simplyTranslateInstance = result.simplyTranslateInstance || simplyTranslateDefault; disableNitter = result.disableNitter; disableInvidious = result.disableInvidious; disableBibliogram = result.disableBibliogram; disableOsm = result.disableOsm; disableReddit = result.disableReddit; disableSearchEngine = result.disableSearchEngine; + disableSimplyTranslate = result.disableSimplyTranslate; alwaysProxy = result.alwaysProxy; onlyEmbeddedVideo = result.onlyEmbeddedVideo; videoQuality = result.videoQuality; @@ -138,6 +148,9 @@ browser.storage.onChanged.addListener((changes) => { if ("osmInstance" in changes) { osmInstance = changes.osmInstance.newValue || osmDefault; } + if ("simplyTranslateInstance" in changes) { + simplyTranslateInstance = changes.simplyTranslateInstance.newValue || simplyTranslateDefault; + } if ("redditInstance" in changes) { redditInstance = changes.redditInstance.newValue || redditDefault; } @@ -162,6 +175,9 @@ browser.storage.onChanged.addListener((changes) => { if ("disableSearchEngine" in changes) { disableSearchEngine = changes.disableSearchEngine.newValue; } + if ("disableSimplyTranslate" in changes) { + disableSimplyTranslate = changes.disableSimplyTranslate.newValue; + } if ("alwaysProxy" in changes) { alwaysProxy = changes.alwaysProxy.newValue; } @@ -469,6 +485,14 @@ function redirectSearchEngine(url, initiator) { return `${searchEngine.link}${searchEngine.q}?${search}`; } +function redirectGoogleTranslate(url, initiator) { + if (disableSimplyTranslate || isException(url, initiator)) { + return null; + } + + return `${simplyTranslateInstance}/${url.search}`; +} + browser.webRequest.onBeforeRequest.addListener( (details) => { const url = new URL(details.url); @@ -506,6 +530,10 @@ browser.webRequest.onBeforeRequest.addListener( redirect = { redirectUrl: redirectSearchEngine(url, initiator), }; + } else if (googleTranslateDomains.includes(url.host)) { + redirect = { + redirectUrl: redirectGoogleTranslate(url, initiator), + } } if (redirect && redirect.redirectUrl) { console.info( diff --git a/src/pages/options/options.html b/src/pages/options/options.html index 8dc1eb7..27e9fe5 100644 --- a/src/pages/options/options.html +++ b/src/pages/options/options.html @@ -164,6 +164,25 @@ +
+ + + + + + + +
+

SimplyTranslate Redirects

+
+   + +
+

Nitter Instance

@@ -229,6 +248,16 @@ />
+
+

SimplyTranslate Instance

+
+ +
+

Theme

  + + + + + +
+