This commit is contained in:
恍兮惚兮 2024-04-06 18:26:34 +08:00
parent c95fa10b88
commit e3505563e3
2 changed files with 9 additions and 4 deletions

View File

@ -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})

View File

@ -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