From c54eabe850cf2a43230c70992ccbd07cc7c9de86 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: Thu, 7 Mar 2024 16:51:26 +0800 Subject: [PATCH] poe Update dev_poe.py --- .../LunaTranslator/translator/dev_poe.py | 23 +++++++++++-------- .../defaultconfig/translatorsetting.json | 10 ++++++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/LunaTranslator/LunaTranslator/translator/dev_poe.py b/LunaTranslator/LunaTranslator/translator/dev_poe.py index c66ede8d..1ce10158 100644 --- a/LunaTranslator/LunaTranslator/translator/dev_poe.py +++ b/LunaTranslator/LunaTranslator/translator/dev_poe.py @@ -8,7 +8,8 @@ class TS(basetransdev): target_url='https://poe.com/' def inittranslator(self): list(self.translate('Please help me translate the following text into: '+self.tgtlang)) - + def langmap(self): + return {'zh': 'Simplified Chinese', 'ja': 'Japanese', 'en': 'English', 'ru': 'Russian', 'es': 'Spanish', 'ko': 'Korean', 'fr': 'French', 'cht': 'Traditional Chinese', 'vi': 'Vietnamese', 'tr': 'Turkish', 'pl': 'Polish', 'uk': 'Ukrainian', 'it': 'Italian', 'ar': 'Arabic', 'th': 'Thai'} def translate(self,content): try: self.num=self.Runtime_evaluate('''document.querySelector("#__next > div > div.AnnouncementWrapper_container__Z51yh > div.SidebarLayout_layoutWrapper__mPYi4.SidebarLayout_layoutWrapperOverflow__0hyZ4 > main > div > div > div > div.InfiniteScroll_container__PHsd4.ChatMessagesView_infiniteScroll__vk3VX").children.length''')['result']['value'] @@ -20,16 +21,18 @@ class TS(basetransdev): self.send_keys(content) self.Runtime_evaluate('''document.querySelector("#__next > div > div.AnnouncementWrapper_container__Z51yh > div.SidebarLayout_layoutWrapper__mPYi4.SidebarLayout_layoutWrapperOverflow__0hyZ4 > main > div > div > div > div.ChatHomeMain_container__l4uRf > div.ChatHomeMain_inputContainer__9mgRh > div > button.Button_buttonBase__Bv9Vx.Button_primary__6UIn0.ChatMessageSendButton_sendButton__4ZyI4.ChatMessageInputContainer_sendButton__dBjTt").click()''') self.Runtime_evaluate('''document.querySelector("#__next > div > div.AnnouncementWrapper_container__Z51yh > div.SidebarLayout_layoutWrapper__mPYi4.SidebarLayout_layoutWrapperOverflow__0hyZ4 > main > div > div > div > footer > div > div > button.Button_buttonBase__Bv9Vx.Button_primary__6UIn0.ChatMessageSendButton_sendButton__4ZyI4.ChatMessageInputContainer_sendButton__dBjTt").click()''') - if 0: + if self.config['流式输出']==False: self.wait_for_result('''document.querySelector("#__next > div > div.AnnouncementWrapper_container__Z51yh > div.SidebarLayout_layoutWrapper__mPYi4.SidebarLayout_layoutWrapperOverflow__0hyZ4 > main > div > div > div > div.InfiniteScroll_container__PHsd4.ChatMessagesView_infiniteScroll__vk3VX > div:nth-child({}) > section.ChatMessageActionBar_actionBar__gyeEs").innerHTML'''.format(self.num+1)) yield self.wait_for_result('''document.querySelector("#__next > div > div.AnnouncementWrapper_container__Z51yh > div.SidebarLayout_layoutWrapper__mPYi4.SidebarLayout_layoutWrapperOverflow__0hyZ4 > main > div > div > div > div.InfiniteScroll_container__PHsd4.ChatMessagesView_infiniteScroll__vk3VX > div:nth-child({}) > div:nth-child(2) > div.ChatMessage_messageRow__DHlnq").textContent'''.format(self.num+1)) - currtext='' - while True: - newcurr=self.wait_for_result('''document.querySelector("#__next > div > div.AnnouncementWrapper_container__Z51yh > div.SidebarLayout_layoutWrapper__mPYi4.SidebarLayout_layoutWrapperOverflow__0hyZ4 > main > div > div > div > div.InfiniteScroll_container__PHsd4.ChatMessagesView_infiniteScroll__vk3VX > div:nth-child({}) > div:nth-child(2) > div.ChatMessage_messageRow__DHlnq").textContent'''.format(self.num+1)) - yield newcurr[len(currtext):] - currtext=newcurr - time.sleep(0.3) - if (self.Runtime_evaluate('''document.querySelector("#__next > div > div.AnnouncementWrapper_container__Z51yh > div.SidebarLayout_layoutWrapper__mPYi4.SidebarLayout_layoutWrapperOverflow__0hyZ4 > main > div > div > div > div.InfiniteScroll_container__PHsd4.ChatMessagesView_infiniteScroll__vk3VX > div:nth-child({}) > section.ChatMessageActionBar_actionBar__gyeEs")'''.format(self.num+1)))['result']['subtype']=='node': + else: + currtext='' + while True: + time.sleep(0.1) newcurr=self.wait_for_result('''document.querySelector("#__next > div > div.AnnouncementWrapper_container__Z51yh > div.SidebarLayout_layoutWrapper__mPYi4.SidebarLayout_layoutWrapperOverflow__0hyZ4 > main > div > div > div > div.InfiniteScroll_container__PHsd4.ChatMessagesView_infiniteScroll__vk3VX > div:nth-child({}) > div:nth-child(2) > div.ChatMessage_messageRow__DHlnq").textContent'''.format(self.num+1)) + if newcurr=='...':continue yield newcurr[len(currtext):] - break \ No newline at end of file + currtext=newcurr + if (self.Runtime_evaluate('''document.querySelector("#__next > div > div.AnnouncementWrapper_container__Z51yh > div.SidebarLayout_layoutWrapper__mPYi4.SidebarLayout_layoutWrapperOverflow__0hyZ4 > main > div > div > div > div.InfiniteScroll_container__PHsd4.ChatMessagesView_infiniteScroll__vk3VX > div:nth-child({}) > section.ChatMessageActionBar_actionBar__gyeEs")'''.format(self.num+1)))['result']['subtype']=='node': + newcurr=self.wait_for_result('''document.querySelector("#__next > div > div.AnnouncementWrapper_container__Z51yh > div.SidebarLayout_layoutWrapper__mPYi4.SidebarLayout_layoutWrapperOverflow__0hyZ4 > main > div > div > div > div.InfiniteScroll_container__PHsd4.ChatMessagesView_infiniteScroll__vk3VX > div:nth-child({}) > div:nth-child(2) > div.ChatMessage_messageRow__DHlnq").textContent'''.format(self.num+1)) + yield newcurr[len(currtext):] + break \ No newline at end of file diff --git a/LunaTranslator/files/defaultconfig/translatorsetting.json b/LunaTranslator/files/defaultconfig/translatorsetting.json index b97a2968..6b983a10 100644 --- a/LunaTranslator/files/defaultconfig/translatorsetting.json +++ b/LunaTranslator/files/defaultconfig/translatorsetting.json @@ -4,6 +4,16 @@ "host": "translate.plausibility.cloud" } }, + "dev_poe":{ + "args":{ + "流式输出":false + }, + "argstype":{ + "流式输出":{ + "type": "switch" + } + } + }, "baiduapi": { "args": { "注册网址": "https://fanyi-api.baidu.com/api/trans/product/desktop",