From 8cd51aa49c5ff37b639a01427cd4c2e57e59cd01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=81=8D=E5=85=AE=E6=83=9A=E5=85=AE?= <1173718158@qq.com> Date: Wed, 4 Dec 2024 21:07:36 +0800 Subject: [PATCH] . --- py/LunaTranslator/translator/cdp_helper.py | 22 +++++++++------------- py/LunaTranslator/translator/deepl.py | 2 +- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/py/LunaTranslator/translator/cdp_helper.py b/py/LunaTranslator/translator/cdp_helper.py index ace486c8..09fdc087 100644 --- a/py/LunaTranslator/translator/cdp_helper.py +++ b/py/LunaTranslator/translator/cdp_helper.py @@ -65,9 +65,13 @@ class Commonloadchromium: class cdp_helper: target_url = None + @property + def config(self): + return self.ref.config + @property def using(self): - return True + return self.ref.using def check_url_is_translator_url(self, url: str): return url.startswith(self.target_url) @@ -100,7 +104,7 @@ class cdp_helper: def __init__(self, ref: basetrans) -> None: self.ref = ref - cdp_helper.commonloadchromium.maybeload(self.ref.config) + cdp_helper.commonloadchromium.maybeload(self.config) self._id = 1 self.sendrecvlock = threading.Lock() self._createtarget() @@ -119,7 +123,7 @@ class cdp_helper: ) res = ws.recv() except requests.RequestException: - cdp_helper.commonloadchromium.maybeload(self.ref.config) + cdp_helper.commonloadchromium.maybeload(self.config) raise Exception(_TR("连接失败")) res = json.loads(res) @@ -132,7 +136,7 @@ class cdp_helper: def _createtarget(self): if self.using == False: return - port = self.ref.config["debugport"] + port = self.config["debugport"] url = self.target_url try: infos = requests.get("http://127.0.0.1:{}/json/list".format(port)).json() @@ -257,14 +261,6 @@ class cdp_helperllm(cdp_helper): function1 = ... function2 = ... - @property - def config(self): - return self.ref.config - - @property - def using(self): - return self.ref.using - def injectjs(self): with open( os.path.join(os.path.dirname(__file__), self.jsfile), @@ -304,7 +300,7 @@ class cdp_helperllm(cdp_helper): self.Runtime_evaluate( "document.querySelector({}).click()".format(repr(self.button_selector)) ) - if self.ref.config["usingstream"]: + if self.config["usingstream"]: __ = [""] def ___(__): diff --git a/py/LunaTranslator/translator/deepl.py b/py/LunaTranslator/translator/deepl.py index 1236f8b1..3ab1d7f7 100644 --- a/py/LunaTranslator/translator/deepl.py +++ b/py/LunaTranslator/translator/deepl.py @@ -60,7 +60,7 @@ class cdp_deepl(cdp_helper): @property def using(self): - return self.ref.using and self.ref.config["usewhich"] == 2 + return self.ref.using and self.config["usewhich"] == 2 @property def srclang(self):