Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 12 additions & 29 deletions chrome_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -2550,7 +2550,7 @@ def batch_open_urls(self):
return

# 确保 URL 格式正确
if not url.startswith(('http://', 'https://')):
if not url.startswith(('http://', 'https://', 'chrome-extension://', 'chrome://')):
url = 'https://' + url

# 获取选中的窗口
Expand Down Expand Up @@ -4793,7 +4793,7 @@ def browse_file():
text="开始输入",
command=lambda: self.execute_text_input(
dialog,
file_path_var.get(),
preview,
input_method.get(),
overwrite_var.get(),
False # 永远不使用延迟输入
Expand All @@ -4802,23 +4802,23 @@ def browse_file():
width=10
).pack(side=tk.RIGHT, padx=5)

def execute_text_input(self, dialog, file_path, input_method, overwrite, delayed):
def execute_text_input(self, dialog, preview, input_method, overwrite, delayed):
"""执行文本输入操作"""
if not file_path:
messagebox.showwarning("警告", "请选择文本文件!")
return

if not os.path.exists(file_path):
messagebox.showerror("错误", "文件不存在!")

# 从预览区获取内容
preview_content = preview.get('1.0', tk.END).strip()
if not preview_content:
messagebox.showwarning("警告", "预览区内容为空!")
return

lines = [line for line in preview_content.splitlines() if line.strip()]

# 关闭对话框
dialog.destroy()

# 调用文本输入功能
self.input_text_from_file(file_path, input_method, overwrite, delayed)
self.input_text_from_preview(lines, input_method, overwrite, delayed)

def input_text_from_file(self, file_path, input_method, overwrite, delayed):
def input_text_from_preview(self, lines, input_method, overwrite, delayed):
"""从文件输入文本到选中的窗口"""
try:
# 获取选中的窗口
Expand All @@ -4832,23 +4832,6 @@ def input_text_from_file(self, file_path, input_method, overwrite, delayed):
messagebox.showwarning("警告", "请先选择要操作的窗口!")
return

# 读取文本文件
try:
with open(file_path, 'r', encoding='utf-8') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
except UnicodeDecodeError:
# 尝试其它编码
try:
with open(file_path, 'r', encoding='gbk') as f:
lines = [line.strip() for line in f.readlines() if line.strip()]
except Exception as e:
messagebox.showerror("错误", f"读取文件失败: {str(e)}")
return

if not lines:
messagebox.showwarning("警告", "文本文件为空!")
return

# 准备文本行
if input_method == "random":
# 为每个窗口随机选择一行
Expand Down