init
This commit is contained in:
commit
ae76837e41
8 files changed
+267
No files matched your search
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 535 B |
+63
@@ -0,0 +1,63 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>影刀 PY 助手</title>
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: Arial, sans-serif;
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
|
.switch {
|
||||||
|
position: relative;
|
||||||
|
display: inline-block;
|
||||||
|
width: 60px;
|
||||||
|
height: 34px;
|
||||||
|
}
|
||||||
|
.switch input {
|
||||||
|
opacity: 0;
|
||||||
|
width: 0;
|
||||||
|
height: 0;
|
||||||
|
}
|
||||||
|
.slider {
|
||||||
|
position: absolute;
|
||||||
|
cursor: pointer;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: #ccc;
|
||||||
|
transition: .4s;
|
||||||
|
}
|
||||||
|
.slider:before {
|
||||||
|
position: absolute;
|
||||||
|
content: "";
|
||||||
|
height: 26px;
|
||||||
|
width: 26px;
|
||||||
|
left: 4px;
|
||||||
|
bottom: 4px;
|
||||||
|
background-color: white;
|
||||||
|
transition: .4s;
|
||||||
|
}
|
||||||
|
input:checked + .slider {
|
||||||
|
background-color: #2196F3;
|
||||||
|
}
|
||||||
|
input:checked + .slider:before {
|
||||||
|
transform: translateX(26px);
|
||||||
|
}
|
||||||
|
.slider.round {
|
||||||
|
border-radius: 34px;
|
||||||
|
}
|
||||||
|
.slider.round:before {
|
||||||
|
border-radius: 50%;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<label class="switch">
|
||||||
|
<input type="checkbox" id="toggleCopyMode">
|
||||||
|
<span class="slider round"></span>
|
||||||
|
</label>
|
||||||
|
<p id="statusText">Copy mode is off</p>
|
||||||
|
<script src="scripts/popup.js"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"name": "Xbot PY Helper",
|
||||||
|
"description": "自动生成 网页自动化代码",
|
||||||
|
"version": "0.1.1",
|
||||||
|
"manifest_version": 3,
|
||||||
|
"permissions": [
|
||||||
|
"activeTab",
|
||||||
|
"scripting",
|
||||||
|
"clipboardWrite"
|
||||||
|
],
|
||||||
|
"background": {
|
||||||
|
"service_worker": "scripts/background.js"
|
||||||
|
},
|
||||||
|
"action": {
|
||||||
|
"default_popup": "index.html",
|
||||||
|
"default_icon": "images/yingdao-16x16.png"
|
||||||
|
},
|
||||||
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"matches": [
|
||||||
|
"<all_urls>"
|
||||||
|
],
|
||||||
|
"js": [
|
||||||
|
"scripts/content.js"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"web_accessible_resources": [
|
||||||
|
{
|
||||||
|
"resources": [
|
||||||
|
"scripts/popup.js"
|
||||||
|
],
|
||||||
|
"matches": [
|
||||||
|
"<all_urls>"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# 影刀YD助手
|
||||||
|
## 项目介绍
|
||||||
|
|
||||||
|
|
||||||
|
## 功能介绍
|
||||||
|
鼠标悬浮到元素上, 自动生成影刀代码
|
||||||
|
|
||||||
|
## 优化项目
|
||||||
|
|
||||||
|
1. 生成xpath的规则
|
||||||
|
2. 支持跨域
|
||||||
|
3. 支持开始和关闭拷贝模式
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
let isCopyModeEnabled = false;
|
||||||
|
|
||||||
|
chrome.action.onClicked.addListener(function (tab) {
|
||||||
|
chrome.scripting.executeScript({
|
||||||
|
target: { tabId: tab.id },
|
||||||
|
function: toggleCopyMode
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
||||||
|
if (request.action === 'toggleCopyMode') {
|
||||||
|
isCopyModeEnabled = !isCopyModeEnabled;
|
||||||
|
chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
||||||
|
chrome.tabs.sendMessage(tabs[0].id, { action: 'toggleCopyMode' }, function (response) {
|
||||||
|
sendResponse({ copyModeEnabled: isCopyModeEnabled });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return true; // Keep the message channel open for sendResponse
|
||||||
|
} else if (request.action === 'getCopyModeStatus') {
|
||||||
|
sendResponse({ copyModeEnabled: isCopyModeEnabled });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function toggleCopyMode() {
|
||||||
|
chrome.runtime.sendMessage({ action: 'toggleCopyMode' }, function (response) {
|
||||||
|
if (response.copyModeEnabled) {
|
||||||
|
console.log('Copy mode enabled');
|
||||||
|
} else {
|
||||||
|
console.log('Copy mode disabled');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
@@ -0,0 +1,102 @@
|
|||||||
|
(function () {
|
||||||
|
// 清除之前的高亮样式
|
||||||
|
let previousHighlight = null;
|
||||||
|
let copyButton = null;
|
||||||
|
let isCopyModeEnabled = false;
|
||||||
|
|
||||||
|
// 创建复制按钮
|
||||||
|
function createCopyButton() {
|
||||||
|
const button = document.createElement('button');
|
||||||
|
button.innerHTML = '📋'; // 使用图标展示拷贝
|
||||||
|
button.style.position = 'absolute';
|
||||||
|
button.style.zIndex = '1000';
|
||||||
|
button.style.display = 'none';
|
||||||
|
button.style.background = 'transparent';
|
||||||
|
button.style.border = 'none';
|
||||||
|
button.style.cursor = 'pointer';
|
||||||
|
button.style.fontSize = '16px';
|
||||||
|
button.addEventListener('click', function () {
|
||||||
|
if (previousHighlight) {
|
||||||
|
const xpath = getElementXPath(previousHighlight);
|
||||||
|
const action = previousHighlight.tagName.toLowerCase() === 'input' ? 'input("your_text")' : 'click()';
|
||||||
|
const command = `web.find_by_xpath("${xpath}").${action}`;
|
||||||
|
navigator.clipboard.writeText(command).then(() => {
|
||||||
|
console.log('Command copied to clipboard:', command);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
document.body.appendChild(button);
|
||||||
|
return button;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取元素的 XPath
|
||||||
|
function getElementXPath(element) {
|
||||||
|
let path = [];
|
||||||
|
while (element) {
|
||||||
|
let index = 1;
|
||||||
|
let sibling = element.previousElementSibling;
|
||||||
|
while (sibling) {
|
||||||
|
if (sibling.nodeName === element.nodeName) {
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
sibling = sibling.previousElementSibling;
|
||||||
|
}
|
||||||
|
path.unshift(`${element.nodeName.toLowerCase()}[${index}]`);
|
||||||
|
element = element.parentNode;
|
||||||
|
}
|
||||||
|
return path.length ? '/' + path.join('/') : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 监听鼠标移动事件
|
||||||
|
document.addEventListener('mousemove', function (event) {
|
||||||
|
if (!isCopyModeEnabled) return;
|
||||||
|
|
||||||
|
// 移除上一次高亮
|
||||||
|
if (previousHighlight) {
|
||||||
|
previousHighlight.style.border = '';
|
||||||
|
previousHighlight.style.borderRadius = '';
|
||||||
|
previousHighlight.style.boxShadow = '';
|
||||||
|
copyButton.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 获取鼠标位置
|
||||||
|
const mouseX = event.clientX;
|
||||||
|
const mouseY = event.clientY;
|
||||||
|
|
||||||
|
// 获取鼠标下的元素
|
||||||
|
const element = document.elementFromPoint(mouseX, mouseY);
|
||||||
|
|
||||||
|
// 如果有元素,添加高亮样式并输出对应的 XPath
|
||||||
|
if (element && element !== document.body) {
|
||||||
|
previousHighlight = element;
|
||||||
|
element.style.border = '2px solid red';
|
||||||
|
element.style.borderRadius = '5px';
|
||||||
|
|
||||||
|
// 设置复制按钮位置并显示
|
||||||
|
const rect = element.getBoundingClientRect();
|
||||||
|
copyButton.style.left = `${rect.right + window.scrollX - 20}px`;
|
||||||
|
copyButton.style.top = `${rect.top + window.scrollY}px`;
|
||||||
|
copyButton.style.display = 'block';
|
||||||
|
|
||||||
|
// 输出 XPath
|
||||||
|
const xpath = getElementXPath(element);
|
||||||
|
console.log('Element XPath:', xpath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// 监听消息以启用或禁用拷贝模式
|
||||||
|
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
|
||||||
|
if (request.action === 'toggleCopyMode') {
|
||||||
|
isCopyModeEnabled = !isCopyModeEnabled;
|
||||||
|
if (!isCopyModeEnabled && previousHighlight) {
|
||||||
|
previousHighlight.style.border = '';
|
||||||
|
previousHighlight.style.borderRadius = '';
|
||||||
|
previousHighlight.style.boxShadow = '';
|
||||||
|
copyButton.style.display = 'none';
|
||||||
|
}
|
||||||
|
sendResponse({ copyModeEnabled: isCopyModeEnabled });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
copyButton = createCopyButton();
|
||||||
|
})();
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
const toggleSwitch = document.getElementById('toggleCopyMode');
|
||||||
|
const statusText = document.getElementById('statusText');
|
||||||
|
|
||||||
|
toggleSwitch.addEventListener('change', function () {
|
||||||
|
chrome.runtime.sendMessage({ action: 'toggleCopyMode' }, function (response) {
|
||||||
|
if (response.copyModeEnabled) {
|
||||||
|
statusText.textContent = 'Copy mode enabled';
|
||||||
|
} else {
|
||||||
|
statusText.textContent = 'Copy mode disabled';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Initialize switch state based on current mode
|
||||||
|
chrome.runtime.sendMessage({ action: 'getCopyModeStatus' }, function (response) {
|
||||||
|
toggleSwitch.checked = response.copyModeEnabled;
|
||||||
|
statusText.textContent = response.copyModeEnabled ? 'Copy mode enabled' : 'Copy mode disabled';
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in new issue
Block a user