Updated translators.

This commit is contained in:
Gres 2017-05-27 12:33:43 +03:00
parent d1f930ff57
commit a84e2fa72a
3 changed files with 16 additions and 11 deletions

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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"
}