Updated bing translation

This commit is contained in:
Gres 2018-10-17 19:33:35 +03:00
parent 4109968fed
commit a69213c956
2 changed files with 15 additions and 6 deletions

View File

@ -6,9 +6,9 @@ function checkFinished () {
if (!isPageLoaded || !isTranslationFinished || isScheduled) return; if (!isPageLoaded || !isTranslationFinished || isScheduled) return;
isScheduled = true; isScheduled = true;
setTimeout(function () { 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) { var text = spans.reduce (function (res, i) {
return res + i.innerText; return res + i.value;
}, ''); }, '');
console.log (text); console.log (text);
st_wtp.translated (text); st_wtp.translated (text);
@ -16,15 +16,24 @@ function checkFinished () {
}, 2000); // wait for gui fill }, 2000); // wait for gui fill
} }
function onResourceLoad (url) { function onResourceLoad (url) {
if (url.indexOf ('/translator/api/Dictionary/Lookup?') > -1) { if (url.indexOf ('bing.com/translator/?') > -1) {
isTranslationFinished = true; isTranslationFinished = true;
checkFinished (); if (isPageLoaded) {
checkFinished ();
}
} }
} }
st_wtp.resourceLoaded.connect (onResourceLoad); st_wtp.resourceLoaded.connect (onResourceLoad);
function onPageLoad () { function onPageLoad () {
if (window.location.href.indexOf('about:blank') === 0) {
translate ();
return;
}
isPageLoaded = true; isPageLoaded = true;
checkFinished (); if (isTranslationFinished) {
checkFinished ();
}
} }
window.onload = onPageLoad(); window.onload = onPageLoad();

View File

@ -13,7 +13,7 @@
"path_linux": "ScreenTranslator" "path_linux": "ScreenTranslator"
}, },
"Bing translator": { "Bing translator": {
"version": 3, "version": 4,
"url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/bing.js", "url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/bing.js",
"path": "translators/bing.js" "path": "translators/bing.js"
}, },