2015-10-10 03:33:49 +07:00
|
|
|
var isPageLoaded = false;
|
|
|
|
var isTranslationFinished = false; // async translation request
|
|
|
|
var isScheduled = false;
|
|
|
|
|
|
|
|
function checkFinished () {
|
|
|
|
if (!isPageLoaded || !isTranslationFinished || isScheduled) return;
|
|
|
|
isScheduled = true;
|
|
|
|
setTimeout(function () {
|
2020-03-24 00:50:17 +07:00
|
|
|
var text = document.querySelector ('#tta_output_ta').value;
|
2017-08-30 23:28:17 +07:00
|
|
|
console.log (text);
|
2015-10-10 03:33:49 +07:00
|
|
|
st_wtp.translated (text);
|
2017-05-27 16:33:43 +07:00
|
|
|
isTranslationFinished = isScheduled = false;
|
2015-11-07 01:13:18 +07:00
|
|
|
}, 2000); // wait for gui fill
|
2015-10-10 03:33:49 +07:00
|
|
|
}
|
|
|
|
function onResourceLoad (url) {
|
2018-10-17 23:33:35 +07:00
|
|
|
if (url.indexOf ('bing.com/translator/?') > -1) {
|
2015-10-10 03:33:49 +07:00
|
|
|
isTranslationFinished = true;
|
2018-10-17 23:33:35 +07:00
|
|
|
if (isPageLoaded) {
|
|
|
|
checkFinished ();
|
|
|
|
}
|
2015-10-10 03:33:49 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
st_wtp.resourceLoaded.connect (onResourceLoad);
|
|
|
|
function onPageLoad () {
|
2018-10-17 23:33:35 +07:00
|
|
|
if (window.location.href.indexOf('about:blank') === 0) {
|
|
|
|
translate ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-10-10 03:33:49 +07:00
|
|
|
isPageLoaded = true;
|
2018-10-17 23:33:35 +07:00
|
|
|
if (isTranslationFinished) {
|
|
|
|
checkFinished ();
|
|
|
|
}
|
2015-10-10 03:33:49 +07:00
|
|
|
}
|
|
|
|
window.onload = onPageLoad();
|
|
|
|
|
|
|
|
function translate (){
|
2017-05-27 16:33:43 +07:00
|
|
|
var url = 'https://bing.com/translator/?from=auto&to=' + st_wtp.resultLanguage +
|
|
|
|
'&text=' + st_wtp.sourceText;
|
2015-10-10 03:33:49 +07:00
|
|
|
window.location = encodeURI (url);
|
|
|
|
}
|