From ca99f570f7a78b039376ab788d2aa9f09ebe56a9 Mon Sep 17 00:00:00 2001 From: Gres Date: Fri, 3 Apr 2020 18:38:59 +0300 Subject: [PATCH] Change url escaping --- translators/bing.js | 4 ++-- translators/deepl.js | 5 ++--- translators/google.js | 4 ++-- translators/google_api.js | 2 +- translators/papago.js | 3 +-- translators/yandex.js | 3 +-- 6 files changed, 9 insertions(+), 12 deletions(-) diff --git a/translators/bing.js b/translators/bing.js index 6e714a9..1eb4117 100644 --- a/translators/bing.js +++ b/translators/bing.js @@ -30,9 +30,9 @@ function translate(text, from, to) { return; } - let url = 'https://www.bing.com/translator/?from=auto&to=' + to + '&text=' + text; + let url = 'https://www.bing.com/translator/?from=auto&to=' + to + '&text=' + encodeURIComponent(text); console.log("setting url", url); - window.location = encodeURI(url); + window.location = url; } diff --git a/translators/deepl.js b/translators/deepl.js index 41da8cd..a72d83b 100644 --- a/translators/deepl.js +++ b/translators/deepl.js @@ -42,10 +42,9 @@ function translate(text, from, to) { return; } - let url = 'https://www.deepl.com/translator#' + langs + - text.replace('\n', ' ').replace('|', ''); + let url = 'https://www.deepl.com/translator#' + langs + encodeURIComponent(text); console.log("setting url", url); - window.location = encodeURI(url); + window.location = url; } function init() { diff --git a/translators/google.js b/translators/google.js index 9b0f318..d203bcb 100644 --- a/translators/google.js +++ b/translators/google.js @@ -29,9 +29,9 @@ function translate(text, from, to) { return; } // let url = 'https://translate.google.com/#auto/' + to + '/' + text; - let url = 'https://translate.google.com/#view=home&op=translate&sl=auto&tl=' + to + '&text=' + text; + let url = 'https://translate.google.com/#view=home&op=translate&sl=auto&tl=' + to + '&text=' + encodeURIComponent(text); console.log("setting url", url); - window.location = encodeURI(url); + window.location = url; } diff --git a/translators/google_api.js b/translators/google_api.js index 34d8fc8..09c80f9 100644 --- a/translators/google_api.js +++ b/translators/google_api.js @@ -11,7 +11,7 @@ function httpGetAsync(url, callback) { function translate(text, from, to) { console.log('start translate', text, from, to) - let url = 'https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=' + to + '&dt=t&q=' + text; + let url = 'https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=' + to + '&dt=t&q=' + encodeURIComponent(text); console.log("loading url", url); httpGetAsync(url, function (response) { diff --git a/translators/papago.js b/translators/papago.js index cf0ca9c..2374ee7 100644 --- a/translators/papago.js +++ b/translators/papago.js @@ -54,8 +54,7 @@ function translate(text, from, to) { return; } - let url = 'https://papago.naver.com/?sk=auto&tk=' + to + '&st=' + - text.replace("\n", " "); + let url = 'https://papago.naver.com/?sk=auto&tk=' + to + '&st=' + encodeURIComponent(text); window.location = encodeURI(url); } diff --git a/translators/yandex.js b/translators/yandex.js index 3722daf..2a1b107 100644 --- a/translators/yandex.js +++ b/translators/yandex.js @@ -32,8 +32,7 @@ function translate(text, from, to) { return; } - let url = 'https://translate.yandex.ru/?' + langs + '&text=' + text; - url = url.replace(new RegExp(' ', 'g'), '%20') + let url = 'https://translate.yandex.ru/?' + langs + '&text=' + encodeURIComponent(text); console.log("setting url", url); window.location = url; }