This commit is contained in:
恍兮惚兮 2024-12-04 21:07:36 +08:00
parent 9a21a91714
commit 8cd51aa49c
2 changed files with 10 additions and 14 deletions

View File

@ -65,9 +65,13 @@ class Commonloadchromium:
class cdp_helper: class cdp_helper:
target_url = None target_url = None
@property
def config(self):
return self.ref.config
@property @property
def using(self): def using(self):
return True return self.ref.using
def check_url_is_translator_url(self, url: str): def check_url_is_translator_url(self, url: str):
return url.startswith(self.target_url) return url.startswith(self.target_url)
@ -100,7 +104,7 @@ class cdp_helper:
def __init__(self, ref: basetrans) -> None: def __init__(self, ref: basetrans) -> None:
self.ref = ref self.ref = ref
cdp_helper.commonloadchromium.maybeload(self.ref.config) cdp_helper.commonloadchromium.maybeload(self.config)
self._id = 1 self._id = 1
self.sendrecvlock = threading.Lock() self.sendrecvlock = threading.Lock()
self._createtarget() self._createtarget()
@ -119,7 +123,7 @@ class cdp_helper:
) )
res = ws.recv() res = ws.recv()
except requests.RequestException: except requests.RequestException:
cdp_helper.commonloadchromium.maybeload(self.ref.config) cdp_helper.commonloadchromium.maybeload(self.config)
raise Exception(_TR("连接失败")) raise Exception(_TR("连接失败"))
res = json.loads(res) res = json.loads(res)
@ -132,7 +136,7 @@ class cdp_helper:
def _createtarget(self): def _createtarget(self):
if self.using == False: if self.using == False:
return return
port = self.ref.config["debugport"] port = self.config["debugport"]
url = self.target_url url = self.target_url
try: try:
infos = requests.get("http://127.0.0.1:{}/json/list".format(port)).json() infos = requests.get("http://127.0.0.1:{}/json/list".format(port)).json()
@ -257,14 +261,6 @@ class cdp_helperllm(cdp_helper):
function1 = ... function1 = ...
function2 = ... function2 = ...
@property
def config(self):
return self.ref.config
@property
def using(self):
return self.ref.using
def injectjs(self): def injectjs(self):
with open( with open(
os.path.join(os.path.dirname(__file__), self.jsfile), os.path.join(os.path.dirname(__file__), self.jsfile),
@ -304,7 +300,7 @@ class cdp_helperllm(cdp_helper):
self.Runtime_evaluate( self.Runtime_evaluate(
"document.querySelector({}).click()".format(repr(self.button_selector)) "document.querySelector({}).click()".format(repr(self.button_selector))
) )
if self.ref.config["usingstream"]: if self.config["usingstream"]:
__ = [""] __ = [""]
def ___(__): def ___(__):

View File

@ -60,7 +60,7 @@ class cdp_deepl(cdp_helper):
@property @property
def using(self): def using(self):
return self.ref.using and self.ref.config["usewhich"] == 2 return self.ref.using and self.config["usewhich"] == 2
@property @property
def srclang(self): def srclang(self):