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) {
 | 
					function translate(text, from, to) {
 | 
				
			||||||
    console.log('start translate', text, from, to)
 | 
					    console.log('start translate', text, from, to)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (text.trim().length == 0) {
 | 
				
			||||||
 | 
					        proxy.setTranslated('');
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    active = true;
 | 
					    active = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let langs = from + '/' + to;
 | 
					    let langs = from + '/' + to;
 | 
				
			||||||
    if (window.location.href.indexOf('//fanyi.baidu.com/') !== -1
 | 
					    if (window.location.href.indexOf('//fanyi.baidu.com/') !== -1
 | 
				
			||||||
        && window.location.href.indexOf(langs) !== -1) {
 | 
					        && window.location.href.indexOf(langs) !== -1) {
 | 
				
			||||||
        document.querySelector('textarea#baidu_translate_input').value = text;
 | 
					        var input = document.querySelector('textarea#baidu_translate_input');
 | 
				
			||||||
        document.querySelector('textarea#baidu_translate_input').dispatchEvent(
 | 
					        if (input.value == text) {
 | 
				
			||||||
            new Event("input", { bubbles: true, cancelable: true }));
 | 
					            console.log('using cached result');
 | 
				
			||||||
 | 
					            lastText = '';
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        input.value = text;
 | 
				
			||||||
 | 
					        input.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -20,13 +20,24 @@ function checkFinished() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function translate(text, from, to) {
 | 
					function translate(text, from, to) {
 | 
				
			||||||
    console.log('start translate', text, from, to)
 | 
					    console.log('start translate', text, from, to)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (text.trim().length == 0) {
 | 
				
			||||||
 | 
					        proxy.setTranslated('');
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    active = true;
 | 
					    active = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (window.location.href.indexOf('bing.com/translator') !== -1
 | 
					    if (window.location.href.indexOf('bing.com/translator') !== -1
 | 
				
			||||||
        && window.location.href.indexOf('&to=' + to + '&') !== -1) {
 | 
					        && window.location.href.indexOf('&to=' + to + '&') !== -1) {
 | 
				
			||||||
        document.querySelector('textarea#tta_input_ta').value = text;
 | 
					        var input = document.querySelector('textarea#tta_input_ta');
 | 
				
			||||||
        document.querySelector('textarea#tta_input_ta').dispatchEvent(
 | 
					        if (input.value == text) {
 | 
				
			||||||
            new Event("input", { bubbles: true, cancelable: true }));
 | 
					            console.log('using cached result');
 | 
				
			||||||
 | 
					            lastText = '';
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        input.value = text;
 | 
				
			||||||
 | 
					        input.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -18,6 +18,12 @@ function checkFinished() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function translate(text, from, to) {
 | 
					function translate(text, from, to) {
 | 
				
			||||||
  console.log('start 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;
 | 
					  from = from == 'zh-CN' ? 'zh' : from;
 | 
				
			||||||
  to = to == 'zh-CN' ? 'zh' : to;
 | 
					  to = to == 'zh-CN' ? 'zh' : to;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -36,9 +42,14 @@ function translate(text, from, to) {
 | 
				
			|||||||
  let langs = from + '/' + to + '/';
 | 
					  let langs = from + '/' + to + '/';
 | 
				
			||||||
  if (window.location.href.indexOf('www.deepl.com/translator') !== -1
 | 
					  if (window.location.href.indexOf('www.deepl.com/translator') !== -1
 | 
				
			||||||
    && window.location.href.indexOf(langs) !== -1) {
 | 
					    && window.location.href.indexOf(langs) !== -1) {
 | 
				
			||||||
    document.querySelector('textarea[dl-test=translator-source-input]').value = text;
 | 
					    var input = document.querySelector('textarea[dl-test=translator-source-input]');
 | 
				
			||||||
    document.querySelector('textarea[dl-test=translator-source-input]').dispatchEvent(
 | 
					    if (input.value == text) {
 | 
				
			||||||
      new Event("input", { bubbles: true, cancelable: true }));
 | 
					        console.log('using cached result');
 | 
				
			||||||
 | 
					        lastText = '';
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    input.value = text;
 | 
				
			||||||
 | 
					    input.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -21,13 +21,24 @@ function checkFinished() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function translate(text, from, to) {
 | 
					function translate(text, from, to) {
 | 
				
			||||||
    console.log('start translate', text, from, to)
 | 
					    console.log('start translate', text, from, to)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (text.trim().length == 0) {
 | 
				
			||||||
 | 
					        proxy.setTranslated('');
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    active = true;
 | 
					    active = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (window.location.href.indexOf('//translate.google') !== -1
 | 
					    if (window.location.href.indexOf('//translate.google') !== -1
 | 
				
			||||||
        && window.location.href.indexOf('&tl=' + to + '&') !== -1) {
 | 
					        && window.location.href.indexOf('&tl=' + to + '&') !== -1) {
 | 
				
			||||||
        document.querySelector('textarea.er8xn').value = text;
 | 
					        var input = document.querySelector('textarea.er8xn');
 | 
				
			||||||
        document.querySelector('textarea.er8xn').dispatchEvent(
 | 
					        if (input.value == text) {
 | 
				
			||||||
            new Event("input", { bubbles: true, cancelable: true }));
 | 
					            console.log('using cached result');
 | 
				
			||||||
 | 
					            lastText = '';
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        input.value = text;
 | 
				
			||||||
 | 
					        input.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    let url = 'https://translate.google.com/#view=home&op=translate&sl=auto&tl=' + to + '&text=' + encodeURIComponent(text);
 | 
					    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) {
 | 
					function translate(text, from, to) {
 | 
				
			||||||
    console.log('start 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',
 | 
					    let supported = ['ko', 'ru', 'en', 'fr', 'pt', 'th', 'ja',
 | 
				
			||||||
        'zh-CN', 'zh-TW', 'de', 'it', 'id', 'es', 'vi', 'hi'];
 | 
					        '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 + '&';
 | 
					    let langs = '?sk=auto&tk=' + to + '&';
 | 
				
			||||||
    if (window.location.href.indexOf('//papago.naver.com/') !== -1
 | 
					    if (window.location.href.indexOf('//papago.naver.com/') !== -1
 | 
				
			||||||
        && window.location.href.indexOf(langs) !== -1) {
 | 
					        && window.location.href.indexOf(langs) !== -1) {
 | 
				
			||||||
        document.querySelector('textarea#txtSource').value = text
 | 
					        var input = document.querySelector('textarea#txtSource');
 | 
				
			||||||
        document.querySelector('textarea#txtSource').dispatchEvent(
 | 
					        if (input.value == text) {
 | 
				
			||||||
            new Event("input", { bubbles: true, cancelable: true }));
 | 
					            console.log('using cached result');
 | 
				
			||||||
 | 
					            lastText = '';
 | 
				
			||||||
 | 
					            return;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        input.value = text;
 | 
				
			||||||
 | 
					        input.dispatchEvent(new Event("input", { bubbles: true, cancelable: true }));
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -20,10 +20,21 @@ function checkFinished() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
function translate(text, from, to) {
 | 
					function translate(text, from, to) {
 | 
				
			||||||
    console.log('start translate', text, from, to)
 | 
					    console.log('start translate', text, from, to)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if (text.trim().length == 0) {
 | 
				
			||||||
 | 
					        proxy.setTranslated('');
 | 
				
			||||||
 | 
					        return;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    active = true;
 | 
					    active = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    let langs = 'lang=' + from + '-' + to;
 | 
					    let langs = 'lang=' + from + '-' + to;
 | 
				
			||||||
    let url = 'https://translate.yandex.ru/?' + langs + '&text=' + encodeURIComponent(text);
 | 
					    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);
 | 
					    console.log("setting url", url);
 | 
				
			||||||
    window.location = url;
 | 
					    window.location = url;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										13
									
								
								updates.json
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								updates.json
									
									
									
									
									
								
							@ -576,26 +576,27 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
,"translators":{
 | 
					,"translators":{
 | 
				
			||||||
 "baidu": {"files":[
 | 
					 "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":[
 | 
					 ,"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":[
 | 
					 ,"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":[
 | 
					 ,"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":[
 | 
					 ,"google_api": {"files":[
 | 
				
			||||||
  {"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google_api.js", "path":"$translators$/google_api.js", "md5":"90b9b1a5c8dc52fd4a3f28be93442a56", "size":1030}
 | 
					  {"url":"https://raw.githubusercontent.com/OneMoreGres/ScreenTranslator/master/translators/google_api.js", "path":"$translators$/google_api.js", "md5":"90b9b1a5c8dc52fd4a3f28be93442a56", "size":1030}
 | 
				
			||||||
 ]}
 | 
					 ]}
 | 
				
			||||||
 ,"papago": {"files":[
 | 
					 ,"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":[
 | 
					 ,"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