From e3505563e3c1d323b17b68e1ea707a8de9142cce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <101191390+HIllya51@users.noreply.github.com> Date: Sat, 6 Apr 2024 18:26:34 +0800 Subject: [PATCH] fix --- .../LunaTranslator/translator/basetranslator_dev.py | 4 ++-- LunaTranslator/LunaTranslator/translator/dev_yandex.py | 9 +++++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/LunaTranslator/LunaTranslator/translator/basetranslator_dev.py b/LunaTranslator/LunaTranslator/translator/basetranslator_dev.py index 400acbad..afb1e08c 100644 --- a/LunaTranslator/LunaTranslator/translator/basetranslator_dev.py +++ b/LunaTranslator/LunaTranslator/translator/basetranslator_dev.py @@ -100,7 +100,7 @@ class basetransdev(basetrans): time.sleep(0.1) def send_keys(self, text): - self._SendRequest("Input.setIgnoreInputEvents", {"ignore": False}) + #self._SendRequest("Input.setIgnoreInputEvents", {"ignore": False}) try: self._SendRequest("Input.insertText", {"text": text}) except: @@ -127,4 +127,4 @@ class basetransdev(basetrans): ) # self._SendRequest('Input.dispatchKeyEvent', {'type': 'keyUp', 'modifiers': 0, 'timestamp': 0, 'text': '', 'unmodifiedText': '', 'keyIdentifier': '', 'code': f'Key{char.upper()}', 'key': char, 'windowsVirtualKeyCode': code, 'nativeVirtualKeyCode': code, 'autoRepeat': False, 'isKeypad': False, 'isSystemKey': False, 'location': 0}) - self._SendRequest("Input.setIgnoreInputEvents", {"ignore": True}) + #self._SendRequest("Input.setIgnoreInputEvents", {"ignore": True}) diff --git a/LunaTranslator/LunaTranslator/translator/dev_yandex.py b/LunaTranslator/LunaTranslator/translator/dev_yandex.py index 29bef544..4369544f 100644 --- a/LunaTranslator/LunaTranslator/translator/dev_yandex.py +++ b/LunaTranslator/LunaTranslator/translator/dev_yandex.py @@ -4,10 +4,15 @@ from translator.basetranslator_dev import basetransdev class TS(basetransdev): target_url = "https://translate.yandex.com/" + def inittranslator(self): + self.last = "" + def translate(self, content): self.Runtime_evaluate('document.querySelector("#fakeArea").innerText=""') self.Runtime_evaluate('document.querySelector("#fakeArea").click()') self.send_keys(content) - return self.wait_for_result( - 'document.querySelector("#translation > span").innerText' + last = self.wait_for_result( + 'document.querySelector("#translation > span").innerText', self.last ) + self.last = last + return self.last