diff --git a/translators/bing.js b/translators/bing.js index 2fa19c1..23998b2 100644 --- a/translators/bing.js +++ b/translators/bing.js @@ -6,15 +6,16 @@ function checkFinished () { if (!isPageLoaded || !isTranslationFinished || isScheduled) return; isScheduled = true; setTimeout(function () { - var spans = [].slice.call (document.querySelectorAll ('#OutputText span')); + var spans = [].slice.call (document.querySelectorAll ('#destText span')); var text = spans.reduce (function (res, i) { return res + i.innerText; }, ''); st_wtp.translated (text); + isTranslationFinished = isScheduled = false; }, 2000); // wait for gui fill } function onResourceLoad (url) { - if (url.indexOf ('/api.microsofttranslator.com/') > -1) { + if (url.indexOf ('/translator/api/Dictionary/Lookup?') > -1) { isTranslationFinished = true; checkFinished (); } @@ -27,7 +28,7 @@ function onPageLoad () { window.onload = onPageLoad(); function translate (){ - var url = 'https://bing.com/translator/?text=' + st_wtp.sourceText + '#auto/' + - st_wtp.resultLanguage; + var url = 'https://bing.com/translator/?from=auto&to=' + st_wtp.resultLanguage + + '&text=' + st_wtp.sourceText; window.location = encodeURI (url); } diff --git a/translators/yandex.js b/translators/yandex.js index 7686593..5c8a084 100644 --- a/translators/yandex.js +++ b/translators/yandex.js @@ -6,14 +6,19 @@ function checkFinished () { if (!isPageLoaded || !isTranslationFinished || isScheduled) return; isScheduled = true; setTimeout(function () { - var spans = [].slice.call (document.querySelectorAll ('#translation > span')); + var spans = [].slice.call (document.querySelectorAll ('span.translation-chunk')); var text = spans.reduce (function (res, i) { - return res + i.innerText; + return res + i.innerText + ' '; }, ''); st_wtp.translated (text); + isTranslationFinished = isScheduled = false; }, 2000); // wait for gui fill } function onResourceLoad (url) { + if (url.indexOf ('/tr.json/translate?') > -1) { + isTranslationFinished = true; + checkFinished (); + } } st_wtp.resourceLoaded.connect (onResourceLoad); function onPageLoad () { @@ -23,9 +28,8 @@ function onPageLoad () { window.onload = onPageLoad(); function translate (){ - var url = 'https://translate.yandex.ru/?text=' + st_wtp.sourceText + '&lang=auto-' + - st_wtp.resultLanguage; + var url = 'https://translate.yandex.ru/&lang=' + st_wtp.sourceLanguage + '-' + + st_wtp.resultLanguage + '?text=' + st_wtp.sourceText ; url = url.replace(new RegExp(' ','g') , '%20') - console.log(encodeURI(url)); window.location = (url); } diff --git a/version.json b/version.json index cccede6..d6f4158 100644 --- a/version.json +++ b/version.json @@ -14,7 +14,7 @@ "path_linux": "ScreenTranslator" }, "Bing translator": { - "version": 1, + "version": 2, "url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/bing.js", "path": "translators/bing.js" }, @@ -24,7 +24,7 @@ "path": "translators/google.js" }, "Yandex translator": { - "version": 1, + "version": 2, "url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/yandex.js", "path": "translators/yandex.js" }