From a69213c9561352476b7454260c5fd93434d9b00a Mon Sep 17 00:00:00 2001 From: Gres Date: Wed, 17 Oct 2018 19:33:35 +0300 Subject: [PATCH] Updated bing translation --- translators/bing.js | 19 ++++++++++++++----- version.json | 2 +- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/translators/bing.js b/translators/bing.js index f78f6a5..e3aa36e 100644 --- a/translators/bing.js +++ b/translators/bing.js @@ -6,9 +6,9 @@ function checkFinished () { if (!isPageLoaded || !isTranslationFinished || isScheduled) return; isScheduled = true; setTimeout(function () { - var spans = [].slice.call (document.querySelectorAll ('#destText span')); + var spans = [].slice.call (document.querySelectorAll ('#t_txtoutblk textarea')); var text = spans.reduce (function (res, i) { - return res + i.innerText; + return res + i.value; }, ''); console.log (text); st_wtp.translated (text); @@ -16,15 +16,24 @@ function checkFinished () { }, 2000); // wait for gui fill } function onResourceLoad (url) { - if (url.indexOf ('/translator/api/Dictionary/Lookup?') > -1) { + if (url.indexOf ('bing.com/translator/?') > -1) { isTranslationFinished = true; - checkFinished (); + if (isPageLoaded) { + checkFinished (); + } } } st_wtp.resourceLoaded.connect (onResourceLoad); function onPageLoad () { + if (window.location.href.indexOf('about:blank') === 0) { + translate (); + return; + } + isPageLoaded = true; - checkFinished (); + if (isTranslationFinished) { + checkFinished (); + } } window.onload = onPageLoad(); diff --git a/version.json b/version.json index bf7b195..e366a39 100644 --- a/version.json +++ b/version.json @@ -13,7 +13,7 @@ "path_linux": "ScreenTranslator" }, "Bing translator": { - "version": 3, + "version": 4, "url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/bing.js", "path": "translators/bing.js" },