diff --git a/LunaTranslator/LunaTranslator/translator/dev_poe.py b/LunaTranslator/LunaTranslator/translator/dev_poe.py index 1ce10158..f02b9b67 100644 --- a/LunaTranslator/LunaTranslator/translator/dev_poe.py +++ b/LunaTranslator/LunaTranslator/translator/dev_poe.py @@ -7,7 +7,7 @@ import time class TS(basetransdev): target_url='https://poe.com/' def inittranslator(self): - list(self.translate('Please help me translate the following text into: '+self.tgtlang)) + list(self.translate('Please help me translate the following {} text into {}'.format(self.srclang,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): diff --git a/LunaTranslator/LunaTranslator/translator/dev_theb.py b/LunaTranslator/LunaTranslator/translator/dev_theb.py new file mode 100644 index 00000000..4ee9e8a7 --- /dev/null +++ b/LunaTranslator/LunaTranslator/translator/dev_theb.py @@ -0,0 +1,40 @@ + + +import json +from translator.basetranslator_dev import basetransdev +import time + +class TS(basetransdev): + target_url='https://beta.theb.ai/' + 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("#html2canvas").children.length''')['result']['value'] + if self.num==1: + self.num=0 + except: + self.num=2 + print(self.num) + self.Runtime_evaluate('''document.querySelector("#textareaAutosize").click()''') + content='Please help me translate the following {} text into {}, and you should only tell me the translation.'.format(self.srclang,self.tgtlang)+'\n'+content + self.send_keys(content) + self.Runtime_evaluate(r'''document.querySelector("#INPUT > div.md\\:bg-white.md\\:dark\\:bg-n-6 > div.max-w-\\[66rem\\].m-auto.relative.z-2.border-2.border-n-3.rounded-xl.overflow-hidden.dark\\:border-n-5.bg-white.dark\\:bg-n-6 > div > button.group.absolute.right-3.bottom-2.rounded-xl.transition-colors.disabled\\:bg-slate-400.disabled\\:hover\\:bg-slate-400.disabled\\:cursor-no-drop.w-10.h-10.bg-primary-1.hover\\:bg-primary-1\\/90").click()''') + if self.config['流式输出']==False: + while 1: + time.sleep(0.1) + if 'stop' not in self.wait_for_result(r'''document.querySelector("#INPUT > div.md\\:bg-white.md\\:dark\\:bg-n-6 > div.flex.justify-center.relative > button").innerText''').lower(): + break + yield self.wait_for_result('''document.querySelector("#html2canvas > div:nth-child({}) > div.markdown.overflow-x-auto.prose").textContent'''.format(self.num+2)) + else: + currtext='' + while True: + time.sleep(0.1) + newcurr=self.wait_for_result('''document.querySelector("#html2canvas > div:nth-child({}) > div.markdown.overflow-x-auto.prose").textContent'''.format(self.num+2)) + if newcurr=='...':continue + yield newcurr[len(currtext):] + currtext=newcurr + if 'stop' not in self.wait_for_result(r'''document.querySelector("#INPUT > div.md\\:bg-white.md\\:dark\\:bg-n-6 > div.flex.justify-center.relative > button").innerText''').lower(): + newcurr=self.wait_for_result('''document.querySelector("#html2canvas > div:nth-child({}) > div.markdown.overflow-x-auto.prose").textContent'''.format(self.num+2)) + yield newcurr[len(currtext):] + break \ No newline at end of file diff --git a/LunaTranslator/files/defaultconfig/config.json b/LunaTranslator/files/defaultconfig/config.json index cd2319d6..ddc242db 100644 --- a/LunaTranslator/files/defaultconfig/config.json +++ b/LunaTranslator/files/defaultconfig/config.json @@ -1157,6 +1157,12 @@ "type": "offline", "color": "blue", "name": "TGW语言模型" + }, + "dev_theb": { + "use": false, + "type": "dev", + "color": "blue", + "name": "beta.theb.ai" } }, "magpie10path":"", diff --git a/LunaTranslator/files/defaultconfig/translatorsetting.json b/LunaTranslator/files/defaultconfig/translatorsetting.json index 6b983a10..b8c067a7 100644 --- a/LunaTranslator/files/defaultconfig/translatorsetting.json +++ b/LunaTranslator/files/defaultconfig/translatorsetting.json @@ -14,6 +14,16 @@ } } }, + "dev_theb":{ + "args":{ + "流式输出":false + }, + "argstype":{ + "流式输出":{ + "type": "switch" + } + } + }, "baiduapi": { "args": { "注册网址": "https://fanyi-api.baidu.com/api/trans/product/desktop",