好友
阅读权限 10
听众
最后登录 1970-1-1
// ==UserScript==
// @name Auto Clicker with Controls
// @namespace http://tampermonkey.net/
// @version 1.0
// @description A simple auto clicker with control options on any webpage
// @AuThor You
// @match *://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// 创建点击器和相关控件容器
var clickerWrapper = document.createElement('div');
clickerWrapper.style.position = 'fixed';
clickerWrapper.style.top = '20px'; // 修改悬浮窗位置到页面顶端
clickerWrapper.style.left = '20px';
clickerWrapper.style.width = '200px'; // 减小悬浮窗宽度
clickerWrapper.style.height = 'auto';
clickerWrapper.style.backgroundColor = '#ccc';
clickerWrapper.style.border = '1px solid #000';
clickerWrapper.style.padding = '5px';
clickerWrapper.style.cursor = 'move';
clickerWrapper.classList.add('auto-clicker-wrapper');
// 创建点击器
var clicker = document.createElement('div');
clicker.innerHTML = 'Click Here to Auto Click';
clicker.style.cursor = 'pointer';
clicker.style.marginBottom = '5px'; // 添加底部间距以适应较小的悬浮窗
// 创建循环次数输入框
var loopCountInput = document.createElement('input');
loopCountInput.type = 'number';
loopCountInput.min = '1';
loopCountInput.max = 'Infinity';
loopCountInput.value = '1';
loopCountInput.style.marginRight = '5px';
loopCountInput.style.width = '50px'; // 减小输入框宽度
// 创建时间间隔输入框(单位为毫秒)
var intervalInput = document.createElement('input');
intervalInput.type = 'number';
intervalInput.min = '0';
intervalInput.value = '1000';
intervalInput.style.marginRight = '5px';
intervalInput.style.width = '50px'; // 减小输入框宽度
// 创建启用/关闭切换按钮
var toggleButton = document.createElement('button');
toggleButton.innerHTML = 'Enable';
toggleButton.onclick = function() {
if (this.innerHTML === 'Enable') {
this.innerHTML = 'Disable';
startAutoClicking();
} else {
this.innerHTML = 'Enable';
clearInterval(autoClickIntervalId);
}
};
// 构建布局
clickerWrapper.appendChild(loopCountInput);
clickerWrapper.appendChild(document.createTextNode(' times, every '));
clickerWrapper.appendChild(intervalInput);
clickerWrapper.appendChild(document.createTextNode('ms'));
clickerWrapper.appendChild(toggleButton);
clickerWrapper.appendChild(clicker);
// 添加拖动功能
let isDragging = false;
let dragStartX, dragStartY;
clickerWrapper.addEventListener('mousedown', function(e) {
isDragging = true;
dragStartX = e.clientX - this.offsetLeft;
dragStartY = e.clientY - this.offsetTop;
document.body.style.userSelect = 'none';
});
document.addEventListener('mousemove', function(e) {
if (isDragging) {
clickerWrapper.style.left = `${e.clientX - dragStartX}px`;
clickerWrapper.style.top = `${e.clientY - dragStartY}px`;
}
});
document.addEventListener('mouseup', function() {
isDragging = false;
document.body.style.userSelect = 'auto';
});
// 自动点击函数
function autoClick() {
const mouseX = clicker.getBoundingClientRect().left + clicker.clientWidth / 2;
const mouseY = clicker.getBoundingClientRect().top + clicker.clientHeight / 2;
const targetElement = document.elementFromPoint(mouseX, mouseY);
if (targetElement) {
const mouseEvent = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
});
targetElement.dispatchEvent(mouseEvent);
}
--currentLoopCount;
if (currentLoopCount > 0 || currentLoopCount === Infinity) {
setTimeout(autoClick, parseInt(intervalInput.value));
}
}
// 开始自动点击
var currentLoopCount;
var autoClickIntervalId;
function startAutoClicking() {
currentLoopCount = parseInt(loopCountInput.value);
autoClick();
}
// 将点击器添加到页面上并初始化
window.onload = function() {
if (!document.querySelector('.auto-clicker-wrapper')) {
document.body.appendChild(clickerWrapper);
}
};
})();
//以上代码并未实现模拟鼠标点击的功能,只有悬浮窗和可修改的参数,还有一个开关功能
发帖前要善用【论坛搜索 】 功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。