Handle empty and same text translation
This commit is contained in:
parent
d46c72fafb
commit
75a04beffa
@ -20,14 +20,25 @@ function checkFinished() {
|
||||
|
||||
function translate(text, from, to) {
|
||||
console.log('start translate', text, from, to)
|
||||
|
||||
if (text.trim().length == 0) {
|
||||
proxy.setTranslated('');
|
||||
return;
|
||||
}
|
||||
|
||||
active = true;
|
||||
|
||||
let langs = from + '/' + to;
|
||||
if (window.location.href.indexOf('//fanyi.baidu.com/') !== -1
|
||||
&& window.location.href.indexOf(langs) !== -1) {
|
||||
document.querySelector('textarea#baidu_translate_input').value = text;
|
||||
document.querySelector('textarea#baidu_translate_input').dispatchEvent(
|
||||
new Event("input", { bubbles: true, cancelable: true }));
|
||||
var input = document.querySelector('textarea#baidu_translate_input');
|
||||
if (input.value == text) {
|
||||
console.log('using cached result');
|
||||
lastText = '';
|
||||
return;
|
||||
}
|
||||
input.value = text;
|
||||
input.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -20,13 +20,24 @@ function checkFinished() {
|
||||
|
||||
function translate(text, from, to) {
|
||||
console.log('start translate', text, from, to)
|
||||
|
||||
if (text.trim().length == 0) {
|
||||
proxy.setTranslated('');
|
||||
return;
|
||||
}
|
||||
|
||||
active = true;
|
||||
|
||||
if (window.location.href.indexOf('bing.com/translator') !== -1
|
||||
&& window.location.href.indexOf('&to=' + to + '&') !== -1) {
|
||||
document.querySelector('textarea#tta_input_ta').value = text;
|
||||
document.querySelector('textarea#tta_input_ta').dispatchEvent(
|
||||
new Event("input", { bubbles: true, cancelable: true }));
|
||||
var input = document.querySelector('textarea#tta_input_ta');
|
||||
if (input.value == text) {
|
||||
console.log('using cached result');
|
||||
lastText = '';
|
||||
return;
|
||||
}
|
||||
input.value = text;
|
||||
input.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,12 @@ function checkFinished() {
|
||||
|
||||
function translate(text, from, to) {
|
||||
console.log('start translate', text, from, to)
|
||||
|
||||
if (text.trim().length == 0) {
|
||||
proxy.setTranslated('');
|
||||
return;
|
||||
}
|
||||
|
||||
from = from == 'zh-CN' ? 'zh' : from;
|
||||
to = to == 'zh-CN' ? 'zh' : to;
|
||||
|
||||
@ -36,9 +42,14 @@ function translate(text, from, to) {
|
||||
let langs = from + '/' + to + '/';
|
||||
if (window.location.href.indexOf('www.deepl.com/translator') !== -1
|
||||
&& window.location.href.indexOf(langs) !== -1) {
|
||||
document.querySelector('textarea[dl-test=translator-source-input]').value = text;
|
||||
document.querySelector('textarea[dl-test=translator-source-input]').dispatchEvent(
|
||||
new Event("input", { bubbles: true, cancelable: true }));
|
||||
var input = document.querySelector('textarea[dl-test=translator-source-input]');
|
||||
if (input.value == text) {
|
||||
console.log('using cached result');
|
||||
lastText = '';
|
||||
return;
|
||||
}
|
||||
input.value = text;
|
||||
input.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -21,13 +21,24 @@ function checkFinished() {
|
||||
|
||||
function translate(text, from, to) {
|
||||
console.log('start translate', text, from, to)
|
||||
|
||||
if (text.trim().length == 0) {
|
||||
proxy.setTranslated('');
|
||||
return;
|
||||
}
|
||||
|
||||
active = true;
|
||||
|
||||
if (window.location.href.indexOf('//translate.google') !== -1
|
||||
&& window.location.href.indexOf('&tl=' + to + '&') !== -1) {
|
||||
document.querySelector('textarea.er8xn').value = text;
|
||||
document.querySelector('textarea.er8xn').dispatchEvent(
|
||||
new Event("input", { bubbles: true, cancelable: true }));
|
||||
var input = document.querySelector('textarea.er8xn');
|
||||
if (input.value == text) {
|
||||
console.log('using cached result');
|
||||
lastText = '';
|
||||
return;
|
||||
}
|
||||
input.value = text;
|
||||
input.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
|
||||
return;
|
||||
}
|
||||
let url = 'https://translate.google.com/#view=home&op=translate&sl=auto&tl=' + to + '&text=' + encodeURIComponent(text);
|
||||
|
@ -31,6 +31,12 @@ function checkFinished() {
|
||||
|
||||
function translate(text, from, to) {
|
||||
console.log('start translate', text, from, to)
|
||||
|
||||
if (text.trim().length == 0) {
|
||||
proxy.setTranslated('');
|
||||
return;
|
||||
}
|
||||
|
||||
let supported = ['ko', 'ru', 'en', 'fr', 'pt', 'th', 'ja',
|
||||
'zh-CN', 'zh-TW', 'de', 'it', 'id', 'es', 'vi', 'hi'];
|
||||
|
||||
@ -48,9 +54,14 @@ function translate(text, from, to) {
|
||||
let langs = '?sk=auto&tk=' + to + '&';
|
||||
if (window.location.href.indexOf('//papago.naver.com/') !== -1
|
||||
&& window.location.href.indexOf(langs) !== -1) {
|
||||
document.querySelector('textarea#txtSource').value = text
|
||||
document.querySelector('textarea#txtSource').dispatchEvent(
|
||||
new Event("input", { bubbles: true, cancelable: true }));
|
||||
var input = document.querySelector('textarea#txtSource');
|
||||
if (input.value == text) {
|
||||
console.log('using cached result');
|
||||
lastText = '';
|
||||
return;
|
||||
}
|
||||
input.value = text;
|
||||
input.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -20,10 +20,21 @@ function checkFinished() {
|
||||
|
||||
function translate(text, from, to) {
|
||||
console.log('start translate', text, from, to)
|
||||
|
||||
if (text.trim().length == 0) {
|
||||
proxy.setTranslated('');
|
||||
return;
|
||||
}
|
||||
|
||||
active = true;
|
||||
|
||||
let langs = 'lang=' + from + '-' + to;
|
||||
let url = 'https://translate.yandex.ru/?' + langs + '&text=' + encodeURIComponent(text);
|
||||
if (window.location.href == url) {
|
||||
console.log('using cached result');
|
||||
lastText = '';
|
||||
return;
|
||||
}
|
||||
console.log("setting url", url);
|
||||
window.location = url;
|
||||
}
|
||||
|
13
updates.json
13
updates.json
@ -576,26 +576,27 @@
|
||||
|
||||
,"translators":{
|
||||
"baidu": {"files":[
|
||||
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/baidu.js", "path":"$translators$/baidu.js", "md5":"93f7bca9b792877350f54a1d47767583", "size":1306}
|
||||
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/baidu.js", "path":"$translators$/baidu.js", "md5":"be3eb6d11fa5faebb046c887c9a8f3bd", "size":1501}
|
||||
]}
|
||||
,"bing": {"files":[
|
||||
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/bing.js", "path":"$translators$/bing.js", "md5":"5c20fe78c25a4f9e97160fdc3bc4572c", "size":1277}
|
||||
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/bing.js", "path":"$translators$/bing.js", "md5":"a982e9aa6cac598f4c9bf4a56386d13e", "size":1481}
|
||||
]}
|
||||
,"deepl": {"files":[
|
||||
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/deepl.js", "path":"$translators$/deepl.js", "md5":"a6dfae3f63ca3fa9c7edbfaff87600e4", "size":1596}
|
||||
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/deepl.js", "path":"$translators$/deepl.js", "md5":"fff5dba9840208cbb98fc85079014b0d", "size":1754}
|
||||
]}
|
||||
,"google": {"files":[
|
||||
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google.js", "path":"$translators$/google.js", "md5":"74f1064ba8f02c9c7be3821a4bdc557b", "size":1297}
|
||||
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google.js", "path":"$translators$/google.js", "md5":"1ceba6431d757fc2ae028a4ec177542c", "size":1508}
|
||||
]}
|
||||
,"google_api": {"files":[
|
||||
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google_api.js", "path":"$translators$/google_api.js", "md5":"90b9b1a5c8dc52fd4a3f28be93442a56", "size":1030}
|
||||
]}
|
||||
,"papago": {"files":[
|
||||
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/papago.js", "path":"$translators$/papago.js", "md5":"538bb7280192b18d15d24b07adae2638", "size":1956}
|
||||
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/papago.js", "path":"$translators$/papago.js", "md5":"603a56fc23990453942064ec53d1eaa3", "size":2164}
|
||||
]}
|
||||
,"yandex": {"files":[
|
||||
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/yandex.js", "path":"$translators$/yandex.js", "md5":"f8c625e8f6ced4a9f5be6791a6ee3f87", "size":957}
|
||||
{"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/yandex.js", "path":"$translators$/yandex.js", "md5":"6bc71c24270ca418b193f073e6155d5f", "size":1177}
|
||||
]}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user