mirror of
https://github.com/NaiboWang/EasySpider.git
synced 2025-04-05 00:38:51 +08:00
New way to show/hide toolkits
This commit is contained in:
parent
33dda444d7
commit
2feede55db
@ -2194,6 +2194,7 @@ if __name__ == '__main__':
|
||||
"pause_key": "p", # 暂停键
|
||||
"version": "0.6.3",
|
||||
"docker_driver": "",
|
||||
"user_folder": "",
|
||||
}
|
||||
c = Config(config)
|
||||
print(c)
|
||||
@ -2289,35 +2290,43 @@ if __name__ == '__main__':
|
||||
os.mkdir(tmp_user_folder_parent)
|
||||
characters = string.ascii_letters + string.digits
|
||||
for i in range(len(c.ids)):
|
||||
id = c.ids[i]
|
||||
# 从字符集中随机选择字符构成字符串
|
||||
random_string = ''.join(random.choice(characters) for i in range(10))
|
||||
tmp_user_data_folder = os.path.join(tmp_user_folder_parent, "user_data_" + str(id) + "_" + str(time.time()).replace(".","") + "_" + random_string)
|
||||
tmp_options[i]["tmp_user_data_folder"] = tmp_user_data_folder
|
||||
if os.path.exists(tmp_user_data_folder):
|
||||
try:
|
||||
shutil.rmtree(tmp_user_data_folder)
|
||||
except:
|
||||
pass
|
||||
print(f"Copying user data folder to: {tmp_user_data_folder}, please wait...")
|
||||
print(f"正在复制用户信息目录到: {tmp_user_data_folder},请稍等...")
|
||||
if os.path.exists(absolute_user_data_folder):
|
||||
try:
|
||||
shutil.copytree(absolute_user_data_folder, tmp_user_data_folder)
|
||||
print("User data folder copied successfully, if you exit the program before it finishes, please delete the temporary user data folder manually.")
|
||||
print("用户信息目录复制成功,如果程序在运行过程中被手动退出,请手动删除临时用户信息目录。")
|
||||
except:
|
||||
tmp_user_data_folder = absolute_user_data_folder
|
||||
print("Copy user data folder failed, use the original folder.")
|
||||
print("复制用户信息目录失败,使用原始目录。")
|
||||
else:
|
||||
tmp_user_data_folder = absolute_user_data_folder
|
||||
print("Cannot find user data folder, create a new folder.")
|
||||
print("未找到用户信息目录,创建新目录。")
|
||||
options = tmp_options[i]["options"]
|
||||
options.add_argument(
|
||||
f'--user-data-dir={tmp_user_data_folder}') # TMALL 反扒
|
||||
options.add_argument("--profile-directory=Default")
|
||||
if c.user_folder == "":
|
||||
id = c.ids[i]
|
||||
# 从字符集中随机选择字符构成字符串
|
||||
random_string = ''.join(random.choice(characters) for i in range(10))
|
||||
tmp_user_data_folder = os.path.join(tmp_user_folder_parent, "user_data_" + str(id) + "_" + str(time.time()).replace(".","") + "_" + random_string)
|
||||
tmp_options[i]["tmp_user_data_folder"] = tmp_user_data_folder
|
||||
if os.path.exists(tmp_user_data_folder):
|
||||
try:
|
||||
shutil.rmtree(tmp_user_data_folder)
|
||||
except:
|
||||
pass
|
||||
print(f"Copying user data folder to: {tmp_user_data_folder}, please wait...")
|
||||
print(f"正在复制用户信息目录到: {tmp_user_data_folder},请稍等...")
|
||||
if os.path.exists(absolute_user_data_folder):
|
||||
try:
|
||||
shutil.copytree(absolute_user_data_folder, tmp_user_data_folder)
|
||||
print("User data folder copied successfully, if you exit the program before it finishes, please delete the temporary user data folder manually.")
|
||||
print("用户信息目录复制成功,如果程序在运行过程中被手动退出,请手动删除临时用户信息目录。")
|
||||
except:
|
||||
tmp_user_data_folder = absolute_user_data_folder
|
||||
print("Copy user data folder failed, use the original folder.")
|
||||
print("复制用户信息目录失败,使用原始目录。")
|
||||
else:
|
||||
tmp_user_data_folder = absolute_user_data_folder
|
||||
print("Cannot find user data folder, create a new folder.")
|
||||
print("未找到用户信息目录,创建新目录。")
|
||||
options.add_argument(
|
||||
f'--user-data-dir={tmp_user_data_folder}') # TMALL 反扒
|
||||
print(f"Use local user data folder: {tmp_user_data_folder}")
|
||||
print(f"使用本地用户信息目录: {tmp_user_data_folder}")
|
||||
else:
|
||||
options.add_argument(
|
||||
f'--user-data-dir={c.user_folder}')
|
||||
print(f"Use specifed user data folder: {c.user_folder}", ", please note if you are using docker, this user folder path should be the path inside the docker container.")
|
||||
print(f"使用指定的用户信息目录: {c.user_folder}", ",请注意如果您正在使用docker,此用户文件夹路径应是容器内的路径。")
|
||||
print(
|
||||
"如果报错Selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally,说明有之前运行的Chrome实例没有正常关闭,请关闭之前打开的所有Chrome实例后再运行程序即可。")
|
||||
print(
|
||||
|
BIN
ElectronJS/EasySpider_en.crx
Normal file
BIN
ElectronJS/EasySpider_en.crx
Normal file
Binary file not shown.
BIN
ElectronJS/EasySpider_zh.crx
Normal file
BIN
ElectronJS/EasySpider_zh.crx
Normal file
Binary file not shown.
@ -114,6 +114,7 @@ let handle_pairs = {};
|
||||
let socket_window = null;
|
||||
let socket_start = null;
|
||||
let socket_flowchart = null;
|
||||
let socket_popup = null;
|
||||
let invoke_window = null;
|
||||
|
||||
// var ffi = require('ffi-napi');
|
||||
@ -1124,6 +1125,20 @@ async function beginInvoke(msg, ws) {
|
||||
} catch {
|
||||
console.log("Cannot get Cookies");
|
||||
}
|
||||
} else if (msg.type == 30) {
|
||||
send_message_to_browser(
|
||||
JSON.stringify({
|
||||
type: "showAllToolboxes"
|
||||
})
|
||||
);
|
||||
console.log("Show all toolboxes");
|
||||
} else if (msg.type == 31) {
|
||||
send_message_to_browser(
|
||||
JSON.stringify({
|
||||
type: "hideAllToolboxes"
|
||||
})
|
||||
);
|
||||
console.log("Hide all toolboxes");
|
||||
}
|
||||
}
|
||||
|
||||
@ -1267,6 +1282,9 @@ wss.on("connection", function (ws) {
|
||||
// console.log("socket_flowchart closed");
|
||||
// });
|
||||
console.log("set socket_flowchart at time: ", new Date());
|
||||
} else if (msg.message.id == 3) {
|
||||
socket_popup = ws;
|
||||
console.log("set socket_popup at time: ", new Date());
|
||||
} else {
|
||||
//其他的ID是用来标识不同的浏览器标签页的
|
||||
// await new Promise(resolve => setTimeout(resolve, 200));
|
||||
|
@ -27,6 +27,10 @@ global.ws.onmessage = function (evt) {
|
||||
clearEl();
|
||||
} else if (evt["type"] == "trial") {
|
||||
trial(evt);
|
||||
} else if (evt["type"] == "showAllToolboxes") {
|
||||
document.getElementById("wrapperToolkit").style.display = "block";
|
||||
} else if (evt["type"] == "hideAllToolboxes") {
|
||||
document.getElementById("wrapperToolkit").style.display = "none";
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
import config from './content-scripts/config.json';
|
||||
import {global} from "./content-scripts/global.js";
|
||||
|
||||
if (config.language == 'zh') {
|
||||
document.getElementById('title').innerText = '可执行操作';
|
||||
@ -10,15 +11,39 @@ if (config.language == 'zh') {
|
||||
document.getElementById('close-toolkit').innerText = 'Hide EasySpider Toolkit';
|
||||
}
|
||||
|
||||
var ws = new WebSocket("ws://localhost:8084");
|
||||
ws.onopen = function () {
|
||||
// Web Socket 已连接上,使用 send() 方法发送数据
|
||||
console.log("已连接");
|
||||
let message = {
|
||||
type: 0, //消息类型,0代表连接操作
|
||||
message: {
|
||||
id: 3, //socket id
|
||||
title: document.title, //网页标题
|
||||
}
|
||||
};
|
||||
this.send(JSON.stringify(message));
|
||||
};
|
||||
|
||||
document.getElementById('show-toolkit').addEventListener('click', async () => {
|
||||
try {
|
||||
// 发送消息给 content script
|
||||
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
|
||||
const [tab] = await chrome.tabs.query({active: true, currentWindow: true});
|
||||
chrome.scripting.executeScript({
|
||||
target: { tabId: tab.id },
|
||||
target: {tabId: tab.id},
|
||||
func: showToolkit
|
||||
});
|
||||
let message_action = {
|
||||
type: 30, //消息类型,30代表显示所有操作台
|
||||
from: 3, //3代表popup
|
||||
message: {}
|
||||
};
|
||||
window.close();
|
||||
try {
|
||||
ws.send(JSON.stringify(message_action));
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error showing toolkit:', error);
|
||||
}
|
||||
@ -27,12 +52,22 @@ document.getElementById('show-toolkit').addEventListener('click', async () => {
|
||||
document.getElementById('close-toolkit').addEventListener('click', async () => {
|
||||
try {
|
||||
// 发送消息给 content script
|
||||
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
|
||||
const [tab] = await chrome.tabs.query({active: true, currentWindow: true});
|
||||
chrome.scripting.executeScript({
|
||||
target: { tabId: tab.id },
|
||||
target: {tabId: tab.id},
|
||||
func: closeToolkit
|
||||
});
|
||||
let message_action = {
|
||||
type: 31, //消息类型,30代表隐藏所有操作台
|
||||
from: 3, //3代表popup
|
||||
message: {}
|
||||
};
|
||||
window.close();
|
||||
try {
|
||||
ws.send(JSON.stringify(message_action));
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error closing toolkit:', error);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user