From d46c72fafb9e55ff84600e3c17f7a98cae995f2f Mon Sep 17 00:00:00 2001 From: Gres Date: Sun, 6 Dec 2020 22:40:03 +0300 Subject: [PATCH] Update google translation script Related to #37 --- translators/google.js | 7 ++++--- updates.json | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/translators/google.js b/translators/google.js index d203bcb..cb203cc 100644 --- a/translators/google.js +++ b/translators/google.js @@ -4,7 +4,7 @@ var active = window.location.href !== "about:blank"; function checkFinished() { if (!active) return; - let spans = [].slice.call(document.querySelectorAll('span.translation > span, #result_box > span')); + let spans = [].slice.call(document.querySelectorAll('span.VIiyi > span > span')); let text = spans.reduce(function (res, i) { return res + ' ' + i.innerText; }, ''); @@ -25,10 +25,11 @@ function translate(text, from, to) { if (window.location.href.indexOf('//translate.google') !== -1 && window.location.href.indexOf('&tl=' + to + '&') !== -1) { - document.querySelector('textarea#source').value = text; + document.querySelector('textarea.er8xn').value = text; + document.querySelector('textarea.er8xn').dispatchEvent( + new Event("input", { bubbles: true, cancelable: true })); 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=' + encodeURIComponent(text); console.log("setting url", url); window.location = url; diff --git a/updates.json b/updates.json index cf1a567..87524a4 100644 --- a/updates.json +++ b/updates.json @@ -585,7 +585,7 @@ {"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/deepl.js", "path":"$translators$/deepl.js", "md5":"a6dfae3f63ca3fa9c7edbfaff87600e4", "size":1596} ]} ,"google": {"files":[ - {"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google.js", "path":"$translators$/google.js", "md5":"16ffead93035e08e8db13279cc8b65a7", "size":1260} + {"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google.js", "path":"$translators$/google.js", "md5":"74f1064ba8f02c9c7be3821a4bdc557b", "size":1297} ]} ,"google_api": {"files":[ {"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google_api.js", "path":"$translators$/google_api.js", "md5":"90b9b1a5c8dc52fd4a3f28be93442a56", "size":1030}