Updated translator script.

This commit is contained in:
Gres 2017-07-21 20:24:53 +03:00
parent b11f3e9368
commit c6dc304627
2 changed files with 17 additions and 3 deletions

View File

@ -17,17 +17,31 @@ function checkFinished () {
function onResourceLoad (url) { function onResourceLoad (url) {
if (url.indexOf ('/translate_a/single') > -1) { if (url.indexOf ('/translate_a/single') > -1) {
isTranslationFinished = true; isTranslationFinished = true;
if (isPageLoaded) {
checkFinished (); 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;
if (isTranslationFinished) {
checkFinished (); checkFinished ();
} }
}
window.onload = onPageLoad(); window.onload = onPageLoad();
function translate (){ function translate (){
if (window.location.href.indexOf('https://translate.google') === 0) {
window.location = 'about:blank';
return;
}
var url = 'https://translate.google.com/#auto/' + var url = 'https://translate.google.com/#auto/' +
st_wtp.resultLanguage + '/' + st_wtp.sourceText; st_wtp.resultLanguage + '/' + st_wtp.sourceText;
window.location = encodeURI (url); window.location = encodeURI (url);

View File

@ -18,7 +18,7 @@
"path": "translators/bing.js" "path": "translators/bing.js"
}, },
"Google translator": { "Google translator": {
"version": 1, "version": 2,
"url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google.js", "url": "https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google.js",
"path": "translators/google.js" "path": "translators/google.js"
}, },