[in]失败后停止【值/表达式】True
[in]操作类型【值/表达式】ExecuteScript
[in]窗口标识【值/表达式】壁纸
[in]JS脚本【值/表达式】try {\r\n
// 创建容器\r\n
const container = document.createElement('div');\r\n
container.id = 'floating-buttons-container';\r\n
container.style.cssText = `\r\n
position: fixed;\r\n
right: 30px;\r\n
bottom: 30px;\r\n
display: flex;\r\n
flex-direction: column;\r\n
gap: 3px;\r\n
z-index: 9999;\r\n
cursor: move;\r\n
`;\r\n
\r\n
// 按钮配置\r\n
const buttons = [\r\n
{ text: '设为壁纸', subprogram: '设置为壁纸', input: `{赋值数据A}` },\r\n
{ text: '下载图片', subprogram: '下载图片', input: `{赋值数据B}` },\r\n
{ text: '打开文件', subprogram: '打开文件夹', input: `{赋值数据C}` }\r\n
];\r\n
\r\n
// 拖动相关变量\r\n
let isDragging = false;\r\n
let offsetX, offsetY;\r\n
let startX, startY;\r\n
\r\n
// 循环创建按钮\r\n
buttons.forEach(config => {\r\n
const button = document.createElement('button');\r\n
button.textContent = config.text;\r\n
button.style.cssText = `\r\n
padding: 6px 12px;\r\n
background: linear-gradient(135deg, #4285f4, #3367d6);\r\n
color: white;\r\n
border: none;\r\n
border-radius: 3px;\r\n
box-shadow: 0 2px 4px rgba(66, 133, 244, 0.3);\r\n
cursor: pointer;\r\n
font-size: 14px;\r\n
font-weight: 500;\r\n
white-space: nowrap;\r\n
transition: all 0.2s ease;\r\n
`;\r\n
\r\n
// 点击事件\r\n
button.addEventListener('click', async (e) => {\r\n
// 阻止事件冒泡到容器,避免触发拖动\r\n
e.stopPropagation();\r\n
\r\n
try {\r\n
button.textContent = `${config.text}中...`;\r\n
\r\n
if (typeof $quicker === 'undefined') {\r\n
throw new Error('Quicker API未找到,请确保Quicker已安装并运行');\r\n
}\r\n
\r\n
const obj = {input: config.input, age: 3};\r\n
await $quicker.subprogram(config.subprogram, JSON.stringify(obj), false, (success, data) => {\r\n
if (!success) {\r\n
button.textContent = `${config.text}失败`;\r\n
alert(`${config.text}失败: ${data}`);\r\n
} else {\r\n
button.textContent = `${config.text}成功`;\r\n
}\r\n
\r\n
setTimeout(() => {\r\n
button.textContent = config.text;\r\n
}, 1000);\r\n
});\r\n
} catch (error) {\r\n
button.textContent = '操作出错';\r\n
alert(`执行出错: ${error.message}`);\r\n
\r\n
setTimeout(() => {\r\n
button.textContent = config.text;\r\n
}, 1000);\r\n
}\r\n
});\r\n
\r\n
container.appendChild(button);\r\n
});\r\n
\r\n
// 容器拖动事件 - 鼠标按下\r\n
container.addEventListener('mousedown', (e) => {\r\n
isDragging = true;\r\n
\r\n
// 计算鼠标与容器左上角的偏移量\r\n
const rect = container.getBoundingClientRect();\r\n
offsetX = e.clientX - rect.left;\r\n
offsetY = e.clientY - rect.top;\r\n
\r\n
// 记录初始位置\r\n
startX = e.clientX;\r\n
startY = e.clientY;\r\n
\r\n
// 添加拖动样式\r\n
container.style.opacity = '0.9';\r\n
container.style.boxShadow = '0 4px 12px rgba(0,0,0,0.2)';\r\n
\r\n
e.preventDefault(); // 阻止默认行为\r\n
});\r\n
\r\n
// 鼠标移动\r\n
document.addEventListener('mousemove', (e) => {\r\n
if (!isDragging) return;\r\n
\r\n
// 计算新位置\r\n
const x = e.clientX - offsetX;\r\n
const y = e.clientY - offsetY;\r\n
\r\n
// 限制在视口内\r\n
const viewportWidth = window.innerWidth;\r\n
const viewportHeight = window.innerHeight;\r\n
const containerWidth = container.offsetWidth;\r\n
const containerHeight = container.offsetHeight;\r\n
\r\n
const maxX = viewportWidth - containerWidth;\r\n
const maxY = viewportHeight - containerHeight;\r\n
\r\n
const constrainedX = Math.max(0, Math.min(x, maxX));\r\n
const constrainedY = Math.max(0, Math.min(y, maxY));\r\n
\r\n
// 更新容器位置\r\n
container.style.left = `${constrainedX}px`;\r\n
container.style.top = `${constrainedY}px`;\r\n
container.style.right = 'auto';\r\n
container.style.bottom = 'auto';\r\n
});\r\n
\r\n
// 鼠标释放\r\n
document.addEventListener('mouseup', () => {\r\n
if (isDragging) {\r\n
isDragging = false;\r\n
\r\n
// 恢复样式\r\n
container.style.opacity = '1';\r\n
container.style.boxShadow = 'none';\r\n
}\r\n
});\r\n
\r\n
// 添加到页面\r\n
document.body.appendChild(container);\r\n
console.log('悬浮按钮创建成功');\r\n
\r\n
} catch (error) {\r\n
console.error('创建悬浮按钮失败:', error);\r\n
alert(`创建悬浮按钮失败: ${error.message}`);\r\n
}
耗时:0ms